Skip to content

Commit

Permalink
Add unit test cases and static files for the same
Browse files Browse the repository at this point in the history
  • Loading branch information
AnishVallolikalathilAchuthadas committed Jun 18, 2024
1 parent 38d1638 commit 5400466
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 34 deletions.
14 changes: 6 additions & 8 deletions containerm/deployment/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
26 changes: 0 additions & 26 deletions containerm/deployment/deployment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
},
},
Expand Down Expand Up @@ -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)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This file is for testing purpose of non json files

0 comments on commit 5400466

Please sign in to comment.