Skip to content

Commit

Permalink
Add Run Task Description
Browse files Browse the repository at this point in the history
Run Tasks now have an optional description field. This commit updates
the RunTask API endpoints to include the description where applicable
(Create/Read/Update).
  • Loading branch information
glennsarti committed Jun 29, 2022
1 parent f6deba7 commit 9f904b8
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 13 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -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

Expand Down
8 changes: 5 additions & 3 deletions helper_test.go
Expand Up @@ -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)
Expand Down
19 changes: 13 additions & 6 deletions run_task.go
Expand Up @@ -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"`
Expand Down Expand Up @@ -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"`

Expand All @@ -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"`

Expand Down
38 changes: 34 additions & 4 deletions run_task_integration_test.go
Expand Up @@ -27,20 +27,23 @@ 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)

assert.NotEmpty(t, r.ID)
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)
Expand Down Expand Up @@ -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)
})
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 9f904b8

Please sign in to comment.