Skip to content

Commit

Permalink
Merged automatically by CI pipeline
Browse files Browse the repository at this point in the history
SCALRCORE-22742 Provider > Add AutoForceRun field to workspace
  • Loading branch information
emocharnik committed Oct 13, 2022
2 parents b4e48eb + 1ad6025 commit e931af8
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
7 changes: 7 additions & 0 deletions workspace.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ type Workspace struct {
ID string `jsonapi:"primary,workspaces"`
Actions *WorkspaceActions `jsonapi:"attr,actions"`
AutoApply bool `jsonapi:"attr,auto-apply"`
ForceLatestRun bool `jsonapi:"attr,force-latest-run"`
CanQueueDestroyPlan bool `jsonapi:"attr,can-queue-destroy-plan"`
CreatedAt time.Time `jsonapi:"attr,created-at,iso8601"`
FileTriggersEnabled bool `jsonapi:"attr,file-triggers-enabled"`
Expand Down Expand Up @@ -168,6 +169,9 @@ type WorkspaceCreateOptions struct {
// Whether to automatically apply changes when a Terraform plan is successful.
AutoApply *bool `jsonapi:"attr,auto-apply,omitempty"`

// Whether to automatically raise the priority of the latest new run.
ForceLatestRun *bool `jsonapi:"attr,force-latest-run,omitempty"`

// The name of the workspace, which can only include letters, numbers, -,
// and _. This will be used as an identifier and must be unique in the
// environment.
Expand Down Expand Up @@ -333,6 +337,9 @@ type WorkspaceUpdateOptions struct {
// Whether to automatically apply changes when a Terraform plan is successful.
AutoApply *bool `jsonapi:"attr,auto-apply,omitempty"`

// Whether to automatically raise the priority of the latest new run.
ForceLatestRun *bool `jsonapi:"attr,force-latest-run,omitempty"`

// A new name for the workspace, which can only include letters, numbers, -,
// and _. This will be used as an identifier and must be unique in the
// environment. Warning: Changing a workspace's name changes its URL in the
Expand Down
10 changes: 10 additions & 0 deletions workspace_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ func TestWorkspacesCreate(t *testing.T) {
Environment: envTest,
Name: String(randomString(t)),
AutoApply: Bool(true),
ForceLatestRun: Bool(true),
ExecutionMode: WorkspaceExecutionModePtr(WorkspaceExecutionModeRemote),
TerraformVersion: String("0.12.25"),
WorkingDirectory: String("bar/"),
Expand All @@ -93,6 +94,7 @@ func TestWorkspacesCreate(t *testing.T) {
assert.NotEmpty(t, item.ID)
assert.Equal(t, *options.Name, item.Name)
assert.Equal(t, *options.AutoApply, item.AutoApply)
assert.Equal(t, *options.ForceLatestRun, item.ForceLatestRun)
assert.Equal(t, false, item.HasResources)
assert.Equal(t, *options.ExecutionMode, item.ExecutionMode)
assert.Equal(t, *options.TerraformVersion, item.TerraformVersion)
Expand Down Expand Up @@ -269,6 +271,7 @@ func TestWorkspacesUpdate(t *testing.T) {
options := WorkspaceUpdateOptions{
Name: String(wsTest.Name),
AutoApply: Bool(true),
ForceLatestRun: Bool(true),
ExecutionMode: WorkspaceExecutionModePtr(WorkspaceExecutionModeRemote),
TerraformVersion: String("0.12.25"),
RunOperationTimeout: Int(20),
Expand All @@ -282,6 +285,7 @@ func TestWorkspacesUpdate(t *testing.T) {
assert.Equal(t, true, wsTest.AutoQueueRuns == nil)
assert.Equal(t, false, *wsAfter.AutoQueueRuns)
assert.NotEqual(t, wsTest.AutoApply, wsAfter.AutoApply)
assert.NotEqual(t, wsTest.ForceLatestRun, wsAfter.ForceLatestRun)
assert.NotEqual(t, wsTest.TerraformVersion, wsAfter.TerraformVersion)
assert.Equal(t, wsTest.WorkingDirectory, wsAfter.WorkingDirectory)
assert.Equal(t, int(20), *wsAfter.RunOperationTimeout)
Expand Down Expand Up @@ -312,6 +316,7 @@ func TestWorkspacesUpdate(t *testing.T) {
options := WorkspaceUpdateOptions{
Name: String(randomString(t)),
AutoApply: Bool(false),
ForceLatestRun: Bool(false),
ExecutionMode: WorkspaceExecutionModePtr(WorkspaceExecutionModeLocal),
TerraformVersion: String("0.12.25"),
WorkingDirectory: String("baz/"),
Expand All @@ -330,6 +335,7 @@ func TestWorkspacesUpdate(t *testing.T) {
} {
assert.Equal(t, *options.Name, item.Name)
assert.Equal(t, *options.AutoApply, item.AutoApply)
assert.Equal(t, *options.ForceLatestRun, item.ForceLatestRun)
assert.Equal(t, *options.ExecutionMode, item.ExecutionMode)
assert.Equal(t, *options.TerraformVersion, item.TerraformVersion)
assert.Equal(t, *options.WorkingDirectory, item.WorkingDirectory)
Expand Down Expand Up @@ -365,6 +371,7 @@ func TestWorkspacesUpdateByID(t *testing.T) {
options := WorkspaceUpdateOptions{
Name: String(wTest.Name),
AutoApply: Bool(true),
ForceLatestRun: Bool(true),
ExecutionMode: WorkspaceExecutionModePtr(WorkspaceExecutionModeRemote),
TerraformVersion: String("0.12.25"),
}
Expand All @@ -374,6 +381,7 @@ func TestWorkspacesUpdateByID(t *testing.T) {

assert.Equal(t, wTest.Name, wAfter.Name)
assert.NotEqual(t, wTest.AutoApply, wAfter.AutoApply)
assert.NotEqual(t, wTest.ForceLatestRun, wAfter.ForceLatestRun)
assert.NotEqual(t, wTest.TerraformVersion, wAfter.TerraformVersion)
assert.Equal(t, wTest.WorkingDirectory, wAfter.WorkingDirectory)
})
Expand All @@ -382,6 +390,7 @@ func TestWorkspacesUpdateByID(t *testing.T) {
options := WorkspaceUpdateOptions{
Name: String(randomString(t)),
AutoApply: Bool(false),
ForceLatestRun: Bool(false),
ExecutionMode: WorkspaceExecutionModePtr(WorkspaceExecutionModeLocal),
TerraformVersion: String("0.12.25"),
WorkingDirectory: String("baz/"),
Expand All @@ -400,6 +409,7 @@ func TestWorkspacesUpdateByID(t *testing.T) {
} {
assert.Equal(t, *options.Name, item.Name)
assert.Equal(t, *options.AutoApply, item.AutoApply)
assert.Equal(t, *options.ForceLatestRun, item.ForceLatestRun)
assert.Equal(t, *options.ExecutionMode, item.ExecutionMode)
assert.Equal(t, *options.TerraformVersion, item.TerraformVersion)
assert.Equal(t, *options.WorkingDirectory, item.WorkingDirectory)
Expand Down

0 comments on commit e931af8

Please sign in to comment.