Skip to content

Commit

Permalink
fix: secret set status code check (#355)
Browse files Browse the repository at this point in the history
  • Loading branch information
sweatybridge authored Aug 11, 2022
1 parent e927845 commit 4da2ed0
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
3 changes: 2 additions & 1 deletion internal/secrets/set/set.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ func Run(ctx context.Context, envFilePath string, args []string, fsys afero.Fs)
return err
}

if resp.StatusCode() != http.StatusOK {
// TODO: remove the StatusOK case after 2022-08-20
if resp.StatusCode() != http.StatusCreated && resp.StatusCode() != http.StatusOK {
return errors.New("Unexpected error setting project secrets: " + string(resp.Body))
}
}
Expand Down
4 changes: 4 additions & 0 deletions internal/secrets/set/set_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ func TestSecretSetCommand(t *testing.T) {
Reply(200)
// Run test
assert.NoError(t, Run(context.Background(), "", []string{dummyEnv}, fsys))
assert.False(t, gock.HasUnmatchedRequest())
})

t.Run("Sets secret value via env file", func(t *testing.T) {
Expand Down Expand Up @@ -69,6 +70,7 @@ func TestSecretSetCommand(t *testing.T) {
Reply(200)
// Run test
assert.NoError(t, Run(context.Background(), tmpfile.Name(), []string{}, fsys))
assert.False(t, gock.HasUnmatchedRequest())
})

t.Run("throws error on missing config file", func(t *testing.T) {
Expand Down Expand Up @@ -148,6 +150,7 @@ func TestSecretSetCommand(t *testing.T) {
ReplyError(errors.New("network error"))
// Run test
assert.Error(t, Run(context.Background(), "", []string{dummyEnv}, fsys))
assert.False(t, gock.HasUnmatchedRequest())
})

t.Run("throws error on server unavailable", func(t *testing.T) {
Expand All @@ -172,5 +175,6 @@ func TestSecretSetCommand(t *testing.T) {
JSON(map[string]string{"message": "unavailable"})
// Run test
assert.Error(t, Run(context.Background(), "", []string{dummyEnv}, fsys))
assert.False(t, gock.HasUnmatchedRequest())
})
}

0 comments on commit 4da2ed0

Please sign in to comment.