Skip to content
Open
Changes from all commits
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
51 changes: 51 additions & 0 deletions pkg/command/escape_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package command

import (
"testing"

"github.com/stretchr/testify/assert"
)

const agentInternalSSHGitClone = "agent internal ssh-git-clone"

func TestQuote(t *testing.T) {
cases := []struct {
name string
args []string
want string
}{
{name: "empty returns empty", args: nil, want: ""},
{name: "empty slice returns empty", args: []string{}, want: ""},
{
name: "single arg passed through unquoted",
args: []string{"devsy-linux-amd64"},
want: "devsy-linux-amd64",
},
{
name: "single arg with spaces passed through unchanged",
args: []string{agentInternalSSHGitClone},
want: agentInternalSSHGitClone,
},
{
name: "multiple args are shell-quoted and joined",
args: []string{"agent", "internal", "ssh-git-clone"},
want: agentInternalSSHGitClone,
},
{
name: "arg needing escaping is single-quoted",
args: []string{"agent", "--key-file=/tmp/my key"},
want: "agent '--key-file=/tmp/my key'",
},
{
name: "embedded single quote is escaped",
args: []string{"echo", "it's"},
want: "echo 'it'\"'\"'s'",
},
}

for _, tc := range cases {
t.Run(tc.name, func(t *testing.T) {
assert.Equal(t, tc.want, Quote(tc.args))
})
}
}
Loading