-
Notifications
You must be signed in to change notification settings - Fork 7
/
service_test.go
46 lines (36 loc) · 1.03 KB
/
service_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
package yext
import (
"net/http"
"net/http/httptest"
)
// Used to make testing easier since ResponseRaw serializes to JSON "response"
type mockResponse struct {
Meta Meta `json:"meta"`
Response interface{} `json:"response,omitempty"`
}
var (
// mux is the HTTP request multiplexer used with the test server.
mux *http.ServeMux
// client is the client being tested.
client *Client
// server is a test HTTP server used to provide mock API responses.
server *httptest.Server
)
func setup() *Config {
// test server
mux = http.NewServeMux()
server = httptest.NewServer(mux)
// client configured to use test server
config := NewConfig().
WithHTTPClient(http.DefaultClient).
WithBaseUrl(server.URL). // Use test server
WithApiKey("apikey"). // Customer ID needs to be set to something to avoid '//' in the URL path
WithRetries(0) // No retries
client = NewClient(config)
// No delay between attempts
DefaultBackoffPolicy = BackoffPolicy{[]int{0}}
return config
}
func teardown() {
server.Close()
}