diff --git a/fastly/dictionary.go b/fastly/dictionary.go index b7f4c7fe6..81faf3cd1 100644 --- a/fastly/dictionary.go +++ b/fastly/dictionary.go @@ -3,7 +3,6 @@ package fastly import ( "fmt" "net/url" - "sort" "time" ) @@ -11,30 +10,12 @@ import ( type Dictionary struct { CreatedAt *time.Time `mapstructure:"created_at"` DeletedAt *time.Time `mapstructure:"deleted_at"` - ID string `mapstructure:"id"` - Name string `mapstructure:"name"` - ServiceID string `mapstructure:"service_id"` - ServiceVersion int `mapstructure:"version"` + ID *string `mapstructure:"id"` + Name *string `mapstructure:"name"` + ServiceID *string `mapstructure:"service_id"` + ServiceVersion *int `mapstructure:"version"` UpdatedAt *time.Time `mapstructure:"updated_at"` - WriteOnly bool `mapstructure:"write_only"` -} - -// dictionariesByName is a sortable list of dictionaries. -type dictionariesByName []*Dictionary - -// Len implement the sortable interface. -func (s dictionariesByName) Len() int { - return len(s) -} - -// Swap implement the sortable interface. -func (s dictionariesByName) Swap(i, j int) { - s[i], s[j] = s[j], s[i] -} - -// Less implement the sortable interface. -func (s dictionariesByName) Less(i, j int) bool { - return s[i].Name < s[j].Name + WriteOnly *bool `mapstructure:"write_only"` } // ListDictionariesInput is used as input to the ListDictionaries function. @@ -65,7 +46,6 @@ func (c *Client) ListDictionaries(i *ListDictionariesInput) ([]*Dictionary, erro if err := decodeBodyMap(resp.Body, &bs); err != nil { return nil, err } - sort.Stable(dictionariesByName(bs)) return bs, nil } diff --git a/fastly/dictionary_info.go b/fastly/dictionary_info.go index 3fbcaa6b7..2d7adc367 100644 --- a/fastly/dictionary_info.go +++ b/fastly/dictionary_info.go @@ -8,16 +8,16 @@ import ( // DictionaryInfo represents a dictionary metadata response from the Fastly API. type DictionaryInfo struct { // Digest is the hash of the dictionary content. - Digest string `mapstructure:"digest"` + Digest *string `mapstructure:"digest"` // ItemCount is the number of items belonging to the dictionary. - ItemCount int `mapstructure:"item_count"` + ItemCount *int `mapstructure:"item_count"` // LastUpdated is the Time-stamp (GMT) when the dictionary was last updated. LastUpdated *time.Time `mapstructure:"last_updated"` } // GetDictionaryInfoInput is used as input to the GetDictionary function. type GetDictionaryInfoInput struct { - // ID is the alphanumeric string identifying a dictionary. + // ID is the alphanumeric string identifying a dictionary (required). ID string // ServiceID is the ID of the service Dictionary belongs to (required). ServiceID string @@ -27,18 +27,16 @@ type GetDictionaryInfoInput struct { // GetDictionaryInfo retrieves the specified resource. func (c *Client) GetDictionaryInfo(i *GetDictionaryInfoInput) (*DictionaryInfo, error) { + if i.ID == "" { + return nil, ErrMissingID + } if i.ServiceID == "" { return nil, ErrMissingServiceID } - if i.ServiceVersion == 0 { return nil, ErrMissingServiceVersion } - if i.ID == "" { - return nil, ErrMissingID - } - path := fmt.Sprintf("/service/%s/version/%d/dictionary/%s/info", i.ServiceID, i.ServiceVersion, i.ID) resp, err := c.Get(path, nil) if err != nil { diff --git a/fastly/dictionary_info_test.go b/fastly/dictionary_info_test.go index 149155714..362b9b48b 100644 --- a/fastly/dictionary_info_test.go +++ b/fastly/dictionary_info_test.go @@ -24,17 +24,17 @@ func TestClient_GetDictionaryInfo(t *testing.T) { record(t, fixtureBase+"create_dictionary_items", func(c *Client) { err = c.BatchModifyDictionaryItems(&BatchModifyDictionaryItemsInput{ ServiceID: testService.ID, - DictionaryID: testDictionary.ID, + DictionaryID: *testDictionary.ID, Items: []*BatchDictionaryItem{ { - Operation: CreateBatchOperation, - ItemKey: "test-dictionary-item-0", - ItemValue: "value", + Operation: ToPointer(CreateBatchOperation), + ItemKey: ToPointer("test-dictionary-item-0"), + ItemValue: ToPointer("value"), }, { - Operation: CreateBatchOperation, - ItemKey: "test-dictionary-item-1", - ItemValue: "value", + Operation: ToPointer(CreateBatchOperation), + ItemKey: ToPointer("test-dictionary-item-1"), + ItemValue: ToPointer("value"), }, }, }) @@ -47,41 +47,38 @@ func TestClient_GetDictionaryInfo(t *testing.T) { info, err = c.GetDictionaryInfo(&GetDictionaryInfoInput{ ServiceID: testService.ID, ServiceVersion: testVersion.Number, - ID: testDictionary.ID, + ID: *testDictionary.ID, }) }) if err != nil { t.Fatal(err) } - if info.ItemCount != 2 { - t.Errorf("bad item_count: %d", info.ItemCount) + if *info.ItemCount != 2 { + t.Errorf("bad item_count: %d", *info.ItemCount) } } func TestClient_GetDictionaryInfo_validation(t *testing.T) { var err error - _, err = testClient.GetDictionaryInfo(&GetDictionaryInfoInput{ - ServiceID: "", - }) - if err != ErrMissingServiceID { + _, err = testClient.GetDictionaryInfo(&GetDictionaryInfoInput{}) + if err != ErrMissingID { t.Errorf("bad error: %s", err) } _, err = testClient.GetDictionaryInfo(&GetDictionaryInfoInput{ - ServiceID: "foo", - ServiceVersion: 0, + ID: "123", }) - if err != ErrMissingServiceVersion { + if err != ErrMissingServiceID { t.Errorf("bad error: %s", err) } _, err = testClient.GetDictionaryInfo(&GetDictionaryInfoInput{ + ID: "123", ServiceID: "foo", - ServiceVersion: 1, - ID: "", + ServiceVersion: 0, }) - if err != ErrMissingID { + if err != ErrMissingServiceVersion { t.Errorf("bad error: %s", err) } } diff --git a/fastly/dictionary_item.go b/fastly/dictionary_item.go index e756f6c7e..8d7515a93 100644 --- a/fastly/dictionary_item.go +++ b/fastly/dictionary_item.go @@ -12,10 +12,10 @@ const dictionaryItemsPath = "/service/%s/dictionary/%s/items" type DictionaryItem struct { CreatedAt *time.Time `mapstructure:"created_at"` DeletedAt *time.Time `mapstructure:"deleted_at"` - DictionaryID string `mapstructure:"dictionary_id"` - ItemKey string `mapstructure:"item_key"` - ItemValue string `mapstructure:"item_value"` - ServiceID string `mapstructure:"service_id"` + DictionaryID *string `mapstructure:"dictionary_id"` + ItemKey *string `mapstructure:"item_key"` + ItemValue *string `mapstructure:"item_value"` + ServiceID *string `mapstructure:"service_id"` UpdatedAt *time.Time `mapstructure:"updated_at"` } @@ -24,25 +24,34 @@ type GetDictionaryItemsInput struct { // DictionaryID is the ID of the dictionary to retrieve items for (required). DictionaryID string // Direction is the direction in which to sort results. - Direction string + Direction *string // Page is the current page. - Page int + Page *int // PerPage is the number of records per page. - PerPage int + PerPage *int // ServiceID is the ID of the service (required). ServiceID string // Sort is the field on which to sort. - Sort string + Sort *string } // GetDictionaryItems returns a ListPaginator for paginating through the resources. func (c *Client) GetDictionaryItems(i *GetDictionaryItemsInput) *ListPaginator[DictionaryItem] { - return newPaginator[DictionaryItem](c, &listInput{ - Direction: i.Direction, - Sort: i.Sort, - Page: i.Page, - PerPage: i.PerPage, - }, fmt.Sprintf(dictionaryItemsPath, i.ServiceID, i.DictionaryID)) + input := &listInput{} + if i.Direction != nil { + input.Direction = *i.Direction + } + if i.Sort != nil { + input.Sort = *i.Sort + } + if i.Page != nil { + input.Page = *i.Page + } + if i.PerPage != nil { + input.PerPage = *i.PerPage + } + path := fmt.Sprintf(dictionaryItemsPath, i.ServiceID, i.DictionaryID) + return newPaginator[DictionaryItem](c, input, path) } // ListDictionaryItemsInput is used as input to the ListDictionaryItems function. @@ -50,11 +59,11 @@ type ListDictionaryItemsInput struct { // DictionaryID is the ID of the dictionary to retrieve items for (required). DictionaryID string // Direction is the direction in which to sort results. - Direction string + Direction *string // ServiceID is the ID of the service (required). ServiceID string // Sort is the field on which to sort. - Sort string + Sort *string } // ListDictionaryItems retrieves all resources. Not suitable for large @@ -86,9 +95,9 @@ func (c *Client) ListDictionaryItems(i *ListDictionaryItemsInput) ([]*Dictionary // CreateDictionaryItemInput is used as input to the CreateDictionaryItem function. type CreateDictionaryItemInput struct { // ItemKey is the dictionary item key, maximum 256 characters. - ItemKey string `url:"item_key,omitempty"` + ItemKey *string `url:"item_key,omitempty"` // ItemValue is the dictionary item value, maximum 8000 characters. - ItemValue string `url:"item_value,omitempty"` + ItemValue *string `url:"item_value,omitempty"` // ServiceID is the ID of the service (required). ServiceID string `url:"-"` // DictionaryID is the ID of the dictionary to retrieve items for (required). @@ -220,11 +229,11 @@ type BatchModifyDictionaryItemsInput struct { // BatchDictionaryItem represents a dictionary item. type BatchDictionaryItem struct { // ItemKey is an item key (maximum 256 characters). - ItemKey string `json:"item_key"` + ItemKey *string `json:"item_key"` // ItemValue is an item value (maximum 8000 characters). - ItemValue string `json:"item_value"` + ItemValue *string `json:"item_value"` // Operation is a batching operation variant. - Operation BatchOperation `json:"op"` + Operation *BatchOperation `json:"op"` } // BatchModifyDictionaryItems bulk updates dictionary items. diff --git a/fastly/dictionary_item_batch_test.go b/fastly/dictionary_item_batch_test.go index 751d17c6d..407271462 100644 --- a/fastly/dictionary_item_batch_test.go +++ b/fastly/dictionary_item_batch_test.go @@ -19,17 +19,17 @@ func TestClient_BatchModifyDictionaryItems_Create(t *testing.T) { batchCreateOperations := &BatchModifyDictionaryItemsInput{ ServiceID: testService.ID, - DictionaryID: testDictionary.ID, + DictionaryID: *testDictionary.ID, Items: []*BatchDictionaryItem{ { - Operation: CreateBatchOperation, - ItemKey: "key1", - ItemValue: "val1", + Operation: ToPointer(CreateBatchOperation), + ItemKey: ToPointer("key1"), + ItemValue: ToPointer("val1"), }, { - Operation: CreateBatchOperation, - ItemKey: "key2", - ItemValue: "val2", + Operation: ToPointer(CreateBatchOperation), + ItemKey: ToPointer("key2"), + ItemValue: ToPointer("val2"), }, }, } @@ -48,7 +48,7 @@ func TestClient_BatchModifyDictionaryItems_Create(t *testing.T) { record(t, fixtureBase+"list_after_create", func(c *Client) { actualDictionaryItems, err = c.ListDictionaryItems(&ListDictionaryItemsInput{ ServiceID: testService.ID, - DictionaryID: testDictionary.ID, + DictionaryID: *testDictionary.ID, }) }) if err != nil { @@ -64,14 +64,14 @@ func TestClient_BatchModifyDictionaryItems_Create(t *testing.T) { for i, item := range actualDictionaryItems { actualItemKey := item.ItemKey expectedItemKey := batchCreateOperations.Items[i].ItemKey - if actualItemKey != expectedItemKey { - t.Errorf("First ItemKey did not match, expected %s, got %s", expectedItemKey, actualItemKey) + if *actualItemKey != *expectedItemKey { + t.Errorf("First ItemKey did not match, expected %s, got %s", *expectedItemKey, *actualItemKey) } actualItemValue := item.ItemValue expectedItemValue := batchCreateOperations.Items[i].ItemValue - if actualItemValue != expectedItemValue { - t.Errorf("First ItemValue did not match, expected %s, got %s", expectedItemValue, actualItemValue) + if *actualItemValue != *expectedItemValue { + t.Errorf("First ItemValue did not match, expected %s, got %s", *expectedItemValue, *actualItemValue) } } } @@ -91,17 +91,17 @@ func TestClient_BatchModifyDictionaryItems_Delete(t *testing.T) { batchCreateOperations := &BatchModifyDictionaryItemsInput{ ServiceID: testService.ID, - DictionaryID: testDictionary.ID, + DictionaryID: *testDictionary.ID, Items: []*BatchDictionaryItem{ { - Operation: CreateBatchOperation, - ItemKey: "key1", - ItemValue: "val1", + Operation: ToPointer(CreateBatchOperation), + ItemKey: ToPointer("key1"), + ItemValue: ToPointer("val1"), }, { - Operation: CreateBatchOperation, - ItemKey: "key2", - ItemValue: "val2", + Operation: ToPointer(CreateBatchOperation), + ItemKey: ToPointer("key2"), + ItemValue: ToPointer("val2"), }, }, } @@ -117,12 +117,12 @@ func TestClient_BatchModifyDictionaryItems_Delete(t *testing.T) { // When: I execute the batch delete operations against the Fastly API, batchDeleteOperations := &BatchModifyDictionaryItemsInput{ ServiceID: testService.ID, - DictionaryID: testDictionary.ID, + DictionaryID: *testDictionary.ID, Items: []*BatchDictionaryItem{ { - Operation: DeleteBatchOperation, - ItemKey: "key2", - ItemValue: "val2", + Operation: ToPointer(DeleteBatchOperation), + ItemKey: ToPointer("key2"), + ItemValue: ToPointer("val2"), }, }, } @@ -139,7 +139,7 @@ func TestClient_BatchModifyDictionaryItems_Delete(t *testing.T) { record(t, fixtureBase+"list_after_delete", func(client *Client) { actualDictionaryItems, err = client.ListDictionaryItems(&ListDictionaryItemsInput{ ServiceID: testService.ID, - DictionaryID: testDictionary.ID, + DictionaryID: *testDictionary.ID, }) }) if err != nil { @@ -168,17 +168,17 @@ func TestClient_BatchModifyDictionaryItems_Update(t *testing.T) { batchCreateOperations := &BatchModifyDictionaryItemsInput{ ServiceID: testService.ID, - DictionaryID: testDictionary.ID, + DictionaryID: *testDictionary.ID, Items: []*BatchDictionaryItem{ { - Operation: CreateBatchOperation, - ItemKey: "key1", - ItemValue: "val1", + Operation: ToPointer(CreateBatchOperation), + ItemKey: ToPointer("key1"), + ItemValue: ToPointer("val1"), }, { - Operation: CreateBatchOperation, - ItemKey: "key2", - ItemValue: "val2", + Operation: ToPointer(CreateBatchOperation), + ItemKey: ToPointer("key2"), + ItemValue: ToPointer("val2"), }, }, } @@ -194,12 +194,12 @@ func TestClient_BatchModifyDictionaryItems_Update(t *testing.T) { // When: I execute the batch update operations against the Fastly API, batchUpdateOperations := &BatchModifyDictionaryItemsInput{ ServiceID: testService.ID, - DictionaryID: testDictionary.ID, + DictionaryID: *testDictionary.ID, Items: []*BatchDictionaryItem{ { - Operation: UpdateBatchOperation, - ItemKey: "key2", - ItemValue: "val2Updated", + Operation: ToPointer(UpdateBatchOperation), + ItemKey: ToPointer("key2"), + ItemValue: ToPointer("val2Updated"), }, }, } @@ -216,7 +216,7 @@ func TestClient_BatchModifyDictionaryItems_Update(t *testing.T) { record(t, fixtureBase+"list_after_update", func(c *Client) { actualDictionaryItems, err = c.ListDictionaryItems(&ListDictionaryItemsInput{ ServiceID: testService.ID, - DictionaryID: testDictionary.ID, + DictionaryID: *testDictionary.ID, }) }) if err != nil { @@ -232,30 +232,30 @@ func TestClient_BatchModifyDictionaryItems_Update(t *testing.T) { actualItemKey := actualDictionaryItems[0].ItemKey expectedItemKey := batchCreateOperations.Items[0].ItemKey - if actualItemKey != expectedItemKey { - t.Errorf("First ItemKey did not match, expected %s, got %s", expectedItemKey, actualItemKey) + if *actualItemKey != *expectedItemKey { + t.Errorf("First ItemKey did not match, expected %s, got %s", *expectedItemKey, *actualItemKey) } actualItemValue := actualDictionaryItems[0].ItemValue expectedItemValue := batchCreateOperations.Items[0].ItemValue // Confirm the second dictionary item contains the modifications. - if actualItemValue != expectedItemValue { - t.Errorf("First ItemValue did not match, expected %s, got %s", expectedItemValue, actualItemValue) + if *actualItemValue != *expectedItemValue { + t.Errorf("First ItemValue did not match, expected %s, got %s", *expectedItemValue, *actualItemValue) } actualItemKey = actualDictionaryItems[1].ItemKey expectedItemKey = batchUpdateOperations.Items[0].ItemKey - if actualItemKey != expectedItemKey { - t.Errorf("Second ItemKey did not match, expected %s, got %s", expectedItemKey, actualItemKey) + if *actualItemKey != *expectedItemKey { + t.Errorf("Second ItemKey did not match, expected %s, got %s", *expectedItemKey, *actualItemKey) } actualItemValue = actualDictionaryItems[1].ItemValue expectedItemValue = batchUpdateOperations.Items[0].ItemValue - if actualItemValue != expectedItemValue { - t.Errorf("Second ItemValue did not match, expected %s, got %s", expectedItemValue, actualItemValue) + if *actualItemValue != *expectedItemValue { + t.Errorf("Second ItemValue did not match, expected %s, got %s", *expectedItemValue, *actualItemValue) } } @@ -274,12 +274,12 @@ func TestClient_BatchModifyDictionaryItems_Upsert(t *testing.T) { batchCreateOperations := &BatchModifyDictionaryItemsInput{ ServiceID: testService.ID, - DictionaryID: testDictionary.ID, + DictionaryID: *testDictionary.ID, Items: []*BatchDictionaryItem{ { - Operation: CreateBatchOperation, - ItemKey: "key1", - ItemValue: "val1", + Operation: ToPointer(CreateBatchOperation), + ItemKey: ToPointer("key1"), + ItemValue: ToPointer("val1"), }, }, } @@ -295,17 +295,17 @@ func TestClient_BatchModifyDictionaryItems_Upsert(t *testing.T) { // When: I execute the batch upsert operations against the Fastly API batchUpsertOperations := &BatchModifyDictionaryItemsInput{ ServiceID: testService.ID, - DictionaryID: testDictionary.ID, + DictionaryID: *testDictionary.ID, Items: []*BatchDictionaryItem{ { - Operation: UpsertBatchOperation, - ItemKey: "key1", - ItemValue: "val1Updated", + Operation: ToPointer(UpsertBatchOperation), + ItemKey: ToPointer("key1"), + ItemValue: ToPointer("val1Updated"), }, { - Operation: UpsertBatchOperation, - ItemKey: "key2", - ItemValue: "val2", + Operation: ToPointer(UpsertBatchOperation), + ItemKey: ToPointer("key2"), + ItemValue: ToPointer("val2"), }, }, } @@ -322,7 +322,7 @@ func TestClient_BatchModifyDictionaryItems_Upsert(t *testing.T) { record(t, fixtureBase+"list_after_upsert", func(c *Client) { actualDictionaryItems, err = c.ListDictionaryItems(&ListDictionaryItemsInput{ ServiceID: testService.ID, - DictionaryID: testDictionary.ID, + DictionaryID: *testDictionary.ID, }) }) if err != nil { @@ -338,14 +338,14 @@ func TestClient_BatchModifyDictionaryItems_Upsert(t *testing.T) { for i, item := range actualDictionaryItems { actualItemKey := item.ItemKey expectedItemKey := batchUpsertOperations.Items[i].ItemKey - if actualItemKey != expectedItemKey { - t.Errorf("First ItemKey did not match, expected %s, got %s", expectedItemKey, actualItemKey) + if *actualItemKey != *expectedItemKey { + t.Errorf("First ItemKey did not match, expected %s, got %s", *expectedItemKey, *actualItemKey) } actualItemValue := item.ItemValue expectedItemValue := batchUpsertOperations.Items[i].ItemValue - if actualItemValue != expectedItemValue { - t.Errorf("First ItemValue did not match, expected %s, got %s", expectedItemValue, actualItemValue) + if *actualItemValue != *expectedItemValue { + t.Errorf("First ItemValue did not match, expected %s, got %s", *expectedItemValue, *actualItemValue) } } } diff --git a/fastly/dictionary_item_test.go b/fastly/dictionary_item_test.go index 27b8c22d1..8d1384045 100644 --- a/fastly/dictionary_item_test.go +++ b/fastly/dictionary_item_test.go @@ -22,9 +22,9 @@ func TestClient_DictionaryItems(t *testing.T) { record(t, fixtureBase+"create", func(c *Client) { createdDictionaryItem, err = c.CreateDictionaryItem(&CreateDictionaryItemInput{ ServiceID: testService.ID, - DictionaryID: testDictionary.ID, - ItemKey: "test-dictionary-item", - ItemValue: "value", + DictionaryID: *testDictionary.ID, + ItemKey: ToPointer("test-dictionary-item"), + ItemValue: ToPointer("value"), }) }) if err != nil { @@ -36,17 +36,17 @@ func TestClient_DictionaryItems(t *testing.T) { record(t, fixtureBase+"cleanup", func(c *Client) { _ = c.DeleteDictionaryItem(&DeleteDictionaryItemInput{ ServiceID: testService.ID, - DictionaryID: testDictionary.ID, + DictionaryID: *testDictionary.ID, ItemKey: "test-dictionary-item", }) }) }() - if createdDictionaryItem.ItemKey != "test-dictionary-item" { - t.Errorf("bad item_key: %q", createdDictionaryItem.ItemKey) + if *createdDictionaryItem.ItemKey != "test-dictionary-item" { + t.Errorf("bad item_key: %q", *createdDictionaryItem.ItemKey) } - if createdDictionaryItem.ItemValue != "value" { - t.Errorf("bad item_value: %q", createdDictionaryItem.ItemValue) + if *createdDictionaryItem.ItemValue != "value" { + t.Errorf("bad item_value: %q", *createdDictionaryItem.ItemValue) } // List @@ -54,7 +54,7 @@ func TestClient_DictionaryItems(t *testing.T) { record(t, fixtureBase+"list", func(c *Client) { dictionaryItems, err = c.ListDictionaryItems(&ListDictionaryItemsInput{ ServiceID: testService.ID, - DictionaryID: testDictionary.ID, + DictionaryID: *testDictionary.ID, }) }) if err != nil { @@ -69,11 +69,11 @@ func TestClient_DictionaryItems(t *testing.T) { var paginator *ListPaginator[DictionaryItem] record(t, fixtureBase+"list2", func(c *Client) { paginator = c.GetDictionaryItems(&GetDictionaryItemsInput{ - DictionaryID: testDictionary.ID, - Direction: "ascend", - PerPage: 50, + DictionaryID: *testDictionary.ID, + Direction: ToPointer("ascend"), + PerPage: ToPointer(50), ServiceID: testService.ID, - Sort: "item_key", + Sort: ToPointer("item_key"), }) for paginator.HasNext() { @@ -100,18 +100,18 @@ func TestClient_DictionaryItems(t *testing.T) { record(t, fixtureBase+"get", func(c *Client) { retrievedDictionaryItem, err = c.GetDictionaryItem(&GetDictionaryItemInput{ ServiceID: testService.ID, - DictionaryID: testDictionary.ID, + DictionaryID: *testDictionary.ID, ItemKey: "test-dictionary-item", }) }) if err != nil { t.Fatal(err) } - if retrievedDictionaryItem.ItemKey != "test-dictionary-item" { - t.Errorf("bad item_key: %q", retrievedDictionaryItem.ItemKey) + if *retrievedDictionaryItem.ItemKey != "test-dictionary-item" { + t.Errorf("bad item_key: %q", *retrievedDictionaryItem.ItemKey) } - if retrievedDictionaryItem.ItemValue != "value" { - t.Errorf("bad item_value: %q", retrievedDictionaryItem.ItemValue) + if *retrievedDictionaryItem.ItemValue != "value" { + t.Errorf("bad item_value: %q", *retrievedDictionaryItem.ItemValue) } // Update @@ -119,7 +119,7 @@ func TestClient_DictionaryItems(t *testing.T) { record(t, fixtureBase+"update", func(c *Client) { updatedDictionaryItem, err = c.UpdateDictionaryItem(&UpdateDictionaryItemInput{ ServiceID: testService.ID, - DictionaryID: testDictionary.ID, + DictionaryID: *testDictionary.ID, ItemKey: "test-dictionary-item", ItemValue: "new-value", }) @@ -127,15 +127,15 @@ func TestClient_DictionaryItems(t *testing.T) { if err != nil { t.Fatal(err) } - if updatedDictionaryItem.ItemValue != "new-value" { - t.Errorf("bad item_value: %q", updatedDictionaryItem.ItemValue) + if *updatedDictionaryItem.ItemValue != "new-value" { + t.Errorf("bad item_value: %q", *updatedDictionaryItem.ItemValue) } // Delete record(t, fixtureBase+"delete", func(c *Client) { err = c.DeleteDictionaryItem(&DeleteDictionaryItemInput{ ServiceID: testService.ID, - DictionaryID: testDictionary.ID, + DictionaryID: *testDictionary.ID, ItemKey: "test-dictionary-item", }) }) diff --git a/fastly/dictionary_test.go b/fastly/dictionary_test.go index 434360609..61451b930 100644 --- a/fastly/dictionary_test.go +++ b/fastly/dictionary_test.go @@ -42,8 +42,8 @@ func TestClient_Dictionaries(t *testing.T) { }) }() - if d.Name != "test_dictionary" { - t.Errorf("bad name: %q", d.Name) + if *d.Name != "test_dictionary" { + t.Errorf("bad name: %q", *d.Name) } // List @@ -73,8 +73,8 @@ func TestClient_Dictionaries(t *testing.T) { if err != nil { t.Fatal(err) } - if d.Name != nd.Name { - t.Errorf("bad name: %q (%q)", d.Name, nd.Name) + if *d.Name != *nd.Name { + t.Errorf("bad name: %q (%q)", *d.Name, *nd.Name) } // Update @@ -90,8 +90,8 @@ func TestClient_Dictionaries(t *testing.T) { if err != nil { t.Fatal(err) } - if ud.Name != "new_test_dictionary" { - t.Errorf("bad name: %q", ud.Name) + if *ud.Name != "new_test_dictionary" { + t.Errorf("bad name: %q", *ud.Name) } // Delete diff --git a/fastly/example_remaining_test.go b/fastly/example_remaining_test.go index 6df0643ed..960234b10 100644 --- a/fastly/example_remaining_test.go +++ b/fastly/example_remaining_test.go @@ -33,9 +33,9 @@ func ExampleClient_RateLimitRemaining() { _, err = c.CreateDictionaryItem(&fastly.CreateDictionaryItemInput{ ServiceID: sid, - DictionaryID: dict.ID, - ItemKey: "test-dictionary-item", - ItemValue: "value", + DictionaryID: *dict.ID, + ItemKey: fastly.ToPointer("test-dictionary-item"), + ItemValue: fastly.ToPointer("value"), }) if err != nil { log.Fatal(err) @@ -46,7 +46,7 @@ func ExampleClient_RateLimitRemaining() { for i := 1; i < 10; i++ { _, err := c.UpdateDictionaryItem(&fastly.UpdateDictionaryItemInput{ ServiceID: sid, - DictionaryID: dict.ID, + DictionaryID: *dict.ID, ItemKey: "test-dictionary-item", ItemValue: fmt.Sprintf("value%d", i), }) diff --git a/fastly/fastly_test.go b/fastly/fastly_test.go index 750a66f97..264a2e08a 100644 --- a/fastly/fastly_test.go +++ b/fastly/fastly_test.go @@ -210,9 +210,9 @@ func deleteTestDictionary(t *testing.T, dictionary *Dictionary, deleteFixture st record(t, deleteFixture, func(client *Client) { err = client.DeleteDictionary(&DeleteDictionaryInput{ - ServiceID: dictionary.ServiceID, - ServiceVersion: dictionary.ServiceVersion, - Name: dictionary.Name, + ServiceID: *dictionary.ServiceID, + ServiceVersion: *dictionary.ServiceVersion, + Name: *dictionary.Name, }) }) if err != nil {