-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathclient_export_test.go
75 lines (60 loc) · 1.74 KB
/
client_export_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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package axiom_test
import (
"context"
"net/http"
"net/http/httptest"
"testing"
"github.com/stretchr/testify/require"
"github.com/axiomhq/axiom-go/axiom"
)
// TestClient makes sure a user of the package can construct his own requests to
// use with the clients methods.
func TestClient_Manual(t *testing.T) {
srv := httptest.NewServer(http.HandlerFunc(func(http.ResponseWriter, *http.Request) {}))
t.Cleanup(srv.Close)
client, err := axiom.NewClient(
axiom.SetURL(srv.URL),
axiom.SetToken("xapt-123"),
axiom.SetOrganizationID("123"),
axiom.SetClient(srv.Client()),
axiom.SetStrictDecoding(true),
axiom.SetNoEnv(),
)
require.NoError(t, err)
opts := struct {
test string `url:"test"`
}{
test: "test",
}
path, err := axiom.AddURLOptions("/v2/test", opts)
require.NoError(t, err)
req, err := client.NewRequest(context.Background(), http.MethodGet, path, nil)
require.NoError(t, err)
resp, err := client.Do(req, nil)
require.NoError(t, err)
require.Equal(t, http.StatusOK, resp.StatusCode)
}
// TestClient makes sure a user of the package can construct his own requests to
// use with the clients Call method.
func TestClient_Call(t *testing.T) {
srv := httptest.NewServer(http.HandlerFunc(func(http.ResponseWriter, *http.Request) {}))
t.Cleanup(srv.Close)
client, err := axiom.NewClient(
axiom.SetURL(srv.URL),
axiom.SetToken("xapt-123"),
axiom.SetOrganizationID("123"),
axiom.SetClient(srv.Client()),
axiom.SetStrictDecoding(true),
axiom.SetNoEnv(),
)
require.NoError(t, err)
opts := struct {
test string `url:"test"`
}{
test: "test",
}
path, err := axiom.AddURLOptions("/v2/test", opts)
require.NoError(t, err)
err = client.Call(context.Background(), http.MethodGet, path, nil, nil)
require.NoError(t, err)
}