add instructions for integration tests
This commit is contained in:
parent
4ff13d9bc2
commit
2febc40f99
1
.gitignore
vendored
1
.gitignore
vendored
@ -6,3 +6,4 @@ dumpcerts.sh
|
|||||||
acme.json
|
acme.json
|
||||||
acme-backup.json
|
acme-backup.json
|
||||||
traefik-certs-dumper
|
traefik-certs-dumper
|
||||||
|
tests/tests
|
||||||
|
|||||||
35
tests/README.md
Normal file
35
tests/README.md
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
# Integration testing
|
||||||
|
|
||||||
|
## Preperation
|
||||||
|
1. Create valid ACME file `/tmp/acme.json`
|
||||||
|
1. Start backends using docker
|
||||||
|
```console
|
||||||
|
docker run -d -p 8500:8500 --name consul consul
|
||||||
|
docker run -d -p 2181:2181 --name zookeeper zookeeper
|
||||||
|
docker run -d -p 2379:2379 --name etcd quay.io/coreos/etcd:v3.3.12 etcd --listen-client-urls http://0.0.0.0:2379 --advertise-client-urls http://0.0.0.0:2380
|
||||||
|
```
|
||||||
|
1. Build tests
|
||||||
|
```console
|
||||||
|
export GO111MODULE=on
|
||||||
|
go build
|
||||||
|
```
|
||||||
|
1. Initialize backends
|
||||||
|
```console
|
||||||
|
./tests
|
||||||
|
```
|
||||||
|
1. Run certs dumper without watching
|
||||||
|
```console
|
||||||
|
../traefik-certs-dumper dump --source.file=/tmp/acme.json
|
||||||
|
../traefik-certs-dumper dump --source consul --source.kv.endpoints=localhost:8500
|
||||||
|
../traefik-certs-dumper dump --source etcd --source.kv.endpoints=localhost:2379
|
||||||
|
../traefik-certs-dumper dump --source boltdb --source.kv.endpoints=/tmp/my.db
|
||||||
|
../traefik-certs-dumper dump --source zookeeper --source.kv.endpoints=localhost:2181
|
||||||
|
```
|
||||||
|
1. Run certs dumper with watching
|
||||||
|
```console
|
||||||
|
../traefik-certs-dumper dump --watch --source.file=/tmp/acme.json
|
||||||
|
../traefik-certs-dumper dump --watch --source consul --source.kv.endpoints=localhost:8500
|
||||||
|
../traefik-certs-dumper dump --watch --source etcd --source.kv.endpoints=localhost:2379
|
||||||
|
../traefik-certs-dumper dump --watch --source zookeeper --source.kv.endpoints=localhost:2181
|
||||||
|
```
|
||||||
|
While watching is enabled, run `./tests` again for KV backends or manipulate `/tmp/acme.json` for file backend that change events are triggered.
|
||||||
111
tests/test.go
Normal file
111
tests/test.go
Normal file
@ -0,0 +1,111 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bufio"
|
||||||
|
"bytes"
|
||||||
|
"compress/gzip"
|
||||||
|
"fmt"
|
||||||
|
"io/ioutil"
|
||||||
|
"os"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/abronan/valkeyrie"
|
||||||
|
"github.com/abronan/valkeyrie/store"
|
||||||
|
"github.com/abronan/valkeyrie/store/boltdb"
|
||||||
|
"github.com/abronan/valkeyrie/store/consul"
|
||||||
|
etcdv3 "github.com/abronan/valkeyrie/store/etcd/v3"
|
||||||
|
"github.com/abronan/valkeyrie/store/zookeeper"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
storeKey = "traefik/acme/account/object"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
writeDataToBackends()
|
||||||
|
}
|
||||||
|
|
||||||
|
func writeDataToBackends() {
|
||||||
|
storeConfig := &store.Config{
|
||||||
|
ConnectionTimeout: 3 * time.Second,
|
||||||
|
Bucket: "traefik",
|
||||||
|
}
|
||||||
|
|
||||||
|
consul.Register()
|
||||||
|
etcdv3.Register()
|
||||||
|
zookeeper.Register()
|
||||||
|
boltdb.Register()
|
||||||
|
|
||||||
|
consulStore, err := valkeyrie.NewStore(
|
||||||
|
store.CONSUL,
|
||||||
|
[]string{"localhost:8500"},
|
||||||
|
storeConfig,
|
||||||
|
)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
etcdv3Store, err := valkeyrie.NewStore(
|
||||||
|
store.ETCDV3,
|
||||||
|
[]string{"localhost:2379"},
|
||||||
|
storeConfig,
|
||||||
|
)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
zkStore, err := valkeyrie.NewStore(
|
||||||
|
store.ZK,
|
||||||
|
[]string{"localhost:2181"},
|
||||||
|
storeConfig,
|
||||||
|
)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
boltdbStore, err := valkeyrie.NewStore(
|
||||||
|
store.BOLTDB,
|
||||||
|
[]string{"/tmp/my.db"},
|
||||||
|
storeConfig,
|
||||||
|
)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
f, _ := os.Open("/tmp/acme.json")
|
||||||
|
reader := bufio.NewReader(f)
|
||||||
|
content, _ := ioutil.ReadAll(reader)
|
||||||
|
|
||||||
|
var b bytes.Buffer
|
||||||
|
gz := gzip.NewWriter(&b)
|
||||||
|
|
||||||
|
_, err = gz.Write(content)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if err = gz.Flush(); err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if err = gz.Close(); err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := boltdbStore.Put(storeKey, b.Bytes(), nil); err == nil {
|
||||||
|
fmt.Println("successfully updated boltdb")
|
||||||
|
}
|
||||||
|
if err := zkStore.Put(storeKey, b.Bytes(), nil); err == nil {
|
||||||
|
fmt.Println("successfully updated zookeeper")
|
||||||
|
}
|
||||||
|
if err := etcdv3Store.Put(storeKey, b.Bytes(), nil); err == nil {
|
||||||
|
fmt.Println("successfully updated etcd")
|
||||||
|
}
|
||||||
|
if err := consulStore.Put(storeKey, b.Bytes(), nil); err == nil {
|
||||||
|
fmt.Println("successfully updated consul")
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user