forked from cloudfoundry/cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathssh_port_forwarding_test.go
62 lines (54 loc) · 1.9 KB
/
ssh_port_forwarding_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package flag_test
import (
"fmt"
. "code.cloudfoundry.org/cli/command/flag"
flags "github.com/jessevdk/go-flags"
. "github.com/onsi/ginkgo"
. "github.com/onsi/ginkgo/extensions/table"
. "github.com/onsi/gomega"
)
var _ = Describe("SpaceRole", func() {
var forward SSHPortForwarding
Describe("UnmarshalFlag", func() {
BeforeEach(func() {
forward = SSHPortForwarding{}
})
When("passed local_port:remote:remote_port", func() {
It("extracts the local and remote addresses", func() {
err := forward.UnmarshalFlag("8888:remote:8080")
Expect(err).ToNot(HaveOccurred())
Expect(forward).To(Equal(SSHPortForwarding{
LocalAddress: "localhost:8888",
RemoteAddress: "remote:8080",
}))
})
})
When("passed local:local_port:remote:remote_port", func() {
It("extracts the local and remote addresses", func() {
err := forward.UnmarshalFlag("local:8888:remote:8080")
Expect(err).ToNot(HaveOccurred())
Expect(forward).To(Equal(SSHPortForwarding{
LocalAddress: "local:8888",
RemoteAddress: "remote:8080",
}))
})
})
DescribeTable("error cases",
func(input string) {
err := forward.UnmarshalFlag(input)
Expect(err).To(MatchError(&flags.Error{
Type: flags.ErrRequired,
Message: fmt.Sprintf("Bad local forwarding specification '%s'", input),
}))
},
Entry("no colons", "IAMABANANA909009009"),
Entry("1 colon", "IAMABANANA:909009009"),
Entry("too many colons", "I:AM:A:BANANA:909009009"),
Entry("empty values in between colons", "I:AM:A:"),
Entry("[implicit localhost] incorrect port numbers for first value", "I:AM:8888"),
Entry("[implicit localhost] incorrect port numbers for third value", "8888:AM:potato"),
Entry("[explicit localhost] incorrect port numbers for second value", "localhost:foo:AM:8888"),
Entry("[explicit localhost] incorrect port numbers for fourth value", "localhost:8080:AM:bar"),
)
})
})