forked from docker-archive/classicswarm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtoken_test.go
48 lines (39 loc) · 1.13 KB
/
token_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
package token
import (
"testing"
"time"
"github.com/docker/docker/pkg/discovery"
"github.com/stretchr/testify/assert"
)
func TestInitialize(t *testing.T) {
discovery := &Discovery{}
err := discovery.Initialize("token", 0, 0, nil)
assert.NoError(t, err)
assert.Equal(t, discovery.token, "token")
assert.Equal(t, discovery.url, discoveryURL)
err = discovery.Initialize("custom/path/token", 0, 0, nil)
assert.NoError(t, err)
assert.Equal(t, discovery.token, "token")
assert.Equal(t, discovery.url, "https://custom/path")
err = discovery.Initialize("", 0, 0, nil)
assert.Error(t, err)
}
func TestRegister(t *testing.T) {
d := &Discovery{token: "TEST_TOKEN", url: discoveryURL, heartbeat: 1}
expected := "127.0.0.1:2675"
expectedEntries, err := discovery.CreateEntries([]string{expected})
assert.NoError(t, err)
// Register
assert.NoError(t, d.Register(expected))
// Watch
ch, errCh := d.Watch(nil)
select {
case entries := <-ch:
assert.True(t, entries.Equals(expectedEntries))
case err := <-errCh:
t.Fatal(err)
case <-time.After(5 * time.Second):
t.Fatal("Timed out")
}
assert.NoError(t, d.Register(expected))
}