🐞 Don't run etcd tests without etcd

Now we check first to see if etcd is running before diving in & testing
against it.

fixes:
```
Unexpected error:
    <*fmt.wrapError | 0xc0003bc8e0>: {
        msg: "couldn't GET \"my-key\": context deadline exceeded",
        err: <context.deadlineExceededError>{},
    }
```
This commit is contained in:
Brian Cunnie
2022-01-20 04:39:32 -08:00
parent c48ca88c4f
commit c0196ed617
2 changed files with 21 additions and 13 deletions

View File

@@ -4,7 +4,7 @@
#
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
cd $DIR/../src/sslip.io-dns-server
ldflags="-X xip/xip.VersionSemantic=2.3.0 \
ldflags="-X xip/xip.VersionSemantic=2.4.0 \
-X xip/xip.VersionDate=$(date +%Y/%m/%d-%H:%M:%S%z) \
-X xip/xip.VersionGitHash=$(git rev-parse --short HEAD)"
export GOOS GOARCH

View File

@@ -201,20 +201,28 @@ var _ = Describe("Xip", func() {
When("there's no etcd, just local, in-memory key-value", func() {
txtTests()
})
When(`etcd is backing the kv store`, func() {
BeforeEach(func() {
etcdCli, err := clientv3.New(clientv3.Config{
Endpoints: []string{"localhost:2379"},
DialTimeout: 250 * time.Millisecond,
etcdURI := "localhost:2379"
// make sure there's an etcd listening before we run our tests
conn, err := net.DialTimeout("tcp", etcdURI, 250*time.Millisecond)
if err == nil {
err = conn.Close()
Expect(err).ToNot(HaveOccurred())
When(`etcd is backing the kv store`, func() {
BeforeEach(func() {
etcdCli, err := clientv3.New(clientv3.Config{
Endpoints: []string{etcdURI},
DialTimeout: 250 * time.Millisecond,
})
Expect(err).ToNot(HaveOccurred())
x.Etcd = etcdCli
})
Expect(err).ToNot(HaveOccurred())
x.Etcd = etcdCli
AfterEach(func() {
err = x.Etcd.Close()
Expect(err).ToNot(HaveOccurred())
})
txtTests()
})
AfterEach(func() {
x.Etcd.Close()
})
txtTests()
})
}
})
})