-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathclient_test.go
91 lines (74 loc) · 1.68 KB
/
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
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
package honeycombio
import (
"context"
"os"
"testing"
"github.com/joho/godotenv"
"github.com/stretchr/testify/assert"
)
func init() {
// load environment values from a .env, if available
_ = godotenv.Load()
}
func newTestClient(t *testing.T) *Client {
apiKey, ok := os.LookupEnv("HONEYCOMBIO_APIKEY")
if !ok {
t.Fatal("expected environment variable HONEYCOMBIO_APIKEY")
}
_, debug := os.LookupEnv("DEBUG")
cfg := &Config{
APIKey: apiKey,
Debug: debug,
}
c, err := NewClient(cfg)
if err != nil {
t.Fatal(err)
}
return c
}
func testDataset(t *testing.T) string {
dataset, ok := os.LookupEnv("HONEYCOMBIO_DATASET")
if !ok {
t.Fatalf("expected environment variable HONEYCOMBIO_DATASET")
}
return dataset
}
func TestConfig_merge(t *testing.T) {
config1 := &Config{
APIKey: "",
APIUrl: "",
UserAgent: "go-honeycombio",
}
config2 := &Config{
APIKey: "",
APIUrl: "http://localhost",
UserAgent: "",
}
expected := &Config{
APIKey: "",
APIUrl: "http://localhost",
UserAgent: "go-honeycombio",
}
config1.merge(config2)
assert.Equal(t, expected, config1)
}
func TestClient_invalidConfig(t *testing.T) {
cfg := &Config{
APIKey: "",
}
_, err := NewClient(cfg)
assert.Error(t, err, "APIKey must be configured")
cfg = &Config{
APIKey: "123",
APIUrl: "cache_object:foo/bar",
}
_, err = NewClient(cfg)
assert.Error(t, err)
assert.Contains(t, err.Error(), "could not parse APIUrl")
}
func TestClient_parseHoneycombioError(t *testing.T) {
ctx := context.Background()
c := newTestClient(t)
err := c.performRequest(ctx, "POST", "/1/boards/", nil, nil)
assert.Error(t, err, "400 Bad Request: request body should not be empty")
}