From 2febc40f9952b9b9de6fdf5dfe162fdabde9f889 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20M=C3=BCller?= Date: Sat, 20 Apr 2019 10:02:37 +0200 Subject: [PATCH] add instructions for integration tests --- .gitignore | 1 + tests/README.md | 35 +++++++++++++++ tests/test.go | 111 ++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 147 insertions(+) create mode 100644 tests/README.md create mode 100644 tests/test.go diff --git a/.gitignore b/.gitignore index 0cace7a..2bcdc0e 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,4 @@ dumpcerts.sh acme.json acme-backup.json traefik-certs-dumper +tests/tests diff --git a/tests/README.md b/tests/README.md new file mode 100644 index 0000000..13fb860 --- /dev/null +++ b/tests/README.md @@ -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. diff --git a/tests/test.go b/tests/test.go new file mode 100644 index 0000000..9921860 --- /dev/null +++ b/tests/test.go @@ -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") + } +}