diff --git a/fastly/fixtures/grafanacloudlogs/create.yaml b/fastly/fixtures/grafanacloudlogs/create.yaml new file mode 100644 index 000000000..1cf673362 --- /dev/null +++ b/fastly/fixtures/grafanacloudlogs/create.yaml @@ -0,0 +1,65 @@ +--- +version: 1 +interactions: +- request: + body: format=format&index=%7B%22env%22%3A+%22prod%22%7D&name=test-grafanacloudlogs&placement=waf_debug&token=abcd1234&url=https%3A%2F%2Ftest123.grafana.net&user=123456 + form: + format: + - format + index: + - '{"env": "prod"}' + name: + - test-grafanacloudlogs + placement: + - waf_debug + token: + - abcd1234 + url: + - https://test123.grafana.net + user: + - "123456" + headers: + Content-Type: + - application/x-www-form-urlencoded + User-Agent: + - FastlyGo/9.8.0 (+github.com/fastly/go-fastly; go1.23.2) + url: https://api.fastly.com/service/7i6HN3TK9wS159v2gPAZ8A/version/138/logging/grafanacloudlogs + method: POST + response: + body: '{"format":"format","index":"{\"env\": \"prod\"}","name":"test-grafanacloudlogs","placement":"waf_debug","token":"abcd1234","url":"https://test123.grafana.net","user":"123456","service_id":"7i6HN3TK9wS159v2gPAZ8A","version":"138","updated_at":"2024-10-24T19:43:58Z","deleted_at":null,"format_version":"2","created_at":"2024-10-24T19:43:58Z","response_condition":""}' + headers: + Accept-Ranges: + - bytes + Cache-Control: + - no-store + Content-Type: + - application/json + Date: + - Thu, 24 Oct 2024 19:43:58 GMT + Fastly-Ratelimit-Remaining: + - "991" + Fastly-Ratelimit-Reset: + - "1729800000" + Pragma: + - no-cache + Server: + - control-gateway + Status: + - 200 OK + Strict-Transport-Security: + - max-age=31536000 + Vary: + - Accept-Encoding + Via: + - 1.1 varnish, 1.1 varnish + X-Cache: + - MISS, MISS + X-Cache-Hits: + - 0, 0 + X-Served-By: + - cache-chi-klot8100074-CHI, cache-bos4679-BOS + X-Timer: + - S1729799038.016898,VS0,VE338 + status: 200 OK + code: 200 + duration: "" diff --git a/fastly/fixtures/grafanacloudlogs/delete.yaml b/fastly/fixtures/grafanacloudlogs/delete.yaml new file mode 100644 index 000000000..da562525b --- /dev/null +++ b/fastly/fixtures/grafanacloudlogs/delete.yaml @@ -0,0 +1,49 @@ +--- +version: 1 +interactions: +- request: + body: "" + form: {} + headers: + User-Agent: + - FastlyGo/9.8.0 (+github.com/fastly/go-fastly; go1.23.2) + url: https://api.fastly.com/service/7i6HN3TK9wS159v2gPAZ8A/version/138/logging/grafanacloudlogs/new-test-grafanacloudlogs + method: DELETE + response: + body: '{"status":"ok"}' + headers: + Accept-Ranges: + - bytes + Cache-Control: + - no-store + Content-Type: + - application/json + Date: + - Thu, 24 Oct 2024 19:43:59 GMT + Fastly-Ratelimit-Remaining: + - "989" + Fastly-Ratelimit-Reset: + - "1729800000" + Pragma: + - no-cache + Server: + - control-gateway + Status: + - 200 OK + Strict-Transport-Security: + - max-age=31536000 + Vary: + - Accept-Encoding + Via: + - 1.1 varnish, 1.1 varnish + X-Cache: + - MISS, MISS + X-Cache-Hits: + - 0, 0 + X-Served-By: + - cache-chi-kigq8000154-CHI, cache-bos4679-BOS + X-Timer: + - S1729799039.017911,VS0,VE270 + status: 200 OK + code: 200 + duration: "" diff --git a/fastly/fixtures/grafanacloudlogs/get.yaml b/fastly/fixtures/grafanacloudlogs/get.yaml new file mode 100644 index 000000000..53e0f43ba --- /dev/null +++ b/fastly/fixtures/grafanacloudlogs/get.yaml @@ -0,0 +1,46 @@ +--- +version: 1 +interactions: +- request: + body: "" + form: {} + headers: + User-Agent: + - FastlyGo/9.8.0 (+github.com/fastly/go-fastly; go1.23.2) + url: https://api.fastly.com/service/7i6HN3TK9wS159v2gPAZ8A/version/138/logging/grafanacloudlogs/test-grafanacloudlogs + method: GET + response: + body: '{"placement":"waf_debug","name":"test-grafanacloudlogs","response_condition":"","user":"123456","updated_at":"2024-10-24T19:43:58Z","format_version":"2","format":"format","token":"abcd1234","deleted_at":null,"created_at":"2024-10-24T19:43:58Z","url":"https://test123.grafana.net","index":"{\"env\": + \"prod\"}","version":"138","service_id":"7i6HN3TK9wS159v2gPAZ8A"}' + headers: + Accept-Ranges: + - bytes + Cache-Control: + - no-store + Content-Type: + - application/json + Date: + - Thu, 24 Oct 2024 19:43:58 GMT + Pragma: + - no-cache + Server: + - control-gateway + Status: + - 200 OK + Strict-Transport-Security: + - max-age=31536000 + Vary: + - Accept-Encoding + Via: + - 1.1 varnish, 1.1 varnish + X-Cache: + - MISS, MISS + X-Cache-Hits: + - 0, 0 + X-Served-By: + - cache-chi-kigq8000134-CHI, cache-bos4679-BOS + X-Timer: + - S1729799039.526983,VS0,VE107 + status: 200 OK + code: 200 + duration: "" diff --git a/fastly/fixtures/grafanacloudlogs/list.yaml b/fastly/fixtures/grafanacloudlogs/list.yaml new file mode 100644 index 000000000..88c2aac13 --- /dev/null +++ b/fastly/fixtures/grafanacloudlogs/list.yaml @@ -0,0 +1,45 @@ +--- +version: 1 +interactions: +- request: + body: "" + form: {} + headers: + User-Agent: + - FastlyGo/9.8.0 (+github.com/fastly/go-fastly; go1.23.2) + url: https://api.fastly.com/service/7i6HN3TK9wS159v2gPAZ8A/version/138/logging/grafanacloudlogs + method: GET + response: + body: '[{"url":"https://test123.grafana.net","index":"{\"env\": \"prod\"}","format":"format","created_at":"2024-10-24T19:43:58Z","format_version":"2","response_condition":"","placement":"waf_debug","updated_at":"2024-10-24T19:43:58Z","service_id":"7i6HN3TK9wS159v2gPAZ8A","deleted_at":null,"name":"test-grafanacloudlogs","token":"abcd1234","version":"138","user":"123456"}]' + headers: + Accept-Ranges: + - bytes + Cache-Control: + - no-store + Content-Type: + - application/json + Date: + - Thu, 24 Oct 2024 19:43:58 GMT + Pragma: + - no-cache + Server: + - control-gateway + Status: + - 200 OK + Strict-Transport-Security: + - max-age=31536000 + Vary: + - Accept-Encoding + Via: + - 1.1 varnish, 1.1 varnish + X-Cache: + - MISS, MISS + X-Cache-Hits: + - 0, 0 + X-Served-By: + - cache-chi-klot8100074-CHI, cache-bos4679-BOS + X-Timer: + - S1729799038.385714,VS0,VE115 + status: 200 OK + code: 200 + duration: "" diff --git a/fastly/fixtures/grafanacloudlogs/update.yaml b/fastly/fixtures/grafanacloudlogs/update.yaml new file mode 100644 index 000000000..bebf355dc --- /dev/null +++ b/fastly/fixtures/grafanacloudlogs/update.yaml @@ -0,0 +1,64 @@ +--- +version: 1 +interactions: +- request: + body: format_version=2&index=%7B%22env%22%3A+%22staging%22%7D&name=new-test-grafanacloudlogs&placement=waf_debug&token=abcd6789&url=https%3A%2F%2Ftest456.grafana.net + form: + format_version: + - "2" + index: + - '{"env": "staging"}' + name: + - new-test-grafanacloudlogs + placement: + - waf_debug + token: + - abcd6789 + url: + - https://test456.grafana.net + headers: + Content-Type: + - application/x-www-form-urlencoded + User-Agent: + - FastlyGo/9.8.0 (+github.com/fastly/go-fastly; go1.23.2) + url: https://api.fastly.com/service/7i6HN3TK9wS159v2gPAZ8A/version/138/logging/grafanacloudlogs/test-grafanacloudlogs + method: PUT + response: + body: '{"deleted_at":null,"token":"abcd6789","name":"new-test-grafanacloudlogs","version":"138","user":"123456","updated_at":"2024-10-24T19:43:58Z","service_id":"7i6HN3TK9wS159v2gPAZ8A","format":"format","created_at":"2024-10-24T19:43:58Z","format_version":"2","response_condition":"","placement":"waf_debug","url":"https://test456.grafana.net","index":"{\"env\": + \"staging\"}"}' + headers: + Accept-Ranges: + - bytes + Cache-Control: + - no-store + Content-Type: + - application/json + Date: + - Thu, 24 Oct 2024 19:43:58 GMT + Fastly-Ratelimit-Remaining: + - "990" + Fastly-Ratelimit-Reset: + - "1729800000" + Pragma: + - no-cache + Server: + - control-gateway + Status: + - 200 OK + Strict-Transport-Security: + - max-age=31536000 + Vary: + - Accept-Encoding + Via: + - 1.1 varnish, 1.1 varnish + X-Cache: + - MISS, MISS + X-Cache-Hits: + - 0, 0 + X-Served-By: + - cache-chi-kigq8000134-CHI, cache-bos4679-BOS + X-Timer: + - S1729799039.663242,VS0,VE328 + status: 200 OK + code: 200 + duration: "" diff --git a/fastly/fixtures/grafanacloudlogs/version.yaml b/fastly/fixtures/grafanacloudlogs/version.yaml new file mode 100644 index 000000000..e9ea9b330 --- /dev/null +++ b/fastly/fixtures/grafanacloudlogs/version.yaml @@ -0,0 +1,51 @@ +--- +version: 1 +interactions: +- request: + body: "" + form: {} + headers: + Content-Type: + - application/x-www-form-urlencoded + User-Agent: + - FastlyGo/9.8.0 (+github.com/fastly/go-fastly; go1.23.2) + url: https://api.fastly.com/service/7i6HN3TK9wS159v2gPAZ8A/version + method: POST + response: + body: '{"service_id":"7i6HN3TK9wS159v2gPAZ8A","number":138}' + headers: + Accept-Ranges: + - bytes + Cache-Control: + - no-store + Content-Type: + - application/json + Date: + - Thu, 24 Oct 2024 19:43:57 GMT + Fastly-Ratelimit-Remaining: + - "992" + Fastly-Ratelimit-Reset: + - "1729800000" + Pragma: + - no-cache + Server: + - control-gateway + Status: + - 200 OK + Strict-Transport-Security: + - max-age=31536000 + Vary: + - Accept-Encoding + Via: + - 1.1 varnish, 1.1 varnish + X-Cache: + - MISS, MISS + X-Cache-Hits: + - 0, 0 + X-Served-By: + - cache-chi-kigq8000137-CHI, cache-bos4679-BOS + X-Timer: + - S1729799038.708215,VS0,VE273 + status: 200 OK + code: 200 + duration: "" diff --git a/fastly/logging_grafanacloudlogs.go b/fastly/logging_grafanacloudlogs.go new file mode 100644 index 000000000..380b80a71 --- /dev/null +++ b/fastly/logging_grafanacloudlogs.go @@ -0,0 +1,232 @@ +package fastly + +import ( + "strconv" + "time" +) + +// GrafanaCloudLogs represents a GrafanaCloudLogs response from the Fastly API. +type GrafanaCloudLogs struct { + CreatedAt *time.Time `mapstructure:"created_at"` + DeletedAt *time.Time `mapstructure:"deleted_at"` + Format *string `mapstructure:"format"` + FormatVersion *int `mapstructure:"format_version"` + Name *string `mapstructure:"name"` + Placement *string `mapstructure:"placement"` + ResponseCondition *string `mapstructure:"response_condition"` + ServiceID *string `mapstructure:"service_id"` + ServiceVersion *int `mapstructure:"version"` + UpdatedAt *time.Time `mapstructure:"updated_at"` + + Index *string `mapstructure:"index"` + Token *string `mapstructure:"token"` + URL *string `mapstructure:"url"` + User *string `mapstructure:"user"` +} + +// ListGrafanaCloudLogsInput is used as input to the ListGrafanaCloudLogs function. +type ListGrafanaCloudLogsInput struct { + // ServiceID is the ID of the service (required). + ServiceID string + // ServiceVersion is the specific configuration version (required). + ServiceVersion int +} + +// ListGrafanaCloudLogs retrieves all resources. +func (c *Client) ListGrafanaCloudLogs(i *ListGrafanaCloudLogsInput) ([]*GrafanaCloudLogs, error) { + if i.ServiceID == "" { + return nil, ErrMissingServiceID + } + if i.ServiceVersion == 0 { + return nil, ErrMissingServiceVersion + } + + path := ToSafeURL("service", i.ServiceID, "version", strconv.Itoa(i.ServiceVersion), "logging", "grafanacloudlogs") + resp, err := c.Get(path, nil) + if err != nil { + return nil, err + } + defer resp.Body.Close() + + var d []*GrafanaCloudLogs + if err := decodeBodyMap(resp.Body, &d); err != nil { + return nil, err + } + return d, nil +} + +// CreateGrafanaCloudLogsInput is used as input to the CreateGrafanaCloudLogs function. +type CreateGrafanaCloudLogsInput struct { + // Format is a Fastly log format string. Must produce valid JSON that GrafanaCloudLogs can ingest. + Format *string `url:"format,omitempty"` + // FormatVersion is the version of the custom logging format used for the configured endpoint. + FormatVersion *int `url:"format_version,omitempty"` + // Name is the name for the real-time logging configuration. + Name *string `url:"name,omitempty"` + // Placement is where in the generated VCL the logging call should be placed. + Placement *string `url:"placement,omitempty"` + // ResponseCondition is the name of an existing condition in the configured endpoint, or leave blank to always execute. + ResponseCondition *string `url:"response_condition,omitempty"` + // ServiceID is the ID of the service (required). + ServiceID string `url:"-"` + // ServiceVersion is the specific configuration version (required). + ServiceVersion int `url:"-"` + // Index + Index *string `url:"index,omitempty"` + // Token is the API key from your GrafanaCloudLogs account. + Token *string `url:"token,omitempty"` + // Index + User *string `url:"user,omitempty"` + // URL is the URL to stream logs to. Must use HTTPS. + URL *string `url:"url,omitempty"` +} + +// CreateGrafanaCloudLogs creates a new resource. +func (c *Client) CreateGrafanaCloudLogs(i *CreateGrafanaCloudLogsInput) (*GrafanaCloudLogs, error) { + if i.ServiceID == "" { + return nil, ErrMissingServiceID + } + if i.ServiceVersion == 0 { + return nil, ErrMissingServiceVersion + } + + path := ToSafeURL("service", i.ServiceID, "version", strconv.Itoa(i.ServiceVersion), "logging", "grafanacloudlogs") + resp, err := c.PostForm(path, i, nil) + if err != nil { + return nil, err + } + defer resp.Body.Close() + + var d *GrafanaCloudLogs + if err := decodeBodyMap(resp.Body, &d); err != nil { + return nil, err + } + return d, nil +} + +// GetGrafanaCloudLogsInput is used as input to the GetGrafanaCloudLogs function. +type GetGrafanaCloudLogsInput struct { + // Name is the name of the GrafanaCloudLogs to fetch (required). + Name string + // ServiceID is the ID of the service (required). + ServiceID string + // ServiceVersion is the specific configuration version (required). + ServiceVersion int +} + +// GetGrafanaCloudLogs retrieves the specified resource. +func (c *Client) GetGrafanaCloudLogs(i *GetGrafanaCloudLogsInput) (*GrafanaCloudLogs, error) { + if i.Name == "" { + return nil, ErrMissingName + } + if i.ServiceID == "" { + return nil, ErrMissingServiceID + } + if i.ServiceVersion == 0 { + return nil, ErrMissingServiceVersion + } + + path := ToSafeURL("service", i.ServiceID, "version", strconv.Itoa(i.ServiceVersion), "logging", "grafanacloudlogs", i.Name) + resp, err := c.Get(path, nil) + if err != nil { + return nil, err + } + defer resp.Body.Close() + + var d *GrafanaCloudLogs + if err := decodeBodyMap(resp.Body, &d); err != nil { + return nil, err + } + return d, nil +} + +// UpdateGrafanaCloudLogsInput is used as input to the UpdateGrafanaCloudLogs function. +type UpdateGrafanaCloudLogsInput struct { + // Format is a Fastly log format string. Must produce valid JSON that GrafanaCloudLogs can ingest. + Format *string `url:"format,omitempty"` + // FormatVersion is the version of the custom logging format used for the configured endpoint. + FormatVersion *int `url:"format_version,omitempty"` + // Name is the name of the GrafanaCloudLogs to update (required). + Name string `url:"-"` + // NewName is the new name for the resource. + NewName *string `url:"name,omitempty"` + // Placement is where in the generated VCL the logging call should be placed. + Placement *string `url:"placement,omitempty"` + // URL is the URL to stream logs to. Must use HTTPS. + URL *string `url:"url,omitempty"` + // ResponseCondition is the name of an existing condition in the configured endpoint, or leave blank to always execute. + ResponseCondition *string `url:"response_condition,omitempty"` + // ServiceID is the ID of the service (required). + ServiceID string `url:"-"` + // ServiceVersion is the specific configuration version (required). + ServiceVersion int `url:"-"` + // Token is the API key from your GrafanaCloudLogs account. + Token *string `url:"token,omitempty"` + // Index is the stream identifier + Index *string `url:"index,omitempty"` +} + +// UpdateGrafanaCloudLogs updates the specified resource. +func (c *Client) UpdateGrafanaCloudLogs(i *UpdateGrafanaCloudLogsInput) (*GrafanaCloudLogs, error) { + if i.Name == "" { + return nil, ErrMissingName + } + if i.ServiceID == "" { + return nil, ErrMissingServiceID + } + if i.ServiceVersion == 0 { + return nil, ErrMissingServiceVersion + } + + path := ToSafeURL("service", i.ServiceID, "version", strconv.Itoa(i.ServiceVersion), "logging", "grafanacloudlogs", i.Name) + resp, err := c.PutForm(path, i, nil) + if err != nil { + return nil, err + } + defer resp.Body.Close() + + var d *GrafanaCloudLogs + if err := decodeBodyMap(resp.Body, &d); err != nil { + return nil, err + } + return d, nil +} + +// DeleteGrafanaCloudLogsInput is the input parameter to DeleteGrafanaCloudLogs. +type DeleteGrafanaCloudLogsInput struct { + // Name is the name of the GrafanaCloudLogs to delete (required). + Name string + // ServiceID is the ID of the service (required). + ServiceID string + // ServiceVersion is the specific configuration version (required). + ServiceVersion int +} + +// DeleteGrafanaCloudLogs deletes the specified resource. +func (c *Client) DeleteGrafanaCloudLogs(i *DeleteGrafanaCloudLogsInput) error { + if i.Name == "" { + return ErrMissingName + } + if i.ServiceID == "" { + return ErrMissingServiceID + } + if i.ServiceVersion == 0 { + return ErrMissingServiceVersion + } + + path := ToSafeURL("service", i.ServiceID, "version", strconv.Itoa(i.ServiceVersion), "logging", "grafanacloudlogs", i.Name) + resp, err := c.Delete(path, nil) + if err != nil { + return err + } + defer resp.Body.Close() + + var r *statusResp + if err := decodeBodyMap(resp.Body, &r); err != nil { + return err + } + if !r.Ok() { + return ErrStatusNotOk + } + return nil +} diff --git a/fastly/logging_grafanacloudlogs_test.go b/fastly/logging_grafanacloudlogs_test.go new file mode 100644 index 000000000..ac4ec11dd --- /dev/null +++ b/fastly/logging_grafanacloudlogs_test.go @@ -0,0 +1,281 @@ +package fastly + +import ( + "testing" +) + +func TestClient_GrafanaCloudLogs(t *testing.T) { + t.Parallel() + + var err error + var tv *Version + record(t, "grafanacloudlogs/version", func(c *Client) { + tv = testVersion(t, c) + }) + + // Create + var d *GrafanaCloudLogs + record(t, "grafanacloudlogs/create", func(c *Client) { + d, err = c.CreateGrafanaCloudLogs(&CreateGrafanaCloudLogsInput{ + ServiceID: testServiceID, + ServiceVersion: *tv.Number, + Name: ToPointer("test-grafanacloudlogs"), + URL: ToPointer("https://test123.grafana.net"), + User: ToPointer("123456"), + Token: ToPointer("abcd1234"), + Format: ToPointer("format"), + Placement: ToPointer("waf_debug"), + Index: ToPointer("{\"env\": \"prod\"}"), + }) + }) + if err != nil { + t.Fatal(err) + } + + // Ensure deleted + defer func() { + record(t, "grafanacloudlogs/delete", func(c *Client) { + _ = c.DeleteGrafanaCloudLogs(&DeleteGrafanaCloudLogsInput{ + ServiceID: testServiceID, + ServiceVersion: *tv.Number, + Name: "test-grafanacloudlogs", + }) + + _ = c.DeleteGrafanaCloudLogs(&DeleteGrafanaCloudLogsInput{ + ServiceID: testServiceID, + ServiceVersion: *tv.Number, + Name: "new-test-grafanacloudlogs", + }) + }) + }() + + if *d.Name != "test-grafanacloudlogs" { + t.Errorf("bad name: %q", *d.Name) + } + if *d.Token != "abcd1234" { + t.Errorf("bad token: %q", *d.Token) + } + if *d.URL != "https://test123.grafana.net" { + t.Errorf("bad URL: %q", *d.URL) + } + if *d.Index != "{\"env\": \"prod\"}" { + t.Errorf("bad index: %q", *d.Index) + } + if *d.Format != "format" { + t.Errorf("bad format: %q", *d.Format) + } + if *d.FormatVersion != 2 { + t.Errorf("bad format_version: %q", *d.FormatVersion) + } + if *d.Placement != "waf_debug" { + t.Errorf("bad placement: %q", *d.Placement) + } + + // List + var ld []*GrafanaCloudLogs + record(t, "grafanacloudlogs/list", func(c *Client) { + ld, err = c.ListGrafanaCloudLogs(&ListGrafanaCloudLogsInput{ + ServiceID: testServiceID, + ServiceVersion: *tv.Number, + }) + }) + if err != nil { + t.Fatal(err) + } + if len(ld) < 1 { + t.Errorf("bad GrafanaCloudLogss: %v", ld) + } + + // Get + var nd *GrafanaCloudLogs + record(t, "grafanacloudlogs/get", func(c *Client) { + nd, err = c.GetGrafanaCloudLogs(&GetGrafanaCloudLogsInput{ + ServiceID: testServiceID, + ServiceVersion: *tv.Number, + Name: "test-grafanacloudlogs", + }) + }) + if err != nil { + t.Fatal(err) + } + if *d.Name != *nd.Name { + t.Errorf("bad name: %q", *d.Name) + } + if *d.Token != *nd.Token { + t.Errorf("bad token: %q", *d.Token) + } + if *d.Format != *nd.Format { + t.Errorf("bad format: %q", *d.Format) + } + if *d.FormatVersion != *nd.FormatVersion { + t.Errorf("bad format_version: %q", *d.FormatVersion) + } + if *d.Placement != *nd.Placement { + t.Errorf("bad placement: %q", *d.Placement) + } + + // Update + var ud *GrafanaCloudLogs + record(t, "grafanacloudlogs/update", func(c *Client) { + ud, err = c.UpdateGrafanaCloudLogs(&UpdateGrafanaCloudLogsInput{ + ServiceID: testServiceID, + ServiceVersion: *tv.Number, + Name: "test-grafanacloudlogs", + NewName: ToPointer("new-test-grafanacloudlogs"), + FormatVersion: ToPointer(2), + URL: ToPointer("https://test456.grafana.net"), + Token: ToPointer("abcd6789"), + Placement: ToPointer("waf_debug"), + Index: ToPointer("{\"env\": \"staging\"}"), + }) + }) + if err != nil { + t.Fatal(err) + } + if *ud.Name != "new-test-grafanacloudlogs" { + t.Errorf("bad name: %q", *ud.Name) + } + if *ud.FormatVersion != 2 { + t.Errorf("bad format_version: %q", *ud.FormatVersion) + } + if *ud.URL != "https://test456.grafana.net" { + t.Errorf("bad url: %q", *ud.URL) + } + if *ud.Index != "{\"env\": \"staging\"}" { + t.Errorf("bad index: %q", *d.Index) + } + + // Delete + record(t, "grafanacloudlogs/delete", func(c *Client) { + err = c.DeleteGrafanaCloudLogs(&DeleteGrafanaCloudLogsInput{ + ServiceID: testServiceID, + ServiceVersion: *tv.Number, + Name: "new-test-grafanacloudlogs", + }) + }) + if err != nil { + t.Fatal(err) + } +} + +func TestClient_ListGrafanaCloudLogs_validation(t *testing.T) { + var err error + + _, err = testClient.ListGrafanaCloudLogs(&ListGrafanaCloudLogsInput{ + ServiceID: "", + }) + if err != ErrMissingServiceID { + t.Errorf("bad error: %s", err) + } + + _, err = testClient.ListGrafanaCloudLogs(&ListGrafanaCloudLogsInput{ + ServiceID: "foo", + ServiceVersion: 0, + }) + if err != ErrMissingServiceVersion { + t.Errorf("bad error: %s", err) + } +} + +func TestClient_CreateGrafanaCloudLogs_validation(t *testing.T) { + var err error + + _, err = testClient.CreateGrafanaCloudLogs(&CreateGrafanaCloudLogsInput{ + ServiceID: "", + }) + if err != ErrMissingServiceID { + t.Errorf("bad error: %s", err) + } + + _, err = testClient.CreateGrafanaCloudLogs(&CreateGrafanaCloudLogsInput{ + ServiceID: "foo", + ServiceVersion: 0, + }) + if err != ErrMissingServiceVersion { + t.Errorf("bad error: %s", err) + } +} + +func TestClient_GetGrafanaCloudLogs_validation(t *testing.T) { + var err error + + _, err = testClient.GetGrafanaCloudLogs(&GetGrafanaCloudLogsInput{ + ServiceID: "foo", + ServiceVersion: 1, + }) + if err != ErrMissingName { + t.Errorf("bad error: %s", err) + } + + _, err = testClient.GetGrafanaCloudLogs(&GetGrafanaCloudLogsInput{ + Name: "test", + ServiceVersion: 1, + }) + if err != ErrMissingServiceID { + t.Errorf("bad error: %s", err) + } + + _, err = testClient.GetGrafanaCloudLogs(&GetGrafanaCloudLogsInput{ + Name: "test", + ServiceID: "foo", + }) + if err != ErrMissingServiceVersion { + t.Errorf("bad error: %s", err) + } +} + +func TestClient_UpdateGrafanaCloudLogs_validation(t *testing.T) { + var err error + + _, err = testClient.UpdateGrafanaCloudLogs(&UpdateGrafanaCloudLogsInput{ + ServiceID: "foo", + ServiceVersion: 1, + }) + if err != ErrMissingName { + t.Errorf("bad error: %s", err) + } + + _, err = testClient.UpdateGrafanaCloudLogs(&UpdateGrafanaCloudLogsInput{ + Name: "test", + ServiceVersion: 1, + }) + if err != ErrMissingServiceID { + t.Errorf("bad error: %s", err) + } + + _, err = testClient.UpdateGrafanaCloudLogs(&UpdateGrafanaCloudLogsInput{ + Name: "test", + ServiceID: "foo", + }) + if err != ErrMissingServiceVersion { + t.Errorf("bad error: %s", err) + } +} + +func TestClient_DeleteGrafanaCloudLogs_validation(t *testing.T) { + var err error + + err = testClient.DeleteGrafanaCloudLogs(&DeleteGrafanaCloudLogsInput{ + ServiceID: "foo", + ServiceVersion: 1, + }) + if err != ErrMissingName { + t.Errorf("bad error: %s", err) + } + + err = testClient.DeleteGrafanaCloudLogs(&DeleteGrafanaCloudLogsInput{ + Name: "test", + ServiceVersion: 1, + }) + if err != ErrMissingServiceID { + t.Errorf("bad error: %s", err) + } + + err = testClient.DeleteGrafanaCloudLogs(&DeleteGrafanaCloudLogsInput{ + Name: "test", + ServiceID: "foo", + }) + if err != ErrMissingServiceVersion { + t.Errorf("bad error: %s", err) + } +}