diff --git a/collector/cfutils_test.go b/collector/cfutils_test.go index 8784edb57..b20847a6d 100644 --- a/collector/cfutils_test.go +++ b/collector/cfutils_test.go @@ -19,14 +19,57 @@ package collector_test import ( "testing" - collector "github.com/konveyor/move2kube/collector" - + "github.com/cloudfoundry-community/go-cfclient/v2" "github.com/konveyor/move2kube/types" + "github.com/stretchr/testify/assert" + + collector "github.com/konveyor/move2kube/collector" ) func TestNewCfApps(t *testing.T) { cfapps := collector.NewCfApps() - if cfapps.Kind != string(collector.CfAppsMetadataKind) || cfapps.APIVersion != types.SchemeGroupVersion.String() { - t.Fatal("Failed to initialize CfApps properly.") + assert.Equal(t, string(collector.CfAppsMetadataKind), cfapps.Kind, "Failed to initialize CfApps kind properly.") + assert.Equal(t, types.SchemeGroupVersion.String(), cfapps.APIVersion, "Failed to initialize CfApps APIVersion properly.") +} + +func TestFormatMapsWithInterface(t *testing.T) { + app := collector.CfApp{ + Application: collector.App{ + DockerCredentialsJSON: map[string]interface{}{"key1": "value1"}, + Environment: map[string]interface{}{"env1": "value1"}, + }, + Environment: cfclient.AppEnv{ + Environment: map[string]interface{}{"env2": "value2"}, + ApplicationEnv: map[string]interface{}{"appenv1": "value1"}, + RunningEnv: map[string]interface{}{"runenv1": "value1"}, + StagingEnv: map[string]interface{}{"stageenv1": "value1"}, + SystemEnv: map[string]interface{}{"sysenv1": "value1"}, + }, + } + cfApps := collector.CfApps{ + Spec: collector.CfAppsSpec{ + CfApps: []collector.CfApp{app}, + }, + } + + cfApps = collector.FormatMapsWithInterface(cfApps) + expectedApp := collector.CfApp{ + Application: collector.App{ + DockerCredentialsJSON: map[string]interface{}{"key1": "value1"}, + Environment: map[string]interface{}{"env1": "value1"}, + }, + Environment: cfclient.AppEnv{ + Environment: map[string]interface{}{"env2": "value2"}, + ApplicationEnv: map[string]interface{}{"appenv1": "value1"}, + RunningEnv: map[string]interface{}{"runenv1": "value1"}, + StagingEnv: map[string]interface{}{"stageenv1": "value1"}, + SystemEnv: map[string]interface{}{"sysenv1": "value1"}, + }, + } + expectedCfApps := collector.CfApps{ + Spec: collector.CfAppsSpec{ + CfApps: []collector.CfApp{expectedApp}, + }, } + assert.Equal(t, expectedCfApps, cfApps, "Failed to format maps with interface correctly.") } diff --git a/go.mod b/go.mod index f37c73f87..710be594f 100644 --- a/go.mod +++ b/go.mod @@ -39,6 +39,7 @@ require ( github.com/spf13/cast v1.5.0 github.com/spf13/cobra v1.7.0 github.com/spf13/viper v1.10.1 + github.com/stretchr/testify v1.8.4 github.com/tektoncd/pipeline v0.31.1-0.20220112162203-fcca72712ce7 github.com/tektoncd/triggers v0.18.0 github.com/tetratelabs/wazero v1.7.0 @@ -184,6 +185,7 @@ require ( github.com/pelletier/go-toml v1.9.5 // indirect github.com/peterbourgon/diskv v2.0.1+incompatible // indirect github.com/pjbgf/sha1cd v0.3.0 // indirect + github.com/pmezard/go-difflib v1.0.0 // indirect github.com/prometheus/client_golang v1.16.0 // indirect github.com/prometheus/client_model v0.3.0 // indirect github.com/prometheus/common v0.42.0 // indirect