diff --git a/containerm/deployment/deployment.go b/containerm/deployment/deployment.go index cc40304..54ea4c4 100755 --- a/containerm/deployment/deployment.go +++ b/containerm/deployment/deployment.go @@ -88,14 +88,12 @@ func (d *deploymentMgr) Deploy(ctx context.Context) error { if err != nil { return err } - if !entry.IsDir() { - if strings.HasSuffix(path, ".json") { - ctr, readErr := util.ReadContainer(path) - if readErr != nil { - log.ErrorErr(readErr, "error reading container configuration from file = %s", path) - } else { - ctrs = append(ctrs, ctr) - } + if !entry.IsDir() && strings.HasSuffix(path, ".json") { + ctr, readErr := util.ReadContainer(path) + if readErr != nil { + log.ErrorErr(readErr, "error reading container configuration from file =", path) + } else { + ctrs = append(ctrs, ctr) } } return nil diff --git a/containerm/deployment/deployment_test.go b/containerm/deployment/deployment_test.go index 8a815d3..adf96c6 100755 --- a/containerm/deployment/deployment_test.go +++ b/containerm/deployment/deployment_test.go @@ -85,20 +85,7 @@ func TestDeployCommon(t *testing.T) { "test_deploy_ignore_non_json_files": { ctrPath: filepath.Join(baseCtrJSONPath, "non_json_files"), mockExec: func(mockMgr *mocks.MockContainerManager) error { - // Set up the mock directory with only the specified non-JSON file - mockDirPath := filepath.Join(baseCtrJSONPath, "non_json_files") - createMockDirectoryWithNonJSONFile(t, mockDirPath) - - // Expecting no interactions with the mock manager for the non-JSON file mockMgr.EXPECT().List(testContext).Return(nil, nil).Times(2) - - // Clean up the mock directory after test - defer func() { - if err := os.RemoveAll(mockDirPath); err != nil { - t.Fatalf("failed to remove mock directory: %v", err) - } - }() - return nil }, }, @@ -644,16 +631,3 @@ func createTmpMetaPathNonEmpty(t *testing.T) string { func newTestContainer(name, image string) *types.Container { return &types.Container{Name: name, Image: types.Image{Name: image}} } - -func createMockDirectoryWithNonJSONFile(t *testing.T, dirPath string) { - err := os.MkdirAll(dirPath, 0755) - if err != nil { - t.Fatalf("failed to create mock directory: %v", err) - } - - filePath := filepath.Join(dirPath, "file1.txt") - content := "This is a text file." - if err := os.WriteFile(filePath, []byte(content), 0644); err != nil { - t.Fatalf("failed to create mock file %s: %v", filePath, err) - } -} 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