diff --git a/CHANGELOG.md b/CHANGELOG.md index fc399a313..f6d6241b2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ * Adds `RetryServerErrors` field to the `Config` object by @sebasslash [#439](https://github.com/hashicorp/go-tfe/pull/439) * [beta] Renames the optional StateVersion field `ExtState` to `JSONState` and changes to string for base64 encoding by @annawinkler [#444](https://github.com/hashicorp/go-tfe/pull/444) * Remove beta messaging for Run Tasks by @glennsarti [#447](https://github.com/hashicorp/go-tfe/pull/447) +* Adds `Description` field to the `RunTask` object by @glennsarti [#447](https://github.com/hashicorp/go-tfe/pull/447) # v1.3.0 diff --git a/helper_test.go b/helper_test.go index 08dbe1a02..d1545e0a0 100644 --- a/helper_test.go +++ b/helper_test.go @@ -776,10 +776,12 @@ func createRunTask(t *testing.T, client *Client, org *Organization) (*RunTask, f } ctx := context.Background() + description := randomString(t) r, err := client.RunTasks.Create(ctx, org.Name, RunTaskCreateOptions{ - Name: "tst-" + randomString(t), - URL: runTaskURL, - Category: "task", + Name: "tst-" + randomString(t), + URL: runTaskURL, + Description: &description, + Category: "task", }) if err != nil { t.Fatal(err) diff --git a/run_task.go b/run_task.go index 63e66f7f1..24ddb616f 100644 --- a/run_task.go +++ b/run_task.go @@ -42,12 +42,13 @@ type runTasks struct { // RunTask represents a TFC/E run task type RunTask struct { - ID string `jsonapi:"primary,tasks"` - Name string `jsonapi:"attr,name"` - URL string `jsonapi:"attr,url"` - Category string `jsonapi:"attr,category"` - HMACKey *string `jsonapi:"attr,hmac-key,omitempty"` - Enabled bool `jsonapi:"attr,enabled"` + ID string `jsonapi:"primary,tasks"` + Name string `jsonapi:"attr,name"` + URL string `jsonapi:"attr,url"` + Description string `jsonapi:"attr,description"` + Category string `jsonapi:"attr,category"` + HMACKey *string `jsonapi:"attr,hmac-key,omitempty"` + Enabled bool `jsonapi:"attr,enabled"` Organization *Organization `jsonapi:"relation,organization"` WorkspaceRunTasks []*WorkspaceRunTask `jsonapi:"relation,workspace-tasks"` @@ -97,6 +98,9 @@ type RunTaskCreateOptions struct { // Required: The URL to send a run task payload URL string `jsonapi:"attr,url"` + // Optional: Description of the task + Description *string `jsonapi:"attr,description"` + // Required: Must be "task" Category string `jsonapi:"attr,category"` @@ -121,6 +125,9 @@ type RunTaskUpdateOptions struct { // Optional: The URL to send a run task payload, defaults to previous value URL *string `jsonapi:"attr,url,omitempty"` + // Optional: An optional description of the task + Description *string `jsonapi:"attr,description,omitempty"` + // Optional: Must be "task", defaults to "task" Category *string `jsonapi:"attr,category,omitempty"` diff --git a/run_task_integration_test.go b/run_task_integration_test.go index baf9ab6d8..cdb5fb285 100644 --- a/run_task_integration_test.go +++ b/run_task_integration_test.go @@ -27,13 +27,15 @@ func TestRunTasksCreate(t *testing.T) { } runTaskName := "tst-runtask-" + randomString(t) + runTaskDescription := "A Run Task Description" t.Run("add run task to organization", func(t *testing.T) { r, err := client.RunTasks.Create(ctx, orgTest.Name, RunTaskCreateOptions{ - Name: runTaskName, - URL: runTaskServerURL, - Category: "task", - Enabled: Bool(true), + Name: runTaskName, + URL: runTaskServerURL, + Description: &runTaskDescription, + Category: "task", + Enabled: Bool(true), }) require.NoError(t, err) @@ -41,6 +43,7 @@ func TestRunTasksCreate(t *testing.T) { assert.Equal(t, r.Name, runTaskName) assert.Equal(t, r.URL, runTaskServerURL) assert.Equal(t, r.Category, "task") + assert.Equal(t, r.Description, runTaskDescription) t.Run("ensure org is deserialized properly", func(t *testing.T) { assert.Equal(t, r.Organization.Name, orgTest.Name) @@ -93,6 +96,7 @@ func TestRunTasksRead(t *testing.T) { assert.Equal(t, runTaskTest.ID, r.ID) assert.Equal(t, runTaskTest.URL, r.URL) assert.Equal(t, runTaskTest.Category, r.Category) + assert.Equal(t, runTaskTest.Description, r.Description) assert.Equal(t, runTaskTest.HMACKey, r.HMACKey) assert.Equal(t, runTaskTest.Enabled, r.Enabled) }) @@ -148,6 +152,32 @@ func TestRunTasksUpdate(t *testing.T) { assert.Equal(t, rename, r.Name) }) + + t.Run("toggle enabled", func(t *testing.T) { + runTaskTest.Enabled = !runTaskTest.Enabled + r, err := client.RunTasks.Update(ctx, runTaskTest.ID, RunTaskUpdateOptions{ + Enabled: &runTaskTest.Enabled, + }) + require.NoError(t, err) + + r, err = client.RunTasks.Read(ctx, r.ID) + require.NoError(t, err) + + assert.Equal(t, runTaskTest.Enabled, r.Enabled) + }) + + t.Run("update description", func(t *testing.T) { + newDescription := "An updated task description" + r, err := client.RunTasks.Update(ctx, runTaskTest.ID, RunTaskUpdateOptions{ + Description: &newDescription, + }) + require.NoError(t, err) + + r, err = client.RunTasks.Read(ctx, r.ID) + require.NoError(t, err) + + assert.Equal(t, newDescription, r.Description) + }) } func TestRunTasksDelete(t *testing.T) {