|
1 | 1 | package sshcommand |
2 | 2 |
|
3 | | -import "fmt" |
| 3 | +import ( |
| 4 | + "fmt" |
| 5 | + "testing" |
| 6 | + |
| 7 | + . "github.com/smartystreets/goconvey/convey" |
| 8 | +) |
4 | 9 |
|
5 | 10 | func ExampleCommand() *Command { |
6 | 11 | return &Command{ |
@@ -145,3 +150,74 @@ func ExampleCommand_Slice_complex() { |
145 | 150 | // Output: |
146 | 151 | // ["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\""] |
147 | 152 | } |
| 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