Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: add unit tests for FormatMapsWithInterface function in cfutils.go #1191

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 47 additions & 4 deletions collector/cfutils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.")
}
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
Loading