Skip to content

Commit

Permalink
Merge pull request #388 from hashicorp/brandonc/apply_comment
Browse files Browse the repository at this point in the history
fix: run actions don't accept json-api resource request bodies
  • Loading branch information
brandonc committed May 4, 2022
2 parents c8acf75 + 5b06ba0 commit 4fc5745
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
8 changes: 4 additions & 4 deletions run.go
Expand Up @@ -253,13 +253,13 @@ type RunCreateOptions struct {
// RunApplyOptions represents the options for applying a run.
type RunApplyOptions struct {
// An optional comment about the run.
Comment *string `jsonapi:"attr,comment,omitempty"`
Comment *string `json:"comment,omitempty"`
}

// RunCancelOptions represents the options for canceling a run.
type RunCancelOptions struct {
// An optional explanation for why the run was canceled.
Comment *string `jsonapi:"attr,comment,omitempty"`
Comment *string `json:"comment,omitempty"`
}

// RunVariable represents a variable that can be applied to a run. All values must be expressed as an HCL literal
Expand All @@ -273,13 +273,13 @@ type RunVariable struct {
// RunForceCancelOptions represents the options for force-canceling a run.
type RunForceCancelOptions struct {
// An optional comment explaining the reason for the force-cancel.
Comment *string `jsonapi:"attr,comment,omitempty"`
Comment *string `json:"comment,omitempty"`
}

// RunDiscardOptions represents the options for discarding a run.
type RunDiscardOptions struct {
// An optional explanation for why the run was discarded.
Comment *string `jsonapi:"attr,comment,omitempty"`
Comment *string `json:"comment,omitempty"`
}

// List all the runs of the given workspace.
Expand Down
13 changes: 12 additions & 1 deletion run_integration_test.go
Expand Up @@ -295,8 +295,19 @@ func TestRunsApply(t *testing.T) {
rTest, _ := createPlannedRun(t, client, wTest)

t.Run("when the run exists", func(t *testing.T) {
err := client.Runs.Apply(ctx, rTest.ID, RunApplyOptions{})
err := client.Runs.Apply(ctx, rTest.ID, RunApplyOptions{
Comment: String("Hello, Earl"),
})
assert.NoError(t, err)

r, err := client.Runs.Read(ctx, rTest.ID)
assert.NoError(t, err)

assert.Len(t, r.Comments, 1)

c, err := client.Comments.Read(ctx, r.Comments[0].ID)
assert.NoError(t, err)
assert.Equal(t, "Hello, Earl", c.Body)
})

t.Run("when the run does not exist", func(t *testing.T) {
Expand Down

0 comments on commit 4fc5745

Please sign in to comment.