Skip to content

Commit

Permalink
Fix - fix support in any cnange deploy (#191)
Browse files Browse the repository at this point in the history
* Fix - fix support in any cnange deploy
  • Loading branch information
GiliFaroEnv0 authored Dec 20, 2021
1 parent 250229f commit a7ead19
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 16 deletions.
12 changes: 4 additions & 8 deletions env0/resource_environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func resourceEnvironment() *schema.Resource {
Type: schema.TypeBool,
Description: "redeploy only on path changes only",
Optional: true,
Default: false,
Default: true,
},
"auto_deploy_by_custom_glob": {
Type: schema.TypeString,
Expand Down Expand Up @@ -400,13 +400,9 @@ func getUpdatePayload(d *schema.ResourceData) client.EnvironmentUpdate {
pullRequestPlanDeployments := d.Get("run_plan_on_pull_requests").(bool)
payload.PullRequestPlanDeployments = &pullRequestPlanDeployments
}
if d.HasChange("auto_deploy_on_path_changes_only") {
autoDeployOnPathChangesOnly := d.Get("auto_deploy_on_path_changes_only").(bool)
payload.AutoDeployOnPathChangesOnly = &autoDeployOnPathChangesOnly
}
if d.HasChange("auto_deploy_by_custom_glob") {
payload.AutoDeployByCustomGlob = d.Get("auto_deploy_by_custom_glob").(string)
}
autoDeployOnPathChangesOnly := d.Get("auto_deploy_on_path_changes_only").(bool)
payload.AutoDeployOnPathChangesOnly = &autoDeployOnPathChangesOnly
payload.AutoDeployByCustomGlob = d.Get("auto_deploy_by_custom_glob").(string)

return payload
}
Expand Down
20 changes: 12 additions & 8 deletions env0/resource_environment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func TestUnitEnvironmentResource(t *testing.T) {
"force_destroy": true,
})
}
autoDeployOnPathChangesOnlyDefault := false
autoDeployOnPathChangesOnlyDefault := true
autoDeployByCustomGlobDefault := ""
t.Run("Success in create", func(t *testing.T) {
testCase := resource.TestCase{
Expand Down Expand Up @@ -80,7 +80,9 @@ func TestUnitEnvironmentResource(t *testing.T) {
},
}).Times(1).Return(environment, nil)
mock.EXPECT().EnvironmentUpdate(updatedEnvironment.Id, client.EnvironmentUpdate{
Name: updatedEnvironment.Name,
Name: updatedEnvironment.Name,
AutoDeployOnPathChangesOnly: &autoDeployOnPathChangesOnlyDefault,
AutoDeployByCustomGlob: autoDeployByCustomGlobDefault,
}).Times(1).Return(updatedEnvironment, nil)
mock.EXPECT().ConfigurationVariables(client.ScopeEnvironment, updatedEnvironment.Id).Times(3).Return(client.ConfigurationChanges{}, nil)
gomock.InOrder(
Expand Down Expand Up @@ -537,10 +539,10 @@ func TestUnitEnvironmentResource(t *testing.T) {
},

ContinuousDeployment: &falsey,
AutoDeployOnPathChangesOnly: &falsey,
AutoDeployOnPathChangesOnly: &autoDeployOnPathChangesOnlyDefault,
RequiresApproval: &truthyFruity,
PullRequestPlanDeployments: &falsey,
AutoDeployByCustomGlob: "",
AutoDeployByCustomGlob: autoDeployByCustomGlobDefault,
}

testCase := resource.TestCase{
Expand Down Expand Up @@ -581,7 +583,7 @@ func TestUnitEnvironmentResource(t *testing.T) {
resource.TestCheckResourceAttr(accessor, "template_id", environment.LatestDeploymentLog.BlueprintId),
resource.TestCheckResourceAttr(accessor, "approve_plan_automatically", "false"),
resource.TestCheckResourceAttr(accessor, "run_plan_on_pull_requests", "false"),
resource.TestCheckResourceAttr(accessor, "auto_deploy_on_path_changes_only", "false"),
resource.TestCheckResourceAttr(accessor, "auto_deploy_on_path_changes_only", "true"),
resource.TestCheckResourceAttr(accessor, "auto_deploy_by_custom_glob", ""),
),
},
Expand All @@ -594,10 +596,10 @@ func TestUnitEnvironmentResource(t *testing.T) {
Name: environment.Name,

ContinuousDeployment: &falsey,
AutoDeployOnPathChangesOnly: &falsey,
AutoDeployOnPathChangesOnly: &autoDeployOnPathChangesOnlyDefault,
RequiresApproval: &truthyFruity,
PullRequestPlanDeployments: &falsey,
AutoDeployByCustomGlob: "",
AutoDeployByCustomGlob: autoDeployByCustomGlobDefault,
}).Times(1).Return(environmentAfterUpdate, nil)

gomock.InOrder(
Expand Down Expand Up @@ -713,7 +715,9 @@ func TestUnitEnvironmentResource(t *testing.T) {
}).Times(1).Return(environment, nil)
mock.EXPECT().ConfigurationVariables(client.ScopeEnvironment, environment.Id).Times(2).Return(client.ConfigurationChanges{}, nil)
mock.EXPECT().EnvironmentUpdate(updatedEnvironment.Id, client.EnvironmentUpdate{
Name: updatedEnvironment.Name,
Name: updatedEnvironment.Name,
AutoDeployOnPathChangesOnly: &autoDeployOnPathChangesOnlyDefault,
AutoDeployByCustomGlob: autoDeployByCustomGlobDefault,
}).Times(1).Return(client.Environment{}, errors.New("error"))
mock.EXPECT().Environment(gomock.Any()).Times(2).Return(environment, nil) // 1 after create, 1 before update
mock.EXPECT().EnvironmentDestroy(environment.Id).Times(1)
Expand Down

0 comments on commit a7ead19

Please sign in to comment.