| 1 |
package fastly |
| 2 |
|
| 3 |
import "testing" |
| 4 |
|
| 5 |
func TestClient_Splunks(t *testing.T) { |
| 6 |
t.Parallel() |
| 7 |
|
| 8 |
var err error |
| 9 |
var tv *Version |
| 10 |
record(t, "splunks/version", func(c *Client) { |
| 11 |
tv = testVersion(t, c) |
| 12 |
}) |
| 13 |
|
| 14 |
// Create |
| 15 |
var s *Splunk |
| 16 |
record(t, "splunks/create", func(c *Client) { |
| 17 |
s, err = c.CreateSplunk(&CreateSplunkInput{ |
| 18 |
Service: testServiceID, |
| 19 |
Version: tv.Number, |
| 20 |
Name: "test-splunk", |
| 21 |
URL: "https://mysplunkendpoint.example.com/services/collector/event", |
| 22 |
Format: "%h %l %u %t \"%r\" %>s %b", |
| 23 |
FormatVersion: 2, |
| 24 |
Placement: "waf_debug", |
| 25 |
Token: "super-secure-token", |
| 26 |
}) |
| 27 |
}) |
| 28 |
if err != nil { |
| 29 |
t.Fatal(err) |
| 30 |
} |
| 31 |
|
| 32 |
// Ensure deleted |
| 33 |
defer func() { |
| 34 |
record(t, "splunks/cleanup", func(c *Client) { |
| 35 |
c.DeleteSplunk(&DeleteSplunkInput{ |
| 36 |
Service: testServiceID, |
| 37 |
Version: tv.Number, |
| 38 |
Name: "test-splunk", |
| 39 |
}) |
| 40 |
|
| 41 |
c.DeleteSplunk(&DeleteSplunkInput{ |
| 42 |
Service: testServiceID, |
| 43 |
Version: tv.Number, |
| 44 |
Name: "new-test-splunk", |
| 45 |
}) |
| 46 |
}) |
| 47 |
}() |
| 48 |
|
| 49 |
if s.Name != "test-splunk" { |
| 50 |
t.Errorf("bad name: %q", s.Name) |
| 51 |
} |
| 52 |
if s.URL != "https://mysplunkendpoint.example.com/services/collector/event" { |
| 53 |
t.Errorf("bad url: %q", s.URL) |
| 54 |
} |
| 55 |
if s.Format != "%h %l %u %t \"%r\" %>s %b" { |
| 56 |
t.Errorf("bad format: %q", s.Format) |
| 57 |
} |
| 58 |
if s.FormatVersion != 2 { |
| 59 |
t.Errorf("bad format_version: %q", s.FormatVersion) |
| 60 |
} |
| 61 |
if s.Placement != "waf_debug" { |
| 62 |
t.Errorf("bad placement: %q", s.Placement) |
| 63 |
} |
| 64 |
if s.Token != "super-secure-token" { |
| 65 |
t.Errorf("bad token: %q", s.Token) |
| 66 |
} |
| 67 |
|
| 68 |
// List |
| 69 |
var ss []*Splunk |
| 70 |
record(t, "splunks/list", func(c *Client) { |
| 71 |
ss, err = c.ListSplunks(&ListSplunksInput{ |
| 72 |
Service: testServiceID, |
| 73 |
Version: tv.Number, |
| 74 |
}) |
| 75 |
}) |
| 76 |
if err != nil { |
| 77 |
t.Fatal(err) |
| 78 |
} |
| 79 |
if len(ss) < 1 { |
| 80 |
t.Errorf("bad splunks: %v", ss) |
| 81 |
} |
| 82 |
|
| 83 |
// Get |
| 84 |
var ns *Splunk |
| 85 |
record(t, "splunks/get", func(c *Client) { |
| 86 |
ns, err = c.GetSplunk(&GetSplunkInput{ |
| 87 |
Service: testServiceID, |
| 88 |
Version: tv.Number, |
| 89 |
Name: "test-splunk", |
| 90 |
}) |
| 91 |
}) |
| 92 |
if err != nil { |
| 93 |
t.Fatal(err) |
| 94 |
} |
| 95 |
if s.Name != ns.Name { |
| 96 |
t.Errorf("bad name: %q", s.Name) |
| 97 |
} |
| 98 |
if s.URL != ns.URL { |
| 99 |
t.Errorf("bad url: %q", s.URL) |
| 100 |
} |
| 101 |
if s.Format != ns.Format { |
| 102 |
t.Errorf("bad format: %q", s.Format) |
| 103 |
} |
| 104 |
if s.FormatVersion != ns.FormatVersion { |
| 105 |
t.Errorf("bad format_version: %q", s.FormatVersion) |
| 106 |
} |
| 107 |
if s.Placement != ns.Placement { |
| 108 |
t.Errorf("bad placement: %q", s.Placement) |
| 109 |
} |
| 110 |
if s.Token != ns.Token { |
| 111 |
t.Errorf("bad token: %q", s.Token) |
| 112 |
} |
| 113 |
|
| 114 |
// Update |
| 115 |
var us *Splunk |
| 116 |
record(t, "splunks/update", func(c *Client) { |
| 117 |
us, err = c.UpdateSplunk(&UpdateSplunkInput{ |
| 118 |
Service: testServiceID, |
| 119 |
Version: tv.Number, |
| 120 |
Name: "test-splunk", |
| 121 |
NewName: "new-test-splunk", |
| 122 |
}) |
| 123 |
}) |
| 124 |
if err != nil { |
| 125 |
t.Fatal(err) |
| 126 |
} |
| 127 |
if us.Name != "new-test-splunk" { |
| 128 |
t.Errorf("bad name: %q", us.Name) |
| 129 |
} |
| 130 |
|
| 131 |
// Delete |
| 132 |
record(t, "splunks/delete", func(c *Client) { |
| 133 |
err = c.DeleteSplunk(&DeleteSplunkInput{ |
| 134 |
Service: testServiceID, |
| 135 |
Version: tv.Number, |
| 136 |
Name: "new-test-splunk", |
| 137 |
}) |
| 138 |
}) |
| 139 |
if err != nil { |
| 140 |
t.Fatal(err) |
| 141 |
} |
| 142 |
} |
| 143 |
|
| 144 |
func TestClient_ListSplunks_validation(t *testing.T) { |
| 145 |
var err error |
| 146 |
_, err = testClient.ListSplunks(&ListSplunksInput{ |
| 147 |
Service: "", |
| 148 |
}) |
| 149 |
if err != ErrMissingService { |
| 150 |
t.Errorf("bad error: %s", err) |
| 151 |
} |
| 152 |
|
| 153 |
_, err = testClient.ListSplunks(&ListSplunksInput{ |
| 154 |
Service: "foo", |
| 155 |
Version: 0, |
| 156 |
}) |
| 157 |
if err != ErrMissingVersion { |
| 158 |
t.Errorf("bad error: %s", err) |
| 159 |
} |
| 160 |
} |
| 161 |
|
| 162 |
func TestClient_CreateSplunk_validation(t *testing.T) { |
| 163 |
var err error |
| 164 |
_, err = testClient.CreateSplunk(&CreateSplunkInput{ |
| 165 |
Service: "", |
| 166 |
}) |
| 167 |
if err != ErrMissingService { |
| 168 |
t.Errorf("bad error: %s", err) |
| 169 |
} |
| 170 |
|
| 171 |
_, err = testClient.CreateSplunk(&CreateSplunkInput{ |
| 172 |
Service: "foo", |
| 173 |
Version: 0, |
| 174 |
}) |
| 175 |
if err != ErrMissingVersion { |
| 176 |
t.Errorf("bad error: %s", err) |
| 177 |
} |
| 178 |
} |
| 179 |
|
| 180 |
func TestClient_GetSplunk_validation(t *testing.T) { |
| 181 |
var err error |
| 182 |
_, err = testClient.GetSplunk(&GetSplunkInput{ |
| 183 |
Service: "", |
| 184 |
}) |
| 185 |
if err != ErrMissingService { |
| 186 |
t.Errorf("bad error: %s", err) |
| 187 |
} |
| 188 |
|
| 189 |
_, err = testClient.GetSplunk(&GetSplunkInput{ |
| 190 |
Service: "foo", |
| 191 |
Version: 0, |
| 192 |
}) |
| 193 |
if err != ErrMissingVersion { |
| 194 |
t.Errorf("bad error: %s", err) |
| 195 |
} |
| 196 |
|
| 197 |
_, err = testClient.GetSplunk(&GetSplunkInput{ |
| 198 |
Service: "foo", |
| 199 |
Version: 1, |
| 200 |
Name: "", |
| 201 |
}) |
| 202 |
if err != ErrMissingName { |
| 203 |
t.Errorf("bad error: %s", err) |
| 204 |
} |
| 205 |
} |
| 206 |
|
| 207 |
func TestClient_UpdateSplunk_validation(t *testing.T) { |
| 208 |
var err error |
| 209 |
_, err = testClient.UpdateSplunk(&UpdateSplunkInput{ |
| 210 |
Service: "", |
| 211 |
}) |
| 212 |
if err != ErrMissingService { |
| 213 |
t.Errorf("bad error: %s", err) |
| 214 |
} |
| 215 |
|
| 216 |
_, err = testClient.UpdateSplunk(&UpdateSplunkInput{ |
| 217 |
Service: "foo", |
| 218 |
Version: 0, |
| 219 |
}) |
| 220 |
if err != ErrMissingVersion { |
| 221 |
t.Errorf("bad error: %s", err) |
| 222 |
} |
| 223 |
|
| 224 |
_, err = testClient.UpdateSplunk(&UpdateSplunkInput{ |
| 225 |
Service: "foo", |
| 226 |
Version: 1, |
| 227 |
Name: "", |
| 228 |
}) |
| 229 |
if err != ErrMissingName { |
| 230 |
t.Errorf("bad error: %s", err) |
| 231 |
} |
| 232 |
} |
| 233 |
|
| 234 |
func TestClient_DeleteSplunk_validation(t *testing.T) { |
| 235 |
var err error |
| 236 |
err = testClient.DeleteSplunk(&DeleteSplunkInput{ |
| 237 |
Service: "", |
| 238 |
}) |
| 239 |
if err != ErrMissingService { |
| 240 |
t.Errorf("bad error: %s", err) |
| 241 |
} |
| 242 |
|
| 243 |
err = testClient.DeleteSplunk(&DeleteSplunkInput{ |
| 244 |
Service: "foo", |
| 245 |
Version: 0, |
| 246 |
}) |
| 247 |
if err != ErrMissingVersion { |
| 248 |
t.Errorf("bad error: %s", err) |
| 249 |
} |
| 250 |
|
| 251 |
err = testClient.DeleteSplunk(&DeleteSplunkInput{ |
| 252 |
Service: "foo", |
| 253 |
Version: 1, |
| 254 |
Name: "", |
| 255 |
}) |
| 256 |
if err != ErrMissingName { |
| 257 |
t.Errorf("bad error: %s", err) |
| 258 |
} |
| 259 |
} |