-
Notifications
You must be signed in to change notification settings - Fork 4
/
testing_helpers.go
72 lines (58 loc) · 2.09 KB
/
testing_helpers.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package devcycle
import (
_ "embed"
"net/http"
"strings"
"time"
"github.com/jarcoal/httpmock"
)
var (
test_environmentKey = "dvc_server_token_hash"
//go:embed testdata/fixture_small_config.json
test_config string
//go:embed testdata/fixture_small_config_special_characters.json
test_config_special_characters_var string
//go:embed testdata/fixture_large_config.json
test_large_config string
test_large_config_variable = "v-key-25"
test_options = &Options{
// use defaults that will be set by the CheckDefaults
EventFlushIntervalMS: time.Second * 30,
ConfigPollingIntervalMS: time.Second * 10,
}
)
func init() {
// Remove newlines in configs
test_config = strings.ReplaceAll(test_config, "\n", "")
test_config_special_characters_var = strings.ReplaceAll(test_config_special_characters_var, "\n", "")
test_large_config = strings.ReplaceAll(test_large_config, "\n", "")
// Set default options
test_options.CheckDefaults()
}
func httpBucketingAPIMock() {
httpmock.RegisterResponder("POST", "https://bucketing-api.devcycle.com/v1/variables/test",
func(req *http.Request) (*http.Response, error) {
resp := httpmock.NewStringResponse(200, `{"value": true, "_id": "614ef6ea475129459160721a", "key": "test", "type": "Boolean"}`)
resp.Header.Set("Etag", "TESTING")
resp.Header.Set("Last-Modified", "LAST-MODIFIED")
return resp, nil
},
)
}
func httpEventsApiMock() {
httpmock.RegisterResponder("POST", "https://events.devcycle.com/v1/events/batch",
httpmock.NewStringResponder(201, `{}`))
}
func httpConfigMock(respcode int) httpmock.Responder {
return httpCustomConfigMock(test_environmentKey, respcode, test_config)
}
func httpCustomConfigMock(sdkKey string, respcode int, config string) httpmock.Responder {
responder := func(req *http.Request) (*http.Response, error) {
resp := httpmock.NewStringResponse(respcode, config)
resp.Header.Set("Etag", "TESTING")
resp.Header.Set("Last-Modified", "LAST-MODIFIED")
return resp, nil
}
httpmock.RegisterResponder("GET", "https://config-cdn.devcycle.com/config/v1/server/"+sdkKey+".json", responder)
return responder
}