forked from mistifyio/lochness
/
context_test.go
54 lines (42 loc) · 1.23 KB
/
context_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package lochness_test
import (
"errors"
"testing"
h "github.com/bakins/test-helpers"
"github.com/coreos/go-etcd/etcd"
"github.com/mistifyio/lochness"
)
func newContext(t *testing.T) *lochness.Context {
e := etcd.NewClient([]string{"http://127.0.0.1:4001"})
if !e.SyncCluster() {
t.Fatal("cannot sync cluster. make sure etcd is running at http://127.0.0.1:4001")
}
c := lochness.NewContext(e)
return c
}
func TestNewContext(t *testing.T) {
_ = newContext(t)
}
func contextCleanup(t *testing.T) {
e := etcd.NewClient([]string{"http://127.0.0.1:4001"})
if !e.SyncCluster() {
t.Fatal("cannot sync cluster. make sure etcd is running at http://127.0.0.1:4001")
}
_, err := e.Delete("lochness", true)
if !lochness.IsKeyNotFound(err) {
h.Ok(t, err)
}
}
func TestIsKeyNotFound(t *testing.T) {
e := etcd.NewClient([]string{"http://127.0.0.1:4001"})
newContext(t)
defer contextCleanup(t)
_, err := e.Get("lochness/some-randon-non-existent-key", false, false)
if !lochness.IsKeyNotFound(err) {
t.Fatalf("was expecting a KeyNotFound error, got: %#v\n", err)
}
err = errors.New("lochness/some-random-non-key-not-found-error")
if lochness.IsKeyNotFound(err) {
t.Fatal("got unexpected positive KeyNotFound error for err:", err)
}
}