Skip to content

Commit

Permalink
Make arguments to APIKey-related methods consistent by accepting valu…
Browse files Browse the repository at this point in the history
…es as arguments everywhere
  • Loading branch information
Slavek Kabrda committed Apr 16, 2019
1 parent 6de206f commit a711b27
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
6 changes: 3 additions & 3 deletions api_keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,12 @@ func (client *Client) GetAPIKey(key string) (*APIKey, error) {
}

// CreateAPIKey creates an API key from given struct and fills the rest of its
// fileds, or returns an error on failure
func (client *Client) CreateAPIKey(name *string) (*APIKey, error) {
// fields, or returns an error on failure
func (client *Client) CreateAPIKey(name string) (*APIKey, error) {
toPost := struct {
Name *string `json:"name,omitempty"`
}{
name,
&name,
}
var out reqAPIKey
if err := client.doJsonRequest("POST", "/v1/api_key", toPost, &out); err != nil {
Expand Down
20 changes: 10 additions & 10 deletions integration/api_keys_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (

func TestAPIKeyCreateGetAndDelete(t *testing.T) {
keyName := "client-test-key"
expected, err := client.CreateAPIKey(datadog.String(keyName))
expected, err := client.CreateAPIKey(keyName)
if err != nil {
t.Fatalf("Creating API key failed when it shouldn't. (%s)", err)
}
Expand All @@ -34,28 +34,28 @@ func TestAPIKeyCreateGetAndDelete(t *testing.T) {
}

func TestAPIKeyUpdateName(t *testing.T) {
keyName := datadog.String("client-test-key")
newKeyName := datadog.String("client-test-key-new")
keyName := "client-test-key"
newKeyName := "client-test-key-new"
keyStruct, err := client.CreateAPIKey(keyName)
if err != nil {
t.Fatalf("Creating API key failed when it shouldn't. (%s)", err)
}
defer cleanUpAPIKey(t, *keyStruct.Key)

keyStruct.Name = newKeyName
*keyStruct.Name = newKeyName
err = client.UpdateAPIKey(keyStruct)
if err != nil {
t.Fatalf("Updating API key failed when it shouldn't. (%s)", err)
}

if keyStruct.Name != newKeyName {
t.Errorf("API key name not updated. Got %s, want %s", *keyStruct.Name, *newKeyName)
if *keyStruct.Name != newKeyName {
t.Errorf("API key name not updated. Got %s, want %s", *keyStruct.Name, newKeyName)
}
}

func TestAPIKeyGetMultipleKeys(t *testing.T) {
key1Name := datadog.String("client-test-1")
key2Name := datadog.String("client-test-2")
key1Name := "client-test-1"
key2Name := "client-test-2"
key1, err := client.CreateAPIKey(key1Name)
if err != nil {
t.Fatalf("Creating API key failed when it shouldn't. (%s)", err)
Expand All @@ -73,10 +73,10 @@ func TestAPIKeyGetMultipleKeys(t *testing.T) {
key1Found, key2Found := false, false
for _, key := range allKeys {
switch *key.Name {
case *key1Name:
case key1Name:
assertAPIKeyEquals(t, &key, key1)
key1Found = true
case *key2Name:
case key2Name:
assertAPIKeyEquals(t, &key, key2)
key2Found = true
}
Expand Down

0 comments on commit a711b27

Please sign in to comment.