-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4427886
commit b03623f
Showing
8 changed files
with
288 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package octopusdeploy | ||
|
||
import ( | ||
"github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/channels" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||
) | ||
|
||
func expandChannelGitResourceRules(ChannelGitResourceRule map[string]interface{}) channels.ChannelGitResourceRule { | ||
if len(ChannelGitResourceRule) == 0 { | ||
return channels.ChannelGitResourceRule{} | ||
} | ||
|
||
return channels.ChannelGitResourceRule{ | ||
Id: ChannelGitResourceRule["id"].(string), | ||
GitDependencyActions: expandDeploymentActionGitDependencies(ChannelGitResourceRule["git_dependency_actions"]), | ||
Rules: ChannelGitResourceRule["rules"].([]string), | ||
} | ||
} | ||
|
||
func flattenChannelGitResourceRules(ChannelGitResourceRules []channels.ChannelGitResourceRule) []map[string]interface{} { | ||
if len(ChannelGitResourceRules) == 0 { | ||
return []map[string]interface{}{} | ||
} | ||
|
||
var flattenedRules = make([]map[string]interface{}, len(ChannelGitResourceRules)) | ||
for key, ChannelGitResourceRule := range ChannelGitResourceRules { | ||
flattenedRules[key] = map[string]interface{}{ | ||
"id": ChannelGitResourceRule.Id, | ||
"git_dependency_actions": flattenDeploymentActionGitDependencies(ChannelGitResourceRule.GitDependencyActions), | ||
"rules": ChannelGitResourceRule.Rules, | ||
} | ||
} | ||
|
||
return flattenedRules | ||
} | ||
|
||
func getChannelGitResourceRuleSchema() map[string]*schema.Schema { | ||
return map[string]*schema.Schema{ | ||
"id": getIDSchema(), | ||
"git_dependency_actions": { | ||
Elem: &schema.Resource{Schema: getDeploymentActionGitDependencySchema()}, | ||
Required: true, | ||
Type: schema.TypeList, | ||
}, | ||
"rules": { | ||
Elem: &schema.Schema{Type: schema.TypeString}, | ||
Optional: true, | ||
Type: schema.TypeList, | ||
}, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package octopusdeploy | ||
|
||
import ( | ||
"github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/gitdependencies" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||
) | ||
|
||
func flattenDeploymentActionGitDependencies(deploymentActionGitDependencies []gitdependencies.DeploymentActionGitDependency) []interface{} { | ||
if len(deploymentActionGitDependencies) == 0 { | ||
return nil | ||
} | ||
|
||
var flattenedDeploymentActionPackages []interface{} | ||
for _, v := range deploymentActionGitDependencies { | ||
flattenedDeploymentActionPackage := map[string]interface{}{ | ||
"deployment_action_slug": v.DeploymentActionSlug, | ||
"git_dependency_name": v.GitDependencyName, | ||
} | ||
flattenedDeploymentActionPackages = append(flattenedDeploymentActionPackages, flattenedDeploymentActionPackage) | ||
} | ||
return flattenedDeploymentActionPackages | ||
} | ||
|
||
func expandDeploymentActionGitDependencies(values interface{}) []gitdependencies.DeploymentActionGitDependency { | ||
if values == nil { | ||
return nil | ||
} | ||
|
||
var gitDependencies []gitdependencies.DeploymentActionGitDependency | ||
for _, v := range values.([]interface{}) { | ||
flattenedMap := v.(map[string]interface{}) | ||
gitDependencies = append(gitDependencies, gitdependencies.DeploymentActionGitDependency{ | ||
DeploymentActionSlug: flattenedMap["deployment_action_slug"].(string), | ||
GitDependencyName: flattenedMap["git_dependency_name"].(string), | ||
}) | ||
} | ||
return gitDependencies | ||
} | ||
|
||
func getDeploymentActionGitDependencySchema() map[string]*schema.Schema { | ||
return map[string]*schema.Schema{ | ||
"deployment_action_slug": { | ||
Optional: true, | ||
Type: schema.TypeString, | ||
}, | ||
"git_dependency_name": { | ||
Optional: true, | ||
Type: schema.TypeString, | ||
}, | ||
} | ||
} |
96 changes: 96 additions & 0 deletions
96
octopusdeploy/schema_deployment_action_git_resource_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
package octopusdeploy | ||
|
||
import ( | ||
"github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/channels" | ||
"github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/gitdependencies" | ||
"reflect" | ||
"testing" | ||
) | ||
|
||
func TestExpandChannelGitResourceRules_WithValidData_ReturnsExpectedResult(t *testing.T) { | ||
input := map[string]interface{}{ | ||
"id": "rule-1", | ||
"git_dependency_actions": []interface{}{ | ||
map[string]interface{}{ | ||
"deployment_action_slug": "deploy-action-1", | ||
"git_dependency_name": "", | ||
}, | ||
}, | ||
"rules": []string{"rule1", "rule2"}, | ||
} | ||
|
||
expected := channels.ChannelGitResourceRule{ | ||
Id: "rule-1", | ||
GitDependencyActions: []gitdependencies.DeploymentActionGitDependency{ | ||
{ | ||
DeploymentActionSlug: "deploy-action-1", | ||
GitDependencyName: "", | ||
}, | ||
}, | ||
Rules: []string{"rule1", "rule2"}, | ||
} | ||
|
||
actual := expandChannelGitResourceRules(input) | ||
|
||
if !reflect.DeepEqual(actual, expected) { | ||
t.Errorf("Expected %+v, got %+v", expected, actual) | ||
} | ||
} | ||
|
||
func TestExpandChannelGitResourceRules_WithEmptyData_ReturnsEmptyStruct(t *testing.T) { | ||
input := map[string]interface{}{} | ||
|
||
expected := channels.ChannelGitResourceRule{} | ||
|
||
actual := expandChannelGitResourceRules(input) | ||
|
||
if !reflect.DeepEqual(actual, expected) { | ||
t.Errorf("Expected %+v, got %+v", expected, actual) | ||
} | ||
} | ||
|
||
func TestFlattenChannelGitResourceRules_WithValidData_ReturnsExpectedMap(t *testing.T) { | ||
input := []channels.ChannelGitResourceRule{ | ||
{ | ||
Id: "rule-1", | ||
GitDependencyActions: []gitdependencies.DeploymentActionGitDependency{ | ||
{ | ||
DeploymentActionSlug: "deploy-action-1", | ||
GitDependencyName: "ref-1", | ||
}, | ||
}, | ||
Rules: []string{"rule1", "rule2"}, | ||
}, | ||
} | ||
|
||
expected := []map[string]interface{}{ | ||
{ | ||
"id": "rule-1", | ||
"git_dependency_actions": []interface{}{ | ||
map[string]interface{}{ | ||
"deployment_action_slug": "deploy-action-1", | ||
"git_dependency_name": "ref-1", | ||
}, | ||
}, | ||
"rules": []string{"rule1", "rule2"}, | ||
}, | ||
} | ||
|
||
actual := flattenChannelGitResourceRules(input) | ||
|
||
if !reflect.DeepEqual(actual, expected) { | ||
t.Errorf("Expected %+v, got %+v", expected, actual) | ||
} | ||
} | ||
|
||
func TestFlattenChannelGitResourceRules_WithEmptyData_ReturnsEmptySlice(t *testing.T) { | ||
input := []channels.ChannelGitResourceRule{} | ||
|
||
expected := []map[string]interface{}{} | ||
|
||
actual := flattenChannelGitResourceRules(input) | ||
|
||
if !reflect.DeepEqual(actual, expected) { | ||
t.Errorf("Expected %+v, got %+v", expected, actual) | ||
} | ||
} |