MCPcopy Create free account
hub / github.com/DoNewsCode/core / TestRemote

Function TestRemote

config/remote/etcd/etcd_test.go:16–62  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

14)
15
16func TestRemote(t *testing.T) {
17 if os.Getenv("ETCD_ADDR") == "" {
18 t.Skip("set ETCD_ADDR to run TestRemote")
19 return
20 }
21 addrs := strings.Split(os.Getenv("ETCD_ADDR"), ",")
22 ctx, cancel := context.WithTimeout(context.Background(), 2*time.Second)
23 defer cancel()
24 cfg := clientv3.Config{
25 Endpoints: addrs,
26 Context: ctx,
27 DialTimeout: time.Second,
28 }
29
30 r := Provider(cfg, "config.yaml")
31
32 testVal := "name: app"
33 // PREPARE TEST DATA
34 if err := put(r, testVal); err != nil {
35 t.Fatal(err)
36 }
37
38 _, err := r.Read()
39 assert.Error(t, err)
40
41 bytes, err := r.ReadBytes()
42 assert.NoError(t, err)
43 assert.Equal(t, testVal, string(bytes))
44
45 ch := make(chan string)
46 go r.Watch(ctx, func() error {
47 bytes, err := r.ReadBytes()
48 if err != nil {
49 ch <- ""
50 return err
51 }
52 ch <- string(bytes)
53 return nil
54 })
55
56 if err := put(r, testVal); err != nil {
57 t.Fatal(err)
58 }
59
60 newVal := <-ch
61 assert.Equal(t, testVal, newVal)
62}
63
64func TestError(t *testing.T) {
65 if os.Getenv("ETCD_ADDR") == "" {

Callers

nothing calls this directly

Calls 6

ProviderFunction · 0.85
putFunction · 0.70
ReadMethod · 0.65
ReadBytesMethod · 0.65
WatchMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected