-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathmanual_polling_policy_test.go
51 lines (40 loc) · 1.23 KB
/
manual_polling_policy_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
package configcat
import (
"context"
"net/http"
"testing"
qt "github.com/frankban/quicktest"
)
func TestManualPollingPolicy_Refresh(t *testing.T) {
c := qt.New(t)
srv := newConfigServer(t)
// Note: don't set a response on the server - the test will
// fail if we get a request.
cfg := srv.config()
cfg.PollingMode = Manual
client := NewCustomClient(cfg)
defer client.Close()
c.Assert(client.fetcher.current(), qt.IsNil)
srv.setResponse(configResponse{body: `{"test":1}`})
client.Refresh(context.Background())
c.Assert(client.fetcher.current().body(), qt.Equals, `{"test":1}`)
srv.setResponse(configResponse{body: `{"test":2}`})
c.Assert(client.fetcher.current().body(), qt.Equals, `{"test":1}`)
client.Refresh(context.Background())
srv.setResponse(configResponse{body: `{"test":2}`})
}
func TestManualPollingPolicy_FetchFail(t *testing.T) {
c := qt.New(t)
srv := newConfigServer(t)
cfg := srv.config()
cfg.PollingMode = Manual
client := NewCustomClient(cfg)
defer client.Close()
c.Assert(client.fetcher.current(), qt.IsNil)
srv.setResponse(configResponse{
status: http.StatusInternalServerError,
body: `something failed`,
})
client.Refresh(context.Background())
c.Assert(client.fetcher.current(), qt.IsNil)
}