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

Function TestError

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

Source from the content-addressed store, hash-verified

62}
63
64func TestError(t *testing.T) {
65 if os.Getenv("ETCD_ADDR") == "" {
66 t.Skip("set ETCD_ADDR to run TestError")
67 return
68 }
69 addrs := strings.Split(os.Getenv("ETCD_ADDR"), ",")
70 var (
71 r *ETCD
72 err error
73 )
74 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
75 defer cancel()
76
77 cfg := clientv3.Config{
78 Endpoints: []string{},
79 DialTimeout: 2 * time.Second,
80 Context: ctx,
81 }
82
83 r = Provider(cfg, "config.yaml")
84 err = put(r, "test")
85 assert.Error(t, err)
86
87 _, err = r.ReadBytes()
88 assert.Error(t, err)
89
90 err = r.Watch(ctx, func() error {
91 return nil
92 })
93 assert.Error(t, err)
94
95 cfg = clientv3.Config{
96 Endpoints: addrs,
97 DialTimeout: 2 * time.Second,
98 Context: ctx,
99 }
100 r = Provider(cfg, "config-test1")
101 _, err = r.ReadBytes()
102 assert.Error(t, err)
103
104 r = Provider(cfg, "config-test2")
105
106 // Confirm that the two coroutines are finished
107 g := sync.WaitGroup{}
108 g.Add(2)
109 go func() {
110 err := r.Watch(ctx, func() error {
111 return fmt.Errorf("for test")
112 })
113 assert.Error(t, err)
114 g.Done()
115 }()
116
117 go func() {
118 err := r.Watch(ctx, func() error {
119 return fmt.Errorf("for test")
120 })
121 assert.Error(t, err)

Callers

nothing calls this directly

Calls 7

ProviderFunction · 0.85
DoneMethod · 0.80
putFunction · 0.70
ReadBytesMethod · 0.65
WatchMethod · 0.65
ErrorMethod · 0.45
AddMethod · 0.45

Tested by

no test coverage detected