Skip to content

Commit

Permalink
chore: add longform boolean unit tests
Browse files Browse the repository at this point in the history
Signed-off-by: Arjun Raja Yogidas <[email protected]>
  • Loading branch information
coderbirju committed Nov 16, 2024
1 parent 3a81c08 commit 99fbb94
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 0 deletions.
30 changes: 30 additions & 0 deletions cmd/finch/nerdctl_darwin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1171,6 +1171,36 @@ func TestNerdctlCommand_run(t *testing.T) {
c.EXPECT().Run()
},
},
{
name: "with long-form boolean flags",
cmdName: "run",
fc: &config.Finch{},
args: []string{
"-e", "ARG1=val1", "-p", "8080:8080",
"--name", "myContainer", "--interactive=true", "--detach", "--rm=true", "--init=false", "--privileged=false", "alpine:latest", "env",
},
wantErr: nil,
mockSvc: func(
_ *testing.T,
lcc *mocks.NerdctlCmdCreator,
_ *mocks.CommandCreator,
ncsd *mocks.NerdctlCommandSystemDeps,
logger *mocks.Logger,
ctrl *gomock.Controller,
_ afero.Fs,
) {
getVMStatusC := mocks.NewCommand(ctrl)
lcc.EXPECT().CreateWithoutStdio("ls", "-f", "{{.Status}}", limaInstanceName).Return(getVMStatusC)
getVMStatusC.EXPECT().Output().Return([]byte("Running"), nil)
logger.EXPECT().Debugf("Status of virtual machine: %s", "Running")
AddEmptyEnvLookUps(ncsd)
c := mocks.NewCommand(ctrl)
lcc.EXPECT().Create("shell", limaInstanceName, "sudo", "-E", nerdctlCmdName, "container", "run",
"-p", "8080:8080", "--name", "myContainer", "--interactive=true", "--detach", "--rm=true", "--init=false", "--privileged=false", "-e", "ARG1=val1",
"alpine:latest", "env").Return(c)
c.EXPECT().Run()
},
},
}

for _, tc := range testCases {
Expand Down
31 changes: 31 additions & 0 deletions cmd/finch/nerdctl_windows_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -769,6 +769,37 @@ func TestNerdctlCommand_run(t *testing.T) {
c.EXPECT().Run()
},
},
{
name: "with long-form boolean flags",
cmdName: "run",
fc: &config.Finch{},
args: []string{"--interactive=true", "--detach", "--rm=true", "--init=false", "--privileged=false", "alpine:latest"},
wantErr: nil,
mockSvc: func(
_ *testing.T,
_ *mocks.CommandCreator,
ncc *mocks.NerdctlCmdCreator,
_ *mocks.Command,
ncsd *mocks.NerdctlCommandSystemDeps,
logger *mocks.Logger,
ctrl *gomock.Controller,
_ afero.Fs,
) {
getVMStatusC := mocks.NewCommand(ctrl)
ncc.EXPECT().CreateWithoutStdio("ls", "-f", "{{.Status}}", limaInstanceName).Return(getVMStatusC)
getVMStatusC.EXPECT().Output().Return([]byte("Running"), nil)
logger.EXPECT().Debugf("Status of virtual machine: %s", "Running")
AddEmptyEnvLookUps(ncsd)
ncsd.EXPECT().GetWd().Return("C:\\workdir", nil)
ncsd.EXPECT().FilePathAbs("C:\\workdir").Return("C:\\workdir", nil)
ncsd.EXPECT().FilePathJoin(string(filepath.Separator), "mnt", "c", "workdir").Return(augmentedPath)
ncsd.EXPECT().FilePathToSlash(augmentedPath).Return(wslPath)
c := mocks.NewCommand(ctrl)
ncc.EXPECT().Create("shell", "--workdir", wslPath, limaInstanceName, "sudo", "-E", nerdctlCmdName, "container", "run",
"--interactive=true", "--detach", "--privileged=false", "--rm=true", "--init=false", "alpine:latest").Return(c)
c.EXPECT().Run()
},
},
}

for _, tc := range testCases {
Expand Down

0 comments on commit 99fbb94

Please sign in to comment.