-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclient_test.go
41 lines (34 loc) · 892 Bytes
/
client_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
package goclient
import (
"context"
"github.com/afex/hystrix-go/hystrix"
"net/http"
"net/http/httptest"
"net/url"
"testing"
)
func TestClient_Do(t *testing.T) {
testServer := httptest.NewServer(&testHandler{})
client, err := NewWithOpts(
testServer.URL,
WithDebug(),
WithNewRelicEnable(),
WithHystrix(NewHystrixConfig("testcmd", hystrix.CommandConfig{})),
)
if err != nil {
t.Fatalf("err: %s",err)
}
q := url.Values{"key1":[]string{"val1"},"key2":[]string{"val2"}}
err = client.Verb(http.MethodGet).Path("/api/v1/testreq").Query(q).Do(context.Background(),nil,nil,nil)
if err != nil {
t.Fatalf("err: %s",err)
}
}
type testHandler struct{}
func (t *testHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
if r.URL.String() == "/api/v1/testreq?key1=val1&key2=val2" {
w.WriteHeader(http.StatusOK)
return
}
w.WriteHeader(http.StatusBadRequest)
}