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