From 3a15f375ee844579d54fc0076409ae8a85a54dea Mon Sep 17 00:00:00 2001 From: brf153 <153hsb@gmail.com> Date: Fri, 2 Aug 2024 14:50:47 +0530 Subject: [PATCH 1/2] add test for FormatMapsWithInterface in cfutils.go Signed-off-by: brf153 <153hsb@gmail.com> --- collector/cfutils_test.go | 67 +++++++++++++++++++++++++++------------ go.mod | 2 ++ 2 files changed, 49 insertions(+), 20 deletions(-) diff --git a/collector/cfutils_test.go b/collector/cfutils_test.go index 8784edb57..de98a9bc0 100644 --- a/collector/cfutils_test.go +++ b/collector/cfutils_test.go @@ -1,32 +1,59 @@ -/* - * Copyright IBM Corporation 2021 - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - 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 From e1cff2bc2c642f6b5a4194d192d8de72cab8bd9d Mon Sep 17 00:00:00 2001 From: brf153 <153hsb@gmail.com> Date: Fri, 2 Aug 2024 19:01:04 +0530 Subject: [PATCH 2/2] add license to cfutils_test.go Signed-off-by: brf153 <153hsb@gmail.com> --- collector/cfutils_test.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/collector/cfutils_test.go b/collector/cfutils_test.go index de98a9bc0..b20847a6d 100644 --- a/collector/cfutils_test.go +++ b/collector/cfutils_test.go @@ -1,3 +1,19 @@ +/* + * Copyright IBM Corporation 2021 + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package collector_test import (