Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## Enhancements

* Adds `Logs` method to `QueryRuns`, which is EXPERIMENTAL, SUBJECT TO CHANGE, and may not be available to all users by @brandonc [#1186](https://github.com/hashicorp/go-tfe/pull/1186)
* Adds `CanceledAt`, `RunEvents`, `TriggerReason` field to `Run` by @jpadrianoGo [#1161](https://github.com/hashicorp/go-tfe/pull/1161)
* Adds `CreatedAt` field to `AgentPool` by @jpadrianoGo [#1150](https://github.com/hashicorp/go-tfe/pull/1150)
* Adds `CreatedBy` relation to `AgentToken` by @jpadrianoGo [#1149](https://github.com/hashicorp/go-tfe/pull/1149)

Expand Down
3 changes: 3 additions & 0 deletions run.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ type Run struct {
AutoApply bool `jsonapi:"attr,auto-apply,omitempty"`
AllowConfigGeneration *bool `jsonapi:"attr,allow-config-generation,omitempty"`
AllowEmptyApply bool `jsonapi:"attr,allow-empty-apply"`
CanceledAt time.Time `jsonapi:"attr,canceled-at,iso8601"`
CreatedAt time.Time `jsonapi:"attr,created-at,iso8601"`
ForceCancelAvailableAt time.Time `jsonapi:"attr,force-cancel-available-at,iso8601"`
HasChanges bool `jsonapi:"attr,has-changes"`
Expand All @@ -153,6 +154,7 @@ type Run struct {
StatusTimestamps *RunStatusTimestamps `jsonapi:"attr,status-timestamps"`
TargetAddrs []string `jsonapi:"attr,target-addrs,omitempty"`
TerraformVersion string `jsonapi:"attr,terraform-version"`
TriggerReason string `jsonapi:"attr,trigger-reason"`
Variables []*RunVariableAttr `jsonapi:"attr,variables"`

// Relations
Expand All @@ -163,6 +165,7 @@ type Run struct {
ConfirmedBy *User `jsonapi:"relation,confirmed-by"`
Plan *Plan `jsonapi:"relation,plan"`
PolicyChecks []*PolicyCheck `jsonapi:"relation,policy-checks"`
RunEvents []*RunEvent `jsonapi:"relation,run-events"`
TaskStages []*TaskStage `jsonapi:"relation,task-stages,omitempty"`
Workspace *Workspace `jsonapi:"relation,workspace"`
Comments []*Comment `jsonapi:"relation,comments"`
Expand Down
90 changes: 90 additions & 0 deletions run_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -473,6 +473,96 @@ func TestRunsConfirmedBy(t *testing.T) {
})
}

func TestRunsCanceledAt(t *testing.T) {
client := testClient(t)

ctx := context.Background()

wTest, wTestCleanup := createWorkspace(t, client, nil)
t.Cleanup(wTestCleanup)

// We need to create 2 runs here. The first run will automatically
// be planned so that one cannot be cancelled. The second one will
// be pending until the first one is confirmed or discarded, so we
// can cancel that one.
createRun(t, client, wTest)
rTest, _ := createRun(t, client, wTest)

t.Run("when the run is not canceled", func(t *testing.T) {
r, err := client.Runs.Read(ctx, rTest.ID)
require.NoError(t, err)

assert.Empty(t, r.CanceledAt)
})

t.Run("when the run is canceled", func(t *testing.T) {
err := client.Runs.Cancel(ctx, rTest.ID, RunCancelOptions{})
require.NoError(t, err)

for i := 1; ; i++ {
// Refresh the view of the run
rTest, err = client.Runs.Read(ctx, rTest.ID)
require.NoError(t, err)

// Check if the timestamp is present.
if !rTest.ForceCancelAvailableAt.IsZero() {
break
}

if i > 30 {
t.Fatal("Timeout waiting for run to be canceled")
}

time.Sleep(time.Second)
}

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

assert.NotEmpty(t, r.CanceledAt)
})
}

func TestRunsRunEvents(t *testing.T) {
client := testClient(t)
ctx := context.Background()

wTest, wTestCleanup := createWorkspace(t, client, nil)
defer wTestCleanup()

_, cvCleanup := createUploadedConfigurationVersion(t, client, wTest)
t.Cleanup(cvCleanup)

options := RunCreateOptions{
Workspace: wTest,
}

r, err := client.Runs.Create(ctx, options)
require.NoError(t, err)

assert.NotEmpty(t, r.RunEvents)
}

func TestRunsTriggerReason(t *testing.T) {
client := testClient(t)
ctx := context.Background()

wTest, wTestCleanup := createWorkspace(t, client, nil)
defer wTestCleanup()

_, cvCleanup := createUploadedConfigurationVersion(t, client, wTest)
t.Cleanup(cvCleanup)

options := RunCreateOptions{
Workspace: wTest,
}

r, err := client.Runs.Create(ctx, options)
require.NoError(t, err)

assert.NotNil(t, r.TriggerReason)
}

func TestRunsApply(t *testing.T) {
client := testClient(t)
ctx := context.Background()
Expand Down
Loading