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