-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathregistry_test.go
52 lines (44 loc) · 929 Bytes
/
registry_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
package discovery
import (
"context"
"fmt"
"testing"
"time"
etcd "go.etcd.io/etcd/client/v3"
)
func TestRegister(t *testing.T) {
etcd := EtcdConfig{
Endpoints: []string{"127.0.0.1:2379"},
Username: "root",
Password: "qwer1234",
}
Register(context.Background(), etcd, &ServiceInfo{
ID: 1,
Name: "hall",
Internal: "127.0.0.1",
Version: "1.0.0",
})
}
func TestEtcdQuery(t *testing.T) {
eCfg := EtcdConfig{
Endpoints: []string{"127.0.0.1:2379"},
Username: "root",
Password: "qwer1234",
}
client, err := etcd.New(etcd.Config{
DialTimeout: time.Second * 3,
Endpoints: eCfg.Endpoints,
Username: eCfg.Username,
Password: eCfg.Password,
})
if err != nil {
panic(err)
}
resp, err := client.Get(context.Background(), "/", etcd.WithPrefix())
if err != nil {
panic(err)
}
for _, kv := range resp.Kvs {
fmt.Printf("key:%s, value:%s\n", kv.Key, kv.Value)
}
}