Skip to content

Commit

Permalink
Fix diagnostic messages on update environment
Browse files Browse the repository at this point in the history
  • Loading branch information
seanyeh committed Dec 12, 2024
1 parent 0a8fc41 commit 0136bbb
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 3 deletions.
4 changes: 2 additions & 2 deletions CHANGELOG_PENDING.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
### Improvements

- Add `--definition` flag to `esc env get` to output definition
[#416](https://github.com/pulumi/esc/pull/416)
- Fix diagnostic messages when updating environment with invalid definition
[#422](https://github.com/pulumi/esc/pull/422)

### Bug Fixes

Expand Down
2 changes: 1 addition & 1 deletion cmd/esc/cli/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -560,7 +560,7 @@ func (pc *client) UpdateEnvironmentWithRevision(
})
if err != nil {
var diags *EnvironmentErrorResponse
if errors.As(err, &diags) && diags.Code == http.StatusBadRequest && len(diags.Diagnostics) != 0 {
if errors.As(err, &diags) && len(diags.Diagnostics) != 0 {
return diags.Diagnostics, 0, nil
}
return nil, 0, err
Expand Down
33 changes: 33 additions & 0 deletions cmd/esc/cli/client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,39 @@ func TestUpdateEnvironment(t *testing.T) {
assert.Equal(t, expected, diags)
})

t.Run("Diags only", func(t *testing.T) {
expected := []EnvironmentDiagnostic{
{
Range: &esc.Range{
Environment: "test-env",
Begin: esc.Pos{Line: 42, Column: 1},
End: esc.Pos{Line: 42, Column: 42},
},
Summary: "diag 1",
},
{
Range: &esc.Range{
Environment: "import-env",
Begin: esc.Pos{Line: 1, Column: 2},
End: esc.Pos{Line: 3, Column: 4},
},
Summary: "diag 2",
},
}

client := newTestClient(t, http.MethodPatch, "/api/esc/environments/test-org/test-project/test-env", func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusBadRequest)

err := json.NewEncoder(w).Encode(EnvironmentErrorResponse{Diagnostics: expected})
require.NoError(t, err)
})

diags, revision, err := client.UpdateEnvironmentWithRevision(context.Background(), "test-org", "test-project", "test-env", nil, "")
require.Equal(t, 0, revision)
require.NoError(t, err)
assert.Equal(t, expected, diags)
})

t.Run("Conflict", func(t *testing.T) {
client := newTestClient(t, http.MethodPatch, "/api/esc/environments/test-org/test-project/test-env", func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusConflict)
Expand Down

0 comments on commit 0136bbb

Please sign in to comment.