forked from spaceapegames/go-wavefront
-
Notifications
You must be signed in to change notification settings - Fork 12
/
externallinks_test.go
92 lines (75 loc) · 2.22 KB
/
externallinks_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
92
package wavefront
import (
"io"
"net/http"
"net/url"
"testing"
)
type MockExternalLinksClient struct {
Client
T *testing.T
}
type MockCrudExternalLinksClient struct {
Client
T *testing.T
method string
}
func (e MockExternalLinksClient) Do(req *http.Request) (io.ReadCloser, error) {
return testDo(e.T, req, "./fixtures/search-extlinks-response.json", "POST", &SearchParams{})
}
func (e MockCrudExternalLinksClient) Do(req *http.Request) (io.ReadCloser, error) {
return testDo(e.T, req, "./fixtures/crud-extlink-response.json", e.method, &ExternalLink{})
}
func TestExternalLinks_Find(t *testing.T) {
baseurl, _ := url.Parse("http://testing.wavefront.com")
e := &ExternalLinks{
client: &MockExternalLinksClient{
Client: Client{
Config: &Config{Token: "1234-5678-9977"},
BaseURL: baseurl,
httpClient: http.DefaultClient,
debug: true,
},
T: t,
},
}
externalLinks, err := e.Find(nil)
if err != nil {
t.Fatal(err)
}
assertEqual(t, 1, len(externalLinks))
assertEqual(t, "someid", *externalLinks[0].ID)
}
func TestExternalLinks_CreateUpdateDelete(t *testing.T) {
baseurl, _ := url.Parse("http://testing.wavefront.com")
e := &ExternalLinks{
client: &MockCrudExternalLinksClient{
Client: Client{
Config: &Config{Token: "1234-5678-9977"},
BaseURL: baseurl,
httpClient: http.DefaultClient,
debug: true,
},
T: t,
},
}
e.client.(*MockCrudExternalLinksClient).method = "POST"
externalLink := &ExternalLink{}
if err := e.Create(externalLink); err == nil {
t.Errorf("expected to receive error for missing fields")
}
externalLink.Name = "Example"
externalLink.Description = "someDescription"
externalLink.Template = "https://www.someSystem.com/events?logSource={{{source}}}&startTime={{startEpochMillis}}&endTime={{endEpochMillis}}"
if err := e.Create(externalLink); err != nil {
t.Fatal(err)
}
assertEqual(t, ".*", externalLink.SourceFilterRegex)
e.client.(*MockCrudExternalLinksClient).method = "GET"
var _ = e.Get(externalLink)
e.client.(*MockCrudExternalLinksClient).method = "PUT"
var _ = e.Update(externalLink)
e.client.(*MockCrudExternalLinksClient).method = "DELETE"
var _ = e.Delete(externalLink)
assertEqual(t, "", *externalLink.ID)
}