github.com/willmadison/cli@v6.40.1-0.20181018160101-29d5937903ff+incompatible/integration/shared/isolated/network_policies_command_test.go (about) 1 package isolated 2 3 import ( 4 "regexp" 5 6 "code.cloudfoundry.org/cli/api/cloudcontroller/ccversion" 7 "code.cloudfoundry.org/cli/integration/helpers" 8 9 . "github.com/onsi/ginkgo" 10 . "github.com/onsi/gomega" 11 . "github.com/onsi/gomega/gbytes" 12 . "github.com/onsi/gomega/gexec" 13 ) 14 15 var _ = Describe("network-policies command", func() { 16 BeforeEach(func() { 17 helpers.SkipIfVersionLessThan(ccversion.MinVersionNetworkingV3) 18 }) 19 20 Describe("help", func() { 21 When("--help flag is set", func() { 22 It("Displays command usage to output", func() { 23 session := helpers.CF("network-policies", "--help") 24 Eventually(session).Should(Say("NAME:")) 25 Eventually(session).Should(Say("network-policies - List direct network traffic policies")) 26 Eventually(session).Should(Say("USAGE:")) 27 Eventually(session).Should(Say(regexp.QuoteMeta("cf network-policies [--source SOURCE_APP]"))) 28 Eventually(session).Should(Say("OPTIONS:")) 29 Eventually(session).Should(Say(" --source Source app to filter results by")) 30 Eventually(session).Should(Say("SEE ALSO:")) 31 Eventually(session).Should(Say(" add-network-policy, apps, remove-network-policy")) 32 Eventually(session).Should(Exit(0)) 33 }) 34 }) 35 }) 36 37 When("the environment is not setup correctly", func() { 38 It("fails with the appropriate errors", func() { 39 helpers.CheckEnvironmentTargetedCorrectly(true, true, ReadOnlyOrg, "network-policies") 40 }) 41 }) 42 43 When("the org and space are properly targetted", func() { 44 var ( 45 orgName string 46 spaceName string 47 appName string 48 ) 49 50 BeforeEach(func() { 51 orgName = helpers.NewOrgName() 52 spaceName = helpers.NewSpaceName() 53 appName = helpers.PrefixedRandomName("app") 54 55 helpers.SetupCF(orgName, spaceName) 56 57 helpers.WithHelloWorldApp(func(appDir string) { 58 Eventually(helpers.CF("push", appName, "-p", appDir, "-b", "staticfile_buildpack", "--no-start")).Should(Exit(0)) 59 }) 60 61 session := helpers.CF("add-network-policy", appName, "--destination-app", appName) 62 Eventually(session).Should(Exit(0)) 63 }) 64 65 AfterEach(func() { 66 helpers.QuickDeleteOrg(orgName) 67 }) 68 69 When("policies exists", func() { 70 It("lists all the policies", func() { 71 session := helpers.CF("network-policies") 72 73 username, _ := helpers.GetCredentials() 74 Eventually(session).Should(Say(`Listing network policies in org %s / space %s as %s\.\.\.`, orgName, spaceName, username)) 75 Consistently(session).ShouldNot(Say("OK")) 76 Eventually(session).Should(Say("source\\s+destination\\s+protocol\\s+ports")) 77 Eventually(session).Should(Say("%s\\s+%s\\s+tcp\\s+8080[^-]", appName, appName)) 78 Eventually(session).Should(Exit(0)) 79 }) 80 }) 81 82 When("policies are filtered by a source app", func() { 83 var srcAppName string 84 BeforeEach(func() { 85 srcAppName = helpers.PrefixedRandomName("app") 86 helpers.WithHelloWorldApp(func(appDir string) { 87 Eventually(helpers.CF("push", srcAppName, "-p", appDir, "-b", "staticfile_buildpack", "--no-start")).Should(Exit(0)) 88 }) 89 90 session := helpers.CF("add-network-policy", srcAppName, "--destination-app", appName) 91 Eventually(session).Should(Exit(0)) 92 }) 93 94 It("lists only policies for which the app is a source", func() { 95 session := helpers.CF("network-policies", "--source", srcAppName) 96 97 username, _ := helpers.GetCredentials() 98 Eventually(session).Should(Say(`Listing network policies of app %s in org %s / space %s as %s\.\.\.`, srcAppName, orgName, spaceName, username)) 99 Eventually(session).Should(Say("source\\s+destination\\s+protocol\\s+ports")) 100 Eventually(session).ShouldNot(Say("%s\\s+%s\\s+tcp\\s+8080[^-]", appName, appName)) 101 Eventually(session).Should(Say("%s\\s+%s\\s+tcp\\s+8080[^-]", srcAppName, appName)) 102 Eventually(session).Should(Exit(0)) 103 }) 104 }) 105 106 When("policies are filtered by a non-existent source app", func() { 107 It("returns an error", func() { 108 session := helpers.CF("network-policies", "--source", "pineapple") 109 110 username, _ := helpers.GetCredentials() 111 Eventually(session).Should(Say(`Listing network policies of app pineapple in org %s / space %s as %s\.\.\.`, orgName, spaceName, username)) 112 Eventually(session.Err).Should(Say("App pineapple not found")) 113 Eventually(session).Should(Say("FAILED")) 114 Eventually(session).Should(Exit(1)) 115 }) 116 }) 117 }) 118 })