forked from warewulf/warewulf
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix regression in container exec argument parsing
- Fixes warewulf#1250 Signed-off-by: Jonathon Anderson <[email protected]>
- Loading branch information
1 parent
1f274c0
commit 5bb13c8
Showing
4 changed files
with
118 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package exec | ||
|
||
import ( | ||
"bytes" | ||
"os/exec" | ||
"testing" | ||
|
||
"github.com/spf13/cobra" | ||
"github.com/stretchr/testify/assert" | ||
"github.com/warewulf/warewulf/internal/pkg/testenv" | ||
) | ||
|
||
func mockChildCmd(cmd *cobra.Command, args []string) error { | ||
child := exec.Command("/usr/bin/echo", args...) | ||
child.Stdin = cmd.InOrStdin() | ||
child.Stdout = cmd.OutOrStdout() | ||
child.Stderr = cmd.ErrOrStderr() | ||
return child.Run() | ||
} | ||
|
||
func Test_Exec_with_bind(t *testing.T) { | ||
env := testenv.New(t) | ||
defer env.RemoveAll(t) | ||
env.MkdirAll(t, "var/lib/warewulf/chroots/alpine/rootfs") | ||
childCommandFunc = mockChildCmd | ||
defer func() { | ||
childCommandFunc = runChildCmd | ||
}() | ||
|
||
cmd := GetCommand() | ||
out := bytes.NewBufferString("") | ||
err := bytes.NewBufferString("") | ||
cmd.SetOut(out) | ||
cmd.SetErr(err) | ||
cmd.SetArgs([]string{"--bind", "/mnt:/mnt", "alpine", "--", "/bin/echo", "Hello, world!"}) | ||
assert.NoError(t, cmd.Execute()) | ||
assert.Contains(t, out.String(), "alpine") | ||
assert.Contains(t, out.String(), "/bin/echo Hello, world!") | ||
assert.Contains(t, out.String(), "--bind /mnt:/mnt") | ||
assert.Empty(t, err.String()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters