Skip to content

Commit 2ec54a8

Browse files
committed
Add Run Task Description
Run Tasks now have an optional description field. This commit updates the RunTask API endpoints to include the description where applicable (Create/Read/Update).
1 parent 8d15748 commit 2ec54a8

4 files changed

+53
-13
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
* Adds `RetryServerErrors` field to the `Config` object by @sebasslash [#439](https://github.com/hashicorp/go-tfe/pull/439)
55
* [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)
66
* Remove beta messaging for Run Tasks by @glennsarti [#447](https://github.com/hashicorp/go-tfe/pull/447)
7+
* Adds `Description` field to the `RunTask` object by @glennsarti [#447](https://github.com/hashicorp/go-tfe/pull/447)
78

89
# v1.3.0
910

helper_test.go

+5-3
Original file line numberDiff line numberDiff line change
@@ -776,10 +776,12 @@ func createRunTask(t *testing.T, client *Client, org *Organization) (*RunTask, f
776776
}
777777

778778
ctx := context.Background()
779+
description := randomString(t)
779780
r, err := client.RunTasks.Create(ctx, org.Name, RunTaskCreateOptions{
780-
Name: "tst-" + randomString(t),
781-
URL: runTaskURL,
782-
Category: "task",
781+
Name: "tst-" + randomString(t),
782+
URL: runTaskURL,
783+
Description: &description,
784+
Category: "task",
783785
})
784786
if err != nil {
785787
t.Fatal(err)

run_task.go

+13-6
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,13 @@ type runTasks struct {
4242

4343
// RunTask represents a TFC/E run task
4444
type RunTask struct {
45-
ID string `jsonapi:"primary,tasks"`
46-
Name string `jsonapi:"attr,name"`
47-
URL string `jsonapi:"attr,url"`
48-
Category string `jsonapi:"attr,category"`
49-
HMACKey *string `jsonapi:"attr,hmac-key,omitempty"`
50-
Enabled bool `jsonapi:"attr,enabled"`
45+
ID string `jsonapi:"primary,tasks"`
46+
Name string `jsonapi:"attr,name"`
47+
URL string `jsonapi:"attr,url"`
48+
Description string `jsonapi:"attr,description"`
49+
Category string `jsonapi:"attr,category"`
50+
HMACKey *string `jsonapi:"attr,hmac-key,omitempty"`
51+
Enabled bool `jsonapi:"attr,enabled"`
5152

5253
Organization *Organization `jsonapi:"relation,organization"`
5354
WorkspaceRunTasks []*WorkspaceRunTask `jsonapi:"relation,workspace-tasks"`
@@ -97,6 +98,9 @@ type RunTaskCreateOptions struct {
9798
// Required: The URL to send a run task payload
9899
URL string `jsonapi:"attr,url"`
99100

101+
// Optional: Description of the task
102+
Description *string `jsonapi:"attr,description"`
103+
100104
// Required: Must be "task"
101105
Category string `jsonapi:"attr,category"`
102106

@@ -121,6 +125,9 @@ type RunTaskUpdateOptions struct {
121125
// Optional: The URL to send a run task payload, defaults to previous value
122126
URL *string `jsonapi:"attr,url,omitempty"`
123127

128+
// Optional: An optional description of the task
129+
Description *string `jsonapi:"attr,description,omitempty"`
130+
124131
// Optional: Must be "task", defaults to "task"
125132
Category *string `jsonapi:"attr,category,omitempty"`
126133

run_task_integration_test.go

+34-4
Original file line numberDiff line numberDiff line change
@@ -27,20 +27,23 @@ func TestRunTasksCreate(t *testing.T) {
2727
}
2828

2929
runTaskName := "tst-runtask-" + randomString(t)
30+
runTaskDescription := "A Run Task Description"
3031

3132
t.Run("add run task to organization", func(t *testing.T) {
3233
r, err := client.RunTasks.Create(ctx, orgTest.Name, RunTaskCreateOptions{
33-
Name: runTaskName,
34-
URL: runTaskServerURL,
35-
Category: "task",
36-
Enabled: Bool(true),
34+
Name: runTaskName,
35+
URL: runTaskServerURL,
36+
Description: &runTaskDescription,
37+
Category: "task",
38+
Enabled: Bool(true),
3739
})
3840
require.NoError(t, err)
3941

4042
assert.NotEmpty(t, r.ID)
4143
assert.Equal(t, r.Name, runTaskName)
4244
assert.Equal(t, r.URL, runTaskServerURL)
4345
assert.Equal(t, r.Category, "task")
46+
assert.Equal(t, r.Description, runTaskDescription)
4447

4548
t.Run("ensure org is deserialized properly", func(t *testing.T) {
4649
assert.Equal(t, r.Organization.Name, orgTest.Name)
@@ -93,6 +96,7 @@ func TestRunTasksRead(t *testing.T) {
9396
assert.Equal(t, runTaskTest.ID, r.ID)
9497
assert.Equal(t, runTaskTest.URL, r.URL)
9598
assert.Equal(t, runTaskTest.Category, r.Category)
99+
assert.Equal(t, runTaskTest.Description, r.Description)
96100
assert.Equal(t, runTaskTest.HMACKey, r.HMACKey)
97101
assert.Equal(t, runTaskTest.Enabled, r.Enabled)
98102
})
@@ -148,6 +152,32 @@ func TestRunTasksUpdate(t *testing.T) {
148152

149153
assert.Equal(t, rename, r.Name)
150154
})
155+
156+
t.Run("toggle enabled", func(t *testing.T) {
157+
runTaskTest.Enabled = !runTaskTest.Enabled
158+
r, err := client.RunTasks.Update(ctx, runTaskTest.ID, RunTaskUpdateOptions{
159+
Enabled: &runTaskTest.Enabled,
160+
})
161+
require.NoError(t, err)
162+
163+
r, err = client.RunTasks.Read(ctx, r.ID)
164+
require.NoError(t, err)
165+
166+
assert.Equal(t, runTaskTest.Enabled, r.Enabled)
167+
})
168+
169+
t.Run("update description", func(t *testing.T) {
170+
newDescription := "An updated task description"
171+
r, err := client.RunTasks.Update(ctx, runTaskTest.ID, RunTaskUpdateOptions{
172+
Description: &newDescription,
173+
})
174+
require.NoError(t, err)
175+
176+
r, err = client.RunTasks.Read(ctx, r.ID)
177+
require.NoError(t, err)
178+
179+
assert.Equal(t, newDescription, r.Description)
180+
})
151181
}
152182

153183
func TestRunTasksDelete(t *testing.T) {

0 commit comments

Comments
 (0)