Skip to content

Commit ba880ba

Browse files
committed
Added more tests on sshcommand
1 parent 0dd4b19 commit ba880ba

File tree

1 file changed

+77
-1
lines changed

1 file changed

+77
-1
lines changed

pkg/sshcommand/sshcommand_test.go

Lines changed: 77 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
package sshcommand
22

3-
import "fmt"
3+
import (
4+
"fmt"
5+
"testing"
6+
7+
. "github.com/smartystreets/goconvey/convey"
8+
)
49

510
func ExampleCommand() *Command {
611
return &Command{
@@ -145,3 +150,74 @@ func ExampleCommand_Slice_complex() {
145150
// Output:
146151
// ["ssh" "-q" "-o" "UserKnownHostsFile=/dev/null" "-o" "StrictHostKeyChecking=no" "-o" "ProxyCommand=ssh -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -W %h:%p -l toor 5.6.7.8 -t -t" "1.2.3.4" "-t" "-t" "--" "/bin/sh" "-e" "-c" "\"echo hello world\""]
147152
}
153+
154+
func TestCommand_defaults(t *testing.T) {
155+
Convey("Testing Command{} default values", t, func() {
156+
command := Command{}
157+
So(command.Host, ShouldEqual, "")
158+
So(command.Port, ShouldEqual, 0)
159+
So(command.User, ShouldEqual, "")
160+
So(command.SkipHostKeyChecking, ShouldEqual, false)
161+
So(command.Quiet, ShouldEqual, false)
162+
So(len(command.SSHOptions), ShouldEqual, 0)
163+
So(command.Gateway, ShouldEqual, nil)
164+
So(command.AllocateTTY, ShouldEqual, false)
165+
So(len(command.Command), ShouldEqual, 0)
166+
So(command.Debug, ShouldEqual, false)
167+
So(command.NoEscapeCommand, ShouldEqual, false)
168+
So(command.isGateway, ShouldEqual, false)
169+
})
170+
}
171+
172+
func TestCommand_applyDefaults(t *testing.T) {
173+
Convey("Testing Command.applyDefaults()", t, func() {
174+
Convey("On a Command{}", func() {
175+
command := Command{}
176+
command.applyDefaults()
177+
So(command.Host, ShouldEqual, "")
178+
So(command.Port, ShouldEqual, 22)
179+
So(command.User, ShouldEqual, "")
180+
So(command.SkipHostKeyChecking, ShouldEqual, false)
181+
So(command.Quiet, ShouldEqual, false)
182+
So(len(command.SSHOptions), ShouldEqual, 0)
183+
So(command.Gateway, ShouldEqual, nil)
184+
So(command.AllocateTTY, ShouldEqual, false)
185+
So(len(command.Command), ShouldEqual, 0)
186+
So(command.Debug, ShouldEqual, false)
187+
So(command.NoEscapeCommand, ShouldEqual, false)
188+
So(command.isGateway, ShouldEqual, false)
189+
})
190+
Convey("On a New(\"example.com\")", func() {
191+
command := New("example.com")
192+
command.applyDefaults()
193+
So(command.Host, ShouldEqual, "example.com")
194+
So(command.Port, ShouldEqual, 22)
195+
So(command.User, ShouldEqual, "")
196+
So(command.SkipHostKeyChecking, ShouldEqual, false)
197+
So(command.Quiet, ShouldEqual, false)
198+
So(len(command.SSHOptions), ShouldEqual, 0)
199+
So(command.Gateway, ShouldEqual, nil)
200+
So(command.AllocateTTY, ShouldEqual, false)
201+
So(len(command.Command), ShouldEqual, 0)
202+
So(command.Debug, ShouldEqual, false)
203+
So(command.NoEscapeCommand, ShouldEqual, false)
204+
So(command.isGateway, ShouldEqual, false)
205+
})
206+
Convey("On a New(\"[email protected]\")", func() {
207+
command := New("[email protected]")
208+
command.applyDefaults()
209+
So(command.Host, ShouldEqual, "example.com")
210+
So(command.Port, ShouldEqual, 22)
211+
So(command.User, ShouldEqual, "toto")
212+
So(command.SkipHostKeyChecking, ShouldEqual, false)
213+
So(command.Quiet, ShouldEqual, false)
214+
So(len(command.SSHOptions), ShouldEqual, 0)
215+
So(command.Gateway, ShouldEqual, nil)
216+
So(command.AllocateTTY, ShouldEqual, false)
217+
So(len(command.Command), ShouldEqual, 0)
218+
So(command.Debug, ShouldEqual, false)
219+
So(command.NoEscapeCommand, ShouldEqual, false)
220+
So(command.isGateway, ShouldEqual, false)
221+
})
222+
})
223+
}

0 commit comments

Comments
 (0)