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