Skip to content

Commit

Permalink
Add shell quoting test
Browse files Browse the repository at this point in the history
Signed-off-by: Sjoerd Simons <[email protected]>
  • Loading branch information
sjoerdsimons authored and obbardc committed Nov 10, 2023
1 parent 639d6af commit 5b4b7a2
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions machine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@ import (
)

var backendName string
var testArg string

func init() {
flag.StringVar(&backendName, "backend", "auto", "Fakemachine backend to use")
flag.StringVar(&testArg, "testarg", "", "Test specific argument")
}

func CreateMachine(t *testing.T) *Machine {
Expand Down Expand Up @@ -217,3 +219,22 @@ func TestVolumes(t *testing.T) {
require.Equal(t, exitcode, -1)
require.Error(t, err)
}

func TestCommandEscaping(t *testing.T) {
t.Parallel()
if InMachine() {
t.Log("Running in the machine")
require.Equal(t, testArg, "$s'n\\akes")
t.Log(testArg)
return
}

m := CreateMachine(t)
exitcode, _ := m.RunInMachineWithArgs([]string{
"-test.v", "-test.run",
"TestCommandEscaping", "-testarg", "$s'n\\akes"})

if exitcode != 0 {
t.Fatalf("Expected 0 but got %d", exitcode)
}
}

0 comments on commit 5b4b7a2

Please sign in to comment.