forked from wavefrontHQ/go-wavefront-management-api
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ingestionpolicies_test.go
93 lines (74 loc) · 2.24 KB
/
ingestionpolicies_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
93
package wavefront
import (
"io"
"net/http"
"net/url"
"testing"
)
type MockIngestionPoliciesClient struct {
Client
T *testing.T
}
type MockCrudIngestionPoliciesClient struct {
Client
T *testing.T
method string
}
func (pol MockIngestionPoliciesClient) Do(req *http.Request) (io.ReadCloser, error) {
return testDo(pol.T, req, "./fixtures/search-ingestionpolicy-response.json", "POST", &SearchParams{})
}
func (pol MockCrudIngestionPoliciesClient) Do(req *http.Request) (io.ReadCloser, error) {
return testDo(pol.T, req, "./fixtures/crud-ingestionpolicy-response.json", pol.method, &IngestionPolicy{})
}
func TestIngestionPolicies_Find(t *testing.T) {
baseurl, _ := url.Parse("http://testing.wavefront.com")
pol := &IngestionPolicies{
client: &MockIngestionPoliciesClient{
Client: Client{
Config: &Config{Token: "1234-5678-9977"},
BaseURL: baseurl,
httpClient: http.DefaultClient,
debug: true,
},
T: t,
},
}
ingestionPolicies, err := pol.Find(nil)
if err != nil {
t.Fatal(err)
}
assertEqual(t, 1, len(ingestionPolicies))
assertEqual(t, "someid", ingestionPolicies[0].ID)
}
func TestIngestionPolicies_CreateUpdateDelete(t *testing.T) {
baseurl, _ := url.Parse("http://testing.wavefront.com")
pol := &IngestionPolicies{
client: &MockCrudIngestionPoliciesClient{
Client: Client{
Config: &Config{Token: "1234-5678-9977"},
BaseURL: baseurl,
httpClient: http.DefaultClient,
debug: true,
},
T: t,
},
}
pol.client.(*MockCrudIngestionPoliciesClient).method = "POST"
ingestionPolicy := &IngestionPolicy{}
if err := pol.Create(ingestionPolicy); err == nil {
t.Errorf("expected to receive error for missing fields")
}
ingestionPolicy.Name = "Example"
ingestionPolicy.Description = "someDescription"
ingestionPolicy.Scope = "ACCOUNT"
if err := pol.Create(ingestionPolicy); err != nil {
t.Fatal(err)
}
pol.client.(*MockCrudIngestionPoliciesClient).method = "GET"
var _ = pol.Get(ingestionPolicy)
pol.client.(*MockCrudIngestionPoliciesClient).method = "PUT"
var _ = pol.Update(ingestionPolicy)
pol.client.(*MockCrudIngestionPoliciesClient).method = "DELETE"
var _ = pol.Delete(ingestionPolicy)
assertEqual(t, "test-policy-1607616352537", ingestionPolicy.ID)
}