sd/etcd: integration_test simply hasn't worked in a long time
Peter Bourgon
7 years ago
0 | // +build integration | |
1 | ||
2 | package etcd | |
3 | ||
4 | import ( | |
5 | "flag" | |
6 | "kit/log" | |
7 | "os" | |
8 | "testing" | |
9 | "time" | |
10 | ||
11 | etcdc "github.com/coreos/etcd/client" | |
12 | etcdi "github.com/coreos/etcd/integration" | |
13 | "golang.org/x/net/context" | |
14 | ) | |
15 | ||
16 | var ( | |
17 | host []string | |
18 | kitClientOptions ClientOptions | |
19 | ) | |
20 | ||
21 | func TestMain(m *testing.M) { | |
22 | flag.Parse() | |
23 | ||
24 | kitClientOptions = ClientOptions{ | |
25 | Cert: "", | |
26 | Key: "", | |
27 | CaCert: "", | |
28 | DialTimeout: (2 * time.Second), | |
29 | DialKeepAlive: (2 * time.Second), | |
30 | HeaderTimeoutPerRequest: (2 * time.Second), | |
31 | } | |
32 | ||
33 | code := m.Run() | |
34 | ||
35 | os.Exit(code) | |
36 | } | |
37 | ||
38 | func TestRegistrar(t *testing.T) { | |
39 | ts := etcdi.NewCluster(t, 1) | |
40 | ts.Launch(t) | |
41 | kitClient, err := NewClient(context.Background(), []string{ts.URL(0)}, kitClientOptions) | |
42 | ||
43 | // Valid registrar should pass | |
44 | registrar := NewRegistrar(kitClient, Service{ | |
45 | Key: "somekey", | |
46 | Value: "somevalue", | |
47 | DeleteOptions: &etcdc.DeleteOptions{ | |
48 | PrevValue: "", | |
49 | PrevIndex: 0, | |
50 | Recursive: true, | |
51 | Dir: false, | |
52 | }, | |
53 | }, log.NewNopLogger()) | |
54 | ||
55 | registrar.Register() | |
56 | r1, err := kitClient.GetEntries(registrar.service.Key) | |
57 | if err != nil { | |
58 | t.Fatalf("unexpected error when getting value for deregistered key: %v", err) | |
59 | } | |
60 | ||
61 | if want, have := registrar.service.Value, r1[0]; want != have { | |
62 | t.Fatalf("want %q, have %q", want, have) | |
63 | } | |
64 | ||
65 | registrar.Deregister() | |
66 | r2, err := kitClient.GetEntries(registrar.service.Key) | |
67 | if len(r2) > 0 { | |
68 | t.Fatalf("unexpected value found for deregistered key: %s", r2) | |
69 | } | |
70 | ||
71 | // Registrar with no key should register but value will be blank | |
72 | registrarNoKey := NewRegistrar(kitClient, Service{ | |
73 | Key: "", | |
74 | Value: "somevalue", | |
75 | DeleteOptions: &etcdc.DeleteOptions{ | |
76 | PrevValue: "", | |
77 | PrevIndex: 0, | |
78 | Recursive: true, | |
79 | Dir: false, | |
80 | }, | |
81 | }, log.NewNopLogger()) | |
82 | ||
83 | registrarNoKey.Register() | |
84 | r3, err := kitClient.GetEntries(registrarNoKey.service.Key) | |
85 | if err != nil { | |
86 | t.Errorf("unexpected error when getting value for entry with no key: %v", err) | |
87 | } | |
88 | ||
89 | if want, have := "", r3[0]; want != have { | |
90 | t.Fatalf("want %q, have %q", want, have) | |
91 | } | |
92 | ||
93 | // Registrar with no value should not register anything | |
94 | registrarNoValue := NewRegistrar(kitClient, Service{ | |
95 | Key: "somekey", | |
96 | Value: "", | |
97 | DeleteOptions: &etcdc.DeleteOptions{ | |
98 | PrevValue: "", | |
99 | PrevIndex: 0, | |
100 | Recursive: true, | |
101 | Dir: false, | |
102 | }, | |
103 | }, log.NewNopLogger()) | |
104 | ||
105 | registrarNoValue.Register() | |
106 | r4, err := kitClient.GetEntries(registrarNoValue.service.Key) | |
107 | if err == nil { | |
108 | t.Errorf("expected error when getting value for entry key which attempted to register with no value") | |
109 | } | |
110 | ||
111 | if len(r4) > 0 { | |
112 | t.Fatalf("unexpected value retreived when getting value for entry with no value") | |
113 | } | |
114 | ||
115 | ts.Terminate(t) | |
116 | } |