From 121a57017e431ab879492975e59bfb6b16fe69d1 Mon Sep 17 00:00:00 2001 From: AnishVallolikalathilAchuthadas Date: Tue, 18 Jun 2024 14:22:03 +0530 Subject: [PATCH] [#222] Deployment only out of .json files (#245) [#222] Deployment only out of .json files Signed-off-by: Anish Vallolikalathil Achuthadas --- containerm/deployment/deployment.go | 3 ++- containerm/deployment/deployment_test.go | 7 +++++++ .../pkg/testutil/config/container/non_json_files/file1.txt | 1 + 3 files changed, 10 insertions(+), 1 deletion(-) create mode 100644 containerm/pkg/testutil/config/container/non_json_files/file1.txt diff --git a/containerm/deployment/deployment.go b/containerm/deployment/deployment.go index daeaadb..d638549 100755 --- a/containerm/deployment/deployment.go +++ b/containerm/deployment/deployment.go @@ -17,6 +17,7 @@ import ( "io/fs" "os" "path/filepath" + "strings" "sync" "github.com/eclipse-kanto/container-management/containerm/containers/types" @@ -87,7 +88,7 @@ func (d *deploymentMgr) Deploy(ctx context.Context) error { if err != nil { return err } - if !entry.IsDir() { + if !entry.IsDir() && strings.HasSuffix(path, ".json") { ctr, readErr := util.ReadContainer(path) if readErr != nil { log.ErrorErr(readErr, "error reading container configuration from file = %s", path) diff --git a/containerm/deployment/deployment_test.go b/containerm/deployment/deployment_test.go index 102bbad..adf96c6 100755 --- a/containerm/deployment/deployment_test.go +++ b/containerm/deployment/deployment_test.go @@ -82,6 +82,13 @@ func TestDeployCommon(t *testing.T) { return nil }, }, + "test_deploy_ignore_non_json_files": { + ctrPath: filepath.Join(baseCtrJSONPath, "non_json_files"), + mockExec: func(mockMgr *mocks.MockContainerManager) error { + mockMgr.EXPECT().List(testContext).Return(nil, nil).Times(2) + return nil + }, + }, } // execute tests diff --git a/containerm/pkg/testutil/config/container/non_json_files/file1.txt b/containerm/pkg/testutil/config/container/non_json_files/file1.txt new file mode 100644 index 0000000..815e2a6 --- /dev/null +++ b/containerm/pkg/testutil/config/container/non_json_files/file1.txt @@ -0,0 +1 @@ +This file is for testing purpose of non json files