Skip to content

Commit

Permalink
add test coverage for mutually exclusive options
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobbednarz committed Jul 18, 2023
1 parent 4165acc commit 5a38e52
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
4 changes: 4 additions & 0 deletions images.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,10 @@ func (api *API) UploadImage(ctx context.Context, rc *ResourceContainer, params U
return Image{}, ErrRequiredAccountLevelResourceContainer
}

if params.File != nil && params.URL != "" {
return Image{}, errors.New("file and url uploads are mutually exclusive and can only be performed individually")
}

uri := fmt.Sprintf("/accounts/%s/images/v1", rc.Identifier)

body := &bytes.Buffer{}
Expand Down
14 changes: 14 additions & 0 deletions images_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,20 @@ func TestCreateImageDirectUploadURL(t *testing.T) {
}
}

func TestCreateImageConflictingTypes(t *testing.T) {
setup()
defer teardown()

_, err := client.UploadImage(context.Background(), AccountIdentifier(testAccountID), UploadImageParams{
URL: "https://example.com/foo.jpg",
File: fakeFile{
Buffer: bytes.NewBufferString("this is definitely an image"),
},
})

assert.Error(t, err)
}

func TestCreateImageDirectUploadURLV2(t *testing.T) {
setup()
defer teardown()
Expand Down

0 comments on commit 5a38e52

Please sign in to comment.