Skip to content

Commit

Permalink
Updated seralisation and testing for deployment action containers
Browse files Browse the repository at this point in the history
  • Loading branch information
jbristowe committed Feb 3, 2021
1 parent f2e97c2 commit d7fde5a
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 3 deletions.
17 changes: 14 additions & 3 deletions octopusdeploy/schema_deployment_action_container.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,28 @@ import (
)

func expandDeploymentActionContainer(values interface{}) octopusdeploy.DeploymentActionContainer {
if values == nil {
return octopusdeploy.DeploymentActionContainer{}
}

flattenedValues := values.([]interface{})
if len(flattenedValues) == 0 || flattenedValues[0] == nil {
return octopusdeploy.DeploymentActionContainer{}
}

flattenedMap := flattenedValues[0].(map[string]interface{})

return octopusdeploy.DeploymentActionContainer{
FeedID: flattenedMap["feed_id"].(string),
Image: flattenedMap["image"].(string),
deploymentActionContainer := octopusdeploy.DeploymentActionContainer{}

if feedID := flattenedMap["feed_id"]; feedID != nil {
deploymentActionContainer.FeedID = feedID.(string)
}

if image := flattenedMap["image"]; image != nil {
deploymentActionContainer.Image = image.(string)
}

return deploymentActionContainer
}

func flattenDeploymentActionContainer(deploymentActionContainer octopusdeploy.DeploymentActionContainer) []interface{} {
Expand Down
42 changes: 42 additions & 0 deletions octopusdeploy/schema_deployment_action_container_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package octopusdeploy

import (
"testing"

"github.com/OctopusDeploy/go-octopusdeploy/octopusdeploy"
"github.com/stretchr/testify/require"
)

func TestExpandDeploymentActionContainer(t *testing.T) {
expected := octopusdeploy.DeploymentActionContainer{}
actual := expandDeploymentActionContainer(nil)
require.Equal(t, expected, actual)

var emptyInterface interface{}
actual = expandDeploymentActionContainer(emptyInterface)
require.Equal(t, expected, actual)

var emptyInterfaceArray []interface{}
actual = expandDeploymentActionContainer(emptyInterfaceArray)
require.Equal(t, expected, actual)

var testMap []interface{} = make([]interface{}, 1)
actual = expandDeploymentActionContainer(testMap)
require.Equal(t, expected, actual)

testMap[0] = make(map[string]interface{}, 1)
actual = expandDeploymentActionContainer(testMap)
require.Equal(t, expected, actual)

testMap[0] = map[string]interface{}{
"feed_id": "feeds-123",
"image": "image-123",
}
expected = octopusdeploy.DeploymentActionContainer{
FeedID: "feeds-123",
Image: "image-123",
}
actual = expandDeploymentActionContainer(testMap)

require.Equal(t, expected, actual)
}

0 comments on commit d7fde5a

Please sign in to comment.