mirror of
https://github.com/appleboy/drone-ssh.git
synced 2025-05-09 18:23:21 +08:00
test: Add escapeArg testing (#116)
This commit is contained in:
parent
7f4cb1c1d0
commit
8bfc58f9d0
@ -273,3 +273,36 @@ func TestSyncMode(t *testing.T) {
|
|||||||
err := plugin.Exec()
|
err := plugin.Exec()
|
||||||
assert.Nil(t, err)
|
assert.Nil(t, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func Test_escapeArg(t *testing.T) {
|
||||||
|
type args struct {
|
||||||
|
arg string
|
||||||
|
}
|
||||||
|
tests := []struct {
|
||||||
|
name string
|
||||||
|
args args
|
||||||
|
want string
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "escape nothing",
|
||||||
|
args: args{
|
||||||
|
arg: "Hi I am appleboy",
|
||||||
|
},
|
||||||
|
want: `'Hi I am appleboy'`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "escape single quote",
|
||||||
|
args: args{
|
||||||
|
arg: "Hi I am 'appleboy'",
|
||||||
|
},
|
||||||
|
want: `'Hi I am '\''appleboy'\'''`,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
for _, tt := range tests {
|
||||||
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
|
if got := escapeArg(tt.args.arg); got != tt.want {
|
||||||
|
t.Errorf("escapeArg() = %v, want %v", got, tt.want)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user