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

Deployment only out of .json files #222 Bug Fix #245

Merged
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Added unit test cases
AnishVallolikalathilAchuthadas committed Jun 17, 2024

Verified

This commit was signed with the committer’s verified signature.
commit 38d163826e196b81fb320a191aa1e7ff2e3294e0
5 changes: 0 additions & 5 deletions containerm/cli/cli_command_ctrs_create.go
Original file line number Diff line number Diff line change
@@ -18,7 +18,6 @@ import (
"fmt"
"os"
"time"
"strings"

"github.com/eclipse-kanto/container-management/containerm/containers/types"
"github.com/eclipse-kanto/container-management/containerm/log"
@@ -115,10 +114,6 @@ func (cc *createCmd) containerFromFile() (*types.Container, error) {
if err != nil {
return nil, err
}
if !strings.HasSuffix(strings.ToLower(cc.config.containerFile), ".json") {
fileName := cc.config.containerFile
return nil, log.NewError(fmt.Sprintf("file %s is not a json file", fileName))
}
byteValue, err := os.ReadFile(cc.config.containerFile)
if err != nil {
return nil, err
2 changes: 1 addition & 1 deletion containerm/deployment/deployment.go
Original file line number Diff line number Diff line change
@@ -17,8 +17,8 @@ import (
"io/fs"
"os"
"path/filepath"
"sync"
"strings"
"sync"

"github.com/eclipse-kanto/container-management/containerm/containers/types"
"github.com/eclipse-kanto/container-management/containerm/log"
33 changes: 33 additions & 0 deletions containerm/deployment/deployment_test.go
Original file line number Diff line number Diff line change
@@ -82,6 +82,26 @@ 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 {
// 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
},
},
}

// execute tests
@@ -624,3 +644,16 @@ 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)
}
}