From e1163b37dfc116e340c18d55ae83578d21193f00 Mon Sep 17 00:00:00 2001 From: Jacob White Date: Fri, 18 Nov 2022 22:01:51 -0500 Subject: [PATCH 1/4] Add support for workers domain API --- .changelog/1130.txt | 3 + workers_domain.go | 126 +++++++++++++++++++++++++++++ workers_domain_test.go | 180 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 309 insertions(+) create mode 100644 .changelog/1130.txt create mode 100644 workers_domain.go create mode 100644 workers_domain_test.go diff --git a/.changelog/1130.txt b/.changelog/1130.txt new file mode 100644 index 000000000..229e12b78 --- /dev/null +++ b/.changelog/1130.txt @@ -0,0 +1,3 @@ +```release-note:enhancement +workers_domain: add support for workers domain API +``` \ No newline at end of file diff --git a/workers_domain.go b/workers_domain.go new file mode 100644 index 000000000..b2ae4ca0d --- /dev/null +++ b/workers_domain.go @@ -0,0 +1,126 @@ +package cloudflare + +import ( + "context" + "encoding/json" + "errors" + "fmt" + "net/http" +) + +var ( + ErrMissingHostname = errors.New("required hostname missing") + ErrMissingService = errors.New("required service missing") + ErrMissingEnvironment = errors.New("required environment missing") +) + +type WorkersDomain struct { + ID string `json:"id,omitempty"` + ZoneID string `json:"zone_id,omitempty"` + ZoneName string `json:"zone_name,omitempty"` + Hostname string `json:"hostname,omitempty"` + Service string `json:"service,omitempty"` + Environment string `json:"environment,omitempty"` +} + +type WorkersDomainResponse struct { + Response + Result WorkersDomain `json:"result"` +} + +type WorkersDomainListParams struct { + ZoneID string `url:"zone_id,omitempty"` + ZoneName string `url:"zone_name,omitempty"` + Hostname string `url:"hostname,omitempty"` + Service string `url:"service,omitempty"` + Environment string `url:"environment,omitempty"` +} + +type WorkersDomainListResponse struct { + Response + Result []WorkersDomain `json:"result"` +} + +// WorkersListDomains lists all Worker Domains. +// +// API reference: https://developers.cloudflare.com/api/operations/worker-domain-list-domains +func (api *API) WorkersListDomains(ctx context.Context, rc *ResourceContainer, params WorkersDomainListParams) ([]WorkersDomain, error) { + if rc.Identifier == "" { + return []WorkersDomain{}, ErrMissingAccountID + } + uri := buildURI(fmt.Sprintf("/accounts/%s/workers/domains", rc.Identifier), params) + res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil) + if err != nil { + return []WorkersDomain{}, fmt.Errorf("%s: %w", errMakeRequestError, err) + } + var r WorkersDomainListResponse + if err := json.Unmarshal(res, &r); err != nil { + return []WorkersDomain{}, fmt.Errorf("%s: %w", errUnmarshalError, err) + } + return r.Result, nil +} + +// WorkersAttachDomain attaches a worker to a zone and hostname. +// +// API reference: https://developers.cloudflare.com/api/operations/worker-domain-attach-to-domain +func (api *API) WorkersAttachDomain(ctx context.Context, rc *ResourceContainer, domain WorkersDomain) (WorkersDomain, error) { + if rc.Identifier == "" { + return WorkersDomain{}, ErrMissingAccountID + } + if domain.ZoneID == "" { + return WorkersDomain{}, ErrMissingZoneID + } + if domain.Hostname == "" { + return WorkersDomain{}, ErrMissingHostname + } + if domain.Service == "" { + return WorkersDomain{}, ErrMissingService + } + if domain.Environment == "" { + return WorkersDomain{}, ErrMissingEnvironment + } + uri := fmt.Sprintf("/accounts/%s/workers/domains", rc.Identifier) + res, err := api.makeRequestContext(ctx, http.MethodPut, uri, domain) + if err != nil { + return WorkersDomain{}, fmt.Errorf("%s: %w", errMakeRequestError, err) + } + var r WorkersDomainResponse + if err := json.Unmarshal(res, &r); err != nil { + return WorkersDomain{}, fmt.Errorf("%s: %w", errUnmarshalError, err) + } + return r.Result, nil +} + +// WorkersDetachDomain detaches a worker from a zone and hostname. +// +// API reference: https://developers.cloudflare.com/api/operations/worker-domain-detach-from-domain +func (api *API) WorkersDetachDomain(ctx context.Context, rc *ResourceContainer, domainID string) error { + if rc.Identifier == "" { + return ErrMissingAccountID + } + uri := fmt.Sprintf("/accounts/%s/workers/domains/%s", rc.Identifier, domainID) + _, err := api.makeRequestContext(ctx, http.MethodDelete, uri, nil) + if err != nil { + return fmt.Errorf("%s: %w", errMakeRequestError, err) + } + return nil +} + +// WorkersGetDomain gets a Worker Domain. +// +// API reference: https://developers.cloudflare.com/api/operations/worker-domain-get-a-domain +func (api *API) WorkersGetDomain(ctx context.Context, rc *ResourceContainer, domainID string) (WorkersDomain, error) { + if rc.Identifier == "" { + return WorkersDomain{}, ErrMissingAccountID + } + uri := fmt.Sprintf("/accounts/%s/workers/domains/%s", rc.Identifier, domainID) + res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil) + if err != nil { + return WorkersDomain{}, fmt.Errorf("%s: %w", errMakeRequestError, err) + } + var r WorkersDomainResponse + if err := json.Unmarshal(res, &r); err != nil { + return WorkersDomain{}, fmt.Errorf("%s: %w", errUnmarshalError, err) + } + return r.Result, nil +} diff --git a/workers_domain_test.go b/workers_domain_test.go new file mode 100644 index 000000000..f9a82d74d --- /dev/null +++ b/workers_domain_test.go @@ -0,0 +1,180 @@ +package cloudflare + +import ( + "context" + "fmt" + "github.com/stretchr/testify/assert" + "net/http" + "testing" +) + +const testWorkerDomainID = "dbe10b4bc17c295377eabd600e1787fd" + +var expectedWorkerDomain = WorkersDomain{ + ID: testWorkerDomainID, + ZoneID: "593c9c94de529bbbfaac7c53ced0447d", + ZoneName: "example.com", + Hostname: "foo.example.com", + Service: "foo", + Environment: "production", +} + +func TestWorkersDomain_GetDomain(t *testing.T) { + setup() + defer teardown() + + mux.HandleFunc(fmt.Sprintf("/accounts/%s/workers/domains/%s", testAccountID, testWorkerDomainID), func(w http.ResponseWriter, r *http.Request) { + assert.Equal(t, http.MethodGet, r.Method, "Expected method 'GET', got %s", r.Method) + w.Header().Set("content-type", "application/json") + fmt.Fprintf(w, `{ + "success": true, + "errors": [], + "messages": [], + "result": { + "id": "dbe10b4bc17c295377eabd600e1787fd", + "zone_id": "593c9c94de529bbbfaac7c53ced0447d", + "zone_name": "example.com", + "hostname": "foo.example.com", + "service": "foo", + "environment": "production" + } + }`) + }) + _, err := client.WorkersGetDomain(context.Background(), AccountIdentifier(""), "") + if assert.Error(t, err) { + assert.Equal(t, ErrMissingAccountID, err) + } + res, err := client.WorkersGetDomain(context.Background(), AccountIdentifier(testAccountID), testWorkerDomainID) + if assert.NoError(t, err) { + assert.Equal(t, expectedWorkerDomain, res) + } +} + +func TestWorkersDomain_ListDomains(t *testing.T) { + setup() + defer teardown() + + mux.HandleFunc(fmt.Sprintf("/accounts/%s/workers/domains", testAccountID), func(w http.ResponseWriter, r *http.Request) { + assert.Equal(t, http.MethodGet, r.Method, "Expected method 'GET', got %s", r.Method) + w.Header().Set("content-type", "application/json") + fmt.Fprintf(w, `{ + "success": true, + "errors": [], + "messages": [], + "result": [ + { + "id": "dbe10b4bc17c295377eabd600e1787fd", + "zone_id": "593c9c94de529bbbfaac7c53ced0447d", + "zone_name": "example.com", + "hostname": "foo.example.com", + "service": "foo", + "environment": "production" + } + ] + }`) + }) + _, err := client.WorkersListDomains(context.Background(), AccountIdentifier(""), WorkersDomainListParams{}) + if assert.Error(t, err) { + assert.Equal(t, ErrMissingAccountID, err) + } + res, err := client.WorkersListDomains(context.Background(), AccountIdentifier(testAccountID), WorkersDomainListParams{}) + if assert.NoError(t, err) { + assert.Equal(t, 1, len(res)) + assert.Equal(t, expectedWorkerDomain, res[0]) + } +} + +func TestWorkersDomain_AttachDomain(t *testing.T) { + setup() + defer teardown() + + mux.HandleFunc(fmt.Sprintf("/accounts/%s/workers/domains", testAccountID), func(w http.ResponseWriter, r *http.Request) { + assert.Equal(t, http.MethodPut, r.Method, "Expected method 'PUT', got %s", r.Method) + w.Header().Set("content-type", "application/json") + fmt.Fprintf(w, `{ + "success": true, + "errors": [], + "messages": [], + "result": { + "id": "dbe10b4bc17c295377eabd600e1787fd", + "zone_id": "593c9c94de529bbbfaac7c53ced0447d", + "zone_name": "example.com", + "hostname": "foo.example.com", + "service": "foo", + "environment": "production" + } + }`) + }) + _, err := client.WorkersAttachDomain(context.Background(), AccountIdentifier(""), WorkersDomain{}) + if assert.Error(t, err) { + assert.Equal(t, ErrMissingAccountID, err) + } + + _, err = client.WorkersAttachDomain(context.Background(), AccountIdentifier(testAccountID), WorkersDomain{}) + if assert.Error(t, err) { + assert.Equal(t, ErrMissingZoneID, err) + } + + _, err = client.WorkersAttachDomain(context.Background(), AccountIdentifier(testAccountID), WorkersDomain{ + ZoneID: testZoneID, + }) + if assert.Error(t, err) { + assert.Equal(t, ErrMissingHostname, err) + } + + _, err = client.WorkersAttachDomain(context.Background(), AccountIdentifier(testAccountID), WorkersDomain{ + ZoneID: testZoneID, + Hostname: "foo.example.com", + }) + if assert.Error(t, err) { + assert.Equal(t, ErrMissingService, err) + } + + _, err = client.WorkersAttachDomain(context.Background(), AccountIdentifier(testAccountID), WorkersDomain{ + ZoneID: testZoneID, + Hostname: "foo.example.com", + Service: "foo", + }) + if assert.Error(t, err) { + assert.Equal(t, ErrMissingEnvironment, err) + } + + res, err := client.WorkersAttachDomain(context.Background(), AccountIdentifier(testAccountID), WorkersDomain{ + ZoneID: testZoneID, + Hostname: "foo.example.com", + Service: "foo", + Environment: "production", + }) + if assert.NoError(t, err) { + assert.Equal(t, expectedWorkerDomain, res) + } +} + +func TestWorkersDomain_DetachDomain(t *testing.T) { + setup() + defer teardown() + + mux.HandleFunc(fmt.Sprintf("/accounts/%s/workers/domains/%s", testAccountID, testWorkerDomainID), func(w http.ResponseWriter, r *http.Request) { + assert.Equal(t, http.MethodDelete, r.Method, "Expected method 'DELETE', got %s", r.Method) + w.Header().Set("content-type", "application/json") + fmt.Fprintf(w, `{ + "success": true, + "errors": [], + "messages": [], + "result": { + "id": "dbe10b4bc17c295377eabd600e1787fd", + "zone_id": "593c9c94de529bbbfaac7c53ced0447d", + "zone_name": "example.com", + "hostname": "foo.example.com", + "service": "foo", + "environment": "production" + } + }`) + }) + err := client.WorkersDetachDomain(context.Background(), AccountIdentifier(""), testWorkerDomainID) + if assert.Error(t, err) { + assert.Equal(t, ErrMissingAccountID, err) + } + err = client.WorkersDetachDomain(context.Background(), AccountIdentifier(testAccountID), testWorkerDomainID) + assert.NoError(t, err) +} From 5a9a2093462d9a0209167b1ffe9b41d82410210c Mon Sep 17 00:00:00 2001 From: Jacob White Date: Fri, 18 Nov 2022 22:05:48 -0500 Subject: [PATCH 2/4] Switch to old API docs --- workers_domain.go | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/workers_domain.go b/workers_domain.go index b2ae4ca0d..b70bb7734 100644 --- a/workers_domain.go +++ b/workers_domain.go @@ -43,7 +43,7 @@ type WorkersDomainListResponse struct { // WorkersListDomains lists all Worker Domains. // -// API reference: https://developers.cloudflare.com/api/operations/worker-domain-list-domains +// API reference: https://api.cloudflare.com/#worker-domain-list-domains func (api *API) WorkersListDomains(ctx context.Context, rc *ResourceContainer, params WorkersDomainListParams) ([]WorkersDomain, error) { if rc.Identifier == "" { return []WorkersDomain{}, ErrMissingAccountID @@ -62,7 +62,7 @@ func (api *API) WorkersListDomains(ctx context.Context, rc *ResourceContainer, p // WorkersAttachDomain attaches a worker to a zone and hostname. // -// API reference: https://developers.cloudflare.com/api/operations/worker-domain-attach-to-domain +// API reference: https://api.cloudflare.com/#worker-domain-attach-to-domain func (api *API) WorkersAttachDomain(ctx context.Context, rc *ResourceContainer, domain WorkersDomain) (WorkersDomain, error) { if rc.Identifier == "" { return WorkersDomain{}, ErrMissingAccountID @@ -91,24 +91,9 @@ func (api *API) WorkersAttachDomain(ctx context.Context, rc *ResourceContainer, return r.Result, nil } -// WorkersDetachDomain detaches a worker from a zone and hostname. -// -// API reference: https://developers.cloudflare.com/api/operations/worker-domain-detach-from-domain -func (api *API) WorkersDetachDomain(ctx context.Context, rc *ResourceContainer, domainID string) error { - if rc.Identifier == "" { - return ErrMissingAccountID - } - uri := fmt.Sprintf("/accounts/%s/workers/domains/%s", rc.Identifier, domainID) - _, err := api.makeRequestContext(ctx, http.MethodDelete, uri, nil) - if err != nil { - return fmt.Errorf("%s: %w", errMakeRequestError, err) - } - return nil -} - // WorkersGetDomain gets a Worker Domain. // -// API reference: https://developers.cloudflare.com/api/operations/worker-domain-get-a-domain +// API reference: https://api.cloudflare.com/#worker-domain-get-a-domain func (api *API) WorkersGetDomain(ctx context.Context, rc *ResourceContainer, domainID string) (WorkersDomain, error) { if rc.Identifier == "" { return WorkersDomain{}, ErrMissingAccountID @@ -124,3 +109,18 @@ func (api *API) WorkersGetDomain(ctx context.Context, rc *ResourceContainer, dom } return r.Result, nil } + +// WorkersDetachDomain detaches a worker from a zone and hostname. +// +// API reference: https://api.cloudflare.com/#worker-domain-detach-from-domain +func (api *API) WorkersDetachDomain(ctx context.Context, rc *ResourceContainer, domainID string) error { + if rc.Identifier == "" { + return ErrMissingAccountID + } + uri := fmt.Sprintf("/accounts/%s/workers/domains/%s", rc.Identifier, domainID) + _, err := api.makeRequestContext(ctx, http.MethodDelete, uri, nil) + if err != nil { + return fmt.Errorf("%s: %w", errMakeRequestError, err) + } + return nil +} From 160d6d2392da0a89f5dc4010a5003c13462bab45 Mon Sep 17 00:00:00 2001 From: Jacob White Date: Fri, 18 Nov 2022 22:09:08 -0500 Subject: [PATCH 3/4] Fix goimports --- workers_domain_test.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/workers_domain_test.go b/workers_domain_test.go index f9a82d74d..a737abe2d 100644 --- a/workers_domain_test.go +++ b/workers_domain_test.go @@ -3,9 +3,10 @@ package cloudflare import ( "context" "fmt" - "github.com/stretchr/testify/assert" "net/http" "testing" + + "github.com/stretchr/testify/assert" ) const testWorkerDomainID = "dbe10b4bc17c295377eabd600e1787fd" From c6a103d5595acd956547d67130d7d95f9357a0ef Mon Sep 17 00:00:00 2001 From: Jacob Bednarz Date: Mon, 21 Nov 2022 10:17:12 +1100 Subject: [PATCH 4/4] rename methods to match format --- workers_domain.go | 42 +++++++++++++++++++++++++++++++++--------- workers_domain_test.go | 24 ++++++++++++------------ 2 files changed, 45 insertions(+), 21 deletions(-) diff --git a/workers_domain.go b/workers_domain.go index b70bb7734..975786d1b 100644 --- a/workers_domain.go +++ b/workers_domain.go @@ -14,6 +14,15 @@ var ( ErrMissingEnvironment = errors.New("required environment missing") ) +type AttachWorkersDomainParams struct { + ID string `json:"id,omitempty"` + ZoneID string `json:"zone_id,omitempty"` + ZoneName string `json:"zone_name,omitempty"` + Hostname string `json:"hostname,omitempty"` + Service string `json:"service,omitempty"` + Environment string `json:"environment,omitempty"` +} + type WorkersDomain struct { ID string `json:"id,omitempty"` ZoneID string `json:"zone_id,omitempty"` @@ -28,7 +37,7 @@ type WorkersDomainResponse struct { Result WorkersDomain `json:"result"` } -type WorkersDomainListParams struct { +type ListWorkersDomainParams struct { ZoneID string `url:"zone_id,omitempty"` ZoneName string `url:"zone_name,omitempty"` Hostname string `url:"hostname,omitempty"` @@ -41,86 +50,101 @@ type WorkersDomainListResponse struct { Result []WorkersDomain `json:"result"` } -// WorkersListDomains lists all Worker Domains. +// ListWorkersDomains lists all Worker Domains. // // API reference: https://api.cloudflare.com/#worker-domain-list-domains -func (api *API) WorkersListDomains(ctx context.Context, rc *ResourceContainer, params WorkersDomainListParams) ([]WorkersDomain, error) { +func (api *API) ListWorkersDomains(ctx context.Context, rc *ResourceContainer, params ListWorkersDomainParams) ([]WorkersDomain, error) { if rc.Identifier == "" { return []WorkersDomain{}, ErrMissingAccountID } + uri := buildURI(fmt.Sprintf("/accounts/%s/workers/domains", rc.Identifier), params) res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil) if err != nil { return []WorkersDomain{}, fmt.Errorf("%s: %w", errMakeRequestError, err) } + var r WorkersDomainListResponse if err := json.Unmarshal(res, &r); err != nil { return []WorkersDomain{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } + return r.Result, nil } -// WorkersAttachDomain attaches a worker to a zone and hostname. +// AttachWorkersDomain attaches a worker to a zone and hostname. // // API reference: https://api.cloudflare.com/#worker-domain-attach-to-domain -func (api *API) WorkersAttachDomain(ctx context.Context, rc *ResourceContainer, domain WorkersDomain) (WorkersDomain, error) { +func (api *API) AttachWorkersDomain(ctx context.Context, rc *ResourceContainer, domain AttachWorkersDomainParams) (WorkersDomain, error) { if rc.Identifier == "" { return WorkersDomain{}, ErrMissingAccountID } + if domain.ZoneID == "" { return WorkersDomain{}, ErrMissingZoneID } + if domain.Hostname == "" { return WorkersDomain{}, ErrMissingHostname } + if domain.Service == "" { return WorkersDomain{}, ErrMissingService } + if domain.Environment == "" { return WorkersDomain{}, ErrMissingEnvironment } + uri := fmt.Sprintf("/accounts/%s/workers/domains", rc.Identifier) res, err := api.makeRequestContext(ctx, http.MethodPut, uri, domain) if err != nil { return WorkersDomain{}, fmt.Errorf("%s: %w", errMakeRequestError, err) } + var r WorkersDomainResponse if err := json.Unmarshal(res, &r); err != nil { return WorkersDomain{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } + return r.Result, nil } -// WorkersGetDomain gets a Worker Domain. +// GetWorkersDomain gets a single Worker Domain. // // API reference: https://api.cloudflare.com/#worker-domain-get-a-domain -func (api *API) WorkersGetDomain(ctx context.Context, rc *ResourceContainer, domainID string) (WorkersDomain, error) { +func (api *API) GetWorkersDomain(ctx context.Context, rc *ResourceContainer, domainID string) (WorkersDomain, error) { if rc.Identifier == "" { return WorkersDomain{}, ErrMissingAccountID } + uri := fmt.Sprintf("/accounts/%s/workers/domains/%s", rc.Identifier, domainID) res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil) if err != nil { return WorkersDomain{}, fmt.Errorf("%s: %w", errMakeRequestError, err) } + var r WorkersDomainResponse if err := json.Unmarshal(res, &r); err != nil { return WorkersDomain{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } + return r.Result, nil } -// WorkersDetachDomain detaches a worker from a zone and hostname. +// DetachWorkersDomain detaches a worker from a zone and hostname. // // API reference: https://api.cloudflare.com/#worker-domain-detach-from-domain -func (api *API) WorkersDetachDomain(ctx context.Context, rc *ResourceContainer, domainID string) error { +func (api *API) DetachWorkersDomain(ctx context.Context, rc *ResourceContainer, domainID string) error { if rc.Identifier == "" { return ErrMissingAccountID } + uri := fmt.Sprintf("/accounts/%s/workers/domains/%s", rc.Identifier, domainID) _, err := api.makeRequestContext(ctx, http.MethodDelete, uri, nil) if err != nil { return fmt.Errorf("%s: %w", errMakeRequestError, err) } + return nil } diff --git a/workers_domain_test.go b/workers_domain_test.go index a737abe2d..443929f28 100644 --- a/workers_domain_test.go +++ b/workers_domain_test.go @@ -41,11 +41,11 @@ func TestWorkersDomain_GetDomain(t *testing.T) { } }`) }) - _, err := client.WorkersGetDomain(context.Background(), AccountIdentifier(""), "") + _, err := client.GetWorkersDomain(context.Background(), AccountIdentifier(""), "") if assert.Error(t, err) { assert.Equal(t, ErrMissingAccountID, err) } - res, err := client.WorkersGetDomain(context.Background(), AccountIdentifier(testAccountID), testWorkerDomainID) + res, err := client.GetWorkersDomain(context.Background(), AccountIdentifier(testAccountID), testWorkerDomainID) if assert.NoError(t, err) { assert.Equal(t, expectedWorkerDomain, res) } @@ -74,11 +74,11 @@ func TestWorkersDomain_ListDomains(t *testing.T) { ] }`) }) - _, err := client.WorkersListDomains(context.Background(), AccountIdentifier(""), WorkersDomainListParams{}) + _, err := client.ListWorkersDomains(context.Background(), AccountIdentifier(""), ListWorkersDomainParams{}) if assert.Error(t, err) { assert.Equal(t, ErrMissingAccountID, err) } - res, err := client.WorkersListDomains(context.Background(), AccountIdentifier(testAccountID), WorkersDomainListParams{}) + res, err := client.ListWorkersDomains(context.Background(), AccountIdentifier(testAccountID), ListWorkersDomainParams{}) if assert.NoError(t, err) { assert.Equal(t, 1, len(res)) assert.Equal(t, expectedWorkerDomain, res[0]) @@ -106,24 +106,24 @@ func TestWorkersDomain_AttachDomain(t *testing.T) { } }`) }) - _, err := client.WorkersAttachDomain(context.Background(), AccountIdentifier(""), WorkersDomain{}) + _, err := client.AttachWorkersDomain(context.Background(), AccountIdentifier(""), AttachWorkersDomainParams{}) if assert.Error(t, err) { assert.Equal(t, ErrMissingAccountID, err) } - _, err = client.WorkersAttachDomain(context.Background(), AccountIdentifier(testAccountID), WorkersDomain{}) + _, err = client.AttachWorkersDomain(context.Background(), AccountIdentifier(testAccountID), AttachWorkersDomainParams{}) if assert.Error(t, err) { assert.Equal(t, ErrMissingZoneID, err) } - _, err = client.WorkersAttachDomain(context.Background(), AccountIdentifier(testAccountID), WorkersDomain{ + _, err = client.AttachWorkersDomain(context.Background(), AccountIdentifier(testAccountID), AttachWorkersDomainParams{ ZoneID: testZoneID, }) if assert.Error(t, err) { assert.Equal(t, ErrMissingHostname, err) } - _, err = client.WorkersAttachDomain(context.Background(), AccountIdentifier(testAccountID), WorkersDomain{ + _, err = client.AttachWorkersDomain(context.Background(), AccountIdentifier(testAccountID), AttachWorkersDomainParams{ ZoneID: testZoneID, Hostname: "foo.example.com", }) @@ -131,7 +131,7 @@ func TestWorkersDomain_AttachDomain(t *testing.T) { assert.Equal(t, ErrMissingService, err) } - _, err = client.WorkersAttachDomain(context.Background(), AccountIdentifier(testAccountID), WorkersDomain{ + _, err = client.AttachWorkersDomain(context.Background(), AccountIdentifier(testAccountID), AttachWorkersDomainParams{ ZoneID: testZoneID, Hostname: "foo.example.com", Service: "foo", @@ -140,7 +140,7 @@ func TestWorkersDomain_AttachDomain(t *testing.T) { assert.Equal(t, ErrMissingEnvironment, err) } - res, err := client.WorkersAttachDomain(context.Background(), AccountIdentifier(testAccountID), WorkersDomain{ + res, err := client.AttachWorkersDomain(context.Background(), AccountIdentifier(testAccountID), AttachWorkersDomainParams{ ZoneID: testZoneID, Hostname: "foo.example.com", Service: "foo", @@ -172,10 +172,10 @@ func TestWorkersDomain_DetachDomain(t *testing.T) { } }`) }) - err := client.WorkersDetachDomain(context.Background(), AccountIdentifier(""), testWorkerDomainID) + err := client.DetachWorkersDomain(context.Background(), AccountIdentifier(""), testWorkerDomainID) if assert.Error(t, err) { assert.Equal(t, ErrMissingAccountID, err) } - err = client.WorkersDetachDomain(context.Background(), AccountIdentifier(testAccountID), testWorkerDomainID) + err = client.DetachWorkersDomain(context.Background(), AccountIdentifier(testAccountID), testWorkerDomainID) assert.NoError(t, err) }