Skip to content

Commit d38a2b9

Browse files
committed
integration: test GracefulStop on secure embedded server
Signed-off-by: Gyuho Lee <[email protected]>
1 parent 1d4fed1 commit d38a2b9

File tree

1 file changed

+27
-7
lines changed

1 file changed

+27
-7
lines changed

integration/embed_test.go

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ func TestEmbedEtcd(t *testing.T) {
4747
{werr: "expected IP"},
4848
}
4949

50-
urls := newEmbedURLs(10)
50+
urls := newEmbedURLs(false, 10)
5151

5252
// setup defaults
5353
for i := range tests {
@@ -105,12 +105,19 @@ func TestEmbedEtcd(t *testing.T) {
105105
}
106106
}
107107

108-
// TestEmbedEtcdGracefulStop ensures embedded server stops
108+
func TestEmbedEtcdGracefulStopSecure(t *testing.T) { testEmbedEtcdGracefulStop(t, true) }
109+
func TestEmbedEtcdGracefulStopInsecure(t *testing.T) { testEmbedEtcdGracefulStop(t, false) }
110+
111+
// testEmbedEtcdGracefulStop ensures embedded server stops
109112
// cutting existing transports.
110-
func TestEmbedEtcdGracefulStop(t *testing.T) {
113+
func testEmbedEtcdGracefulStop(t *testing.T, secure bool) {
111114
cfg := embed.NewConfig()
115+
if secure {
116+
cfg.ClientTLSInfo = testTLSInfo
117+
cfg.PeerTLSInfo = testTLSInfo
118+
}
112119

113-
urls := newEmbedURLs(2)
120+
urls := newEmbedURLs(secure, 2)
114121
setupEmbedCfg(cfg, []url.URL{urls[0]}, []url.URL{urls[1]})
115122

116123
cfg.Dir = filepath.Join(os.TempDir(), fmt.Sprintf("embed-etcd"))
@@ -123,7 +130,16 @@ func TestEmbedEtcdGracefulStop(t *testing.T) {
123130
}
124131
<-e.Server.ReadyNotify() // wait for e.Server to join the cluster
125132

126-
cli, err := clientv3.New(clientv3.Config{Endpoints: []string{urls[0].String()}})
133+
clientCfg := clientv3.Config{
134+
Endpoints: []string{urls[0].String()},
135+
}
136+
if secure {
137+
clientCfg.TLS, err = testTLSInfo.ClientConfig()
138+
if err != nil {
139+
t.Fatal(err)
140+
}
141+
}
142+
cli, err := clientv3.New(clientCfg)
127143
if err != nil {
128144
t.Fatal(err)
129145
}
@@ -146,9 +162,13 @@ func TestEmbedEtcdGracefulStop(t *testing.T) {
146162
}
147163
}
148164

149-
func newEmbedURLs(n int) (urls []url.URL) {
165+
func newEmbedURLs(secure bool, n int) (urls []url.URL) {
166+
scheme := "unix"
167+
if secure {
168+
scheme = "unixs"
169+
}
150170
for i := 0; i < n; i++ {
151-
u, _ := url.Parse(fmt.Sprintf("unix://localhost:%d%06d", os.Getpid(), i))
171+
u, _ := url.Parse(fmt.Sprintf("%s://localhost:%d%06d", scheme, os.Getpid(), i))
152172
urls = append(urls, *u)
153173
}
154174
return urls

0 commit comments

Comments
 (0)