github.com/randomtask1155/cli@v6.41.1-0.20181227003417-a98eed78cbde+incompatible/integration/shared/experimental/v3_droplets_command_test.go (about)

     1  package experimental
     2  
     3  import (
     4  	"code.cloudfoundry.org/cli/api/cloudcontroller/ccversion"
     5  	"code.cloudfoundry.org/cli/integration/helpers"
     6  	. "github.com/onsi/ginkgo"
     7  	. "github.com/onsi/gomega"
     8  	. "github.com/onsi/gomega/gbytes"
     9  	. "github.com/onsi/gomega/gexec"
    10  	. "github.com/onsi/gomega/ghttp"
    11  )
    12  
    13  var _ = Describe("v3-droplets command", func() {
    14  	var (
    15  		orgName   string
    16  		spaceName string
    17  		appName   string
    18  	)
    19  
    20  	BeforeEach(func() {
    21  		orgName = helpers.NewOrgName()
    22  		spaceName = helpers.NewSpaceName()
    23  		appName = helpers.NewAppName()
    24  	})
    25  
    26  	Describe("help", func() {
    27  		When("--help flag is set", func() {
    28  			It("Displays command usage to output", func() {
    29  				session := helpers.CF("v3-droplets", "--help")
    30  
    31  				Eventually(session).Should(Say("NAME:"))
    32  				Eventually(session).Should(Say("v3-droplets - List droplets of an app"))
    33  				Eventually(session).Should(Say("USAGE:"))
    34  				Eventually(session).Should(Say("cf v3-droplets APP_NAME"))
    35  
    36  				Eventually(session).Should(Exit(0))
    37  			})
    38  		})
    39  	})
    40  
    41  	When("the app name is not provided", func() {
    42  		It("tells the user that the app name is required, prints help text, and exits 1", func() {
    43  			session := helpers.CF("v3-droplets")
    44  
    45  			Eventually(session.Err).Should(Say("Incorrect Usage: the required argument `APP_NAME` was not provided"))
    46  			Eventually(session).Should(Say("NAME:"))
    47  			Eventually(session).Should(Exit(1))
    48  		})
    49  	})
    50  
    51  	It("displays the experimental warning", func() {
    52  		session := helpers.CF("v3-droplets", appName)
    53  		Eventually(session.Err).Should(Say("This command is in EXPERIMENTAL stage and may change without notice"))
    54  		Eventually(session).Should(Exit())
    55  	})
    56  
    57  	When("the environment is not setup correctly", func() {
    58  		When("the v3 api version is lower than the minimum version", func() {
    59  			var server *Server
    60  
    61  			BeforeEach(func() {
    62  				server = helpers.StartAndTargetServerWithAPIVersions(helpers.DefaultV2Version, ccversion.MinV3ClientVersion)
    63  			})
    64  
    65  			AfterEach(func() {
    66  				server.Close()
    67  			})
    68  
    69  			It("fails with error message that the minimum version is not met", func() {
    70  				session := helpers.CF("v3-droplets", appName)
    71  				Eventually(session).Should(Say("FAILED"))
    72  				Eventually(session.Err).Should(Say(`This command requires CF API version 3\.27\.0 or higher\.`))
    73  				Eventually(session).Should(Exit(1))
    74  			})
    75  		})
    76  
    77  		It("fails with the appropriate errors", func() {
    78  			helpers.CheckEnvironmentTargetedCorrectly(true, true, ReadOnlyOrg, "v3-droplets", appName)
    79  		})
    80  	})
    81  
    82  	When("the environment is set up correctly", func() {
    83  		var userName string
    84  
    85  		BeforeEach(func() {
    86  			helpers.SetupCF(orgName, spaceName)
    87  			userName, _ = helpers.GetCredentials()
    88  		})
    89  
    90  		AfterEach(func() {
    91  			helpers.QuickDeleteOrg(orgName)
    92  		})
    93  
    94  		When("the app does not exist", func() {
    95  			It("displays app not found and exits 1", func() {
    96  				session := helpers.CF("v3-droplets", appName)
    97  
    98  				Eventually(session).Should(Say(`Listing droplets of app %s in org %s / space %s as %s\.\.\.`, appName, orgName, spaceName, userName))
    99  				Eventually(session.Err).Should(Say("App %s not found", appName))
   100  				Eventually(session).Should(Say("FAILED"))
   101  
   102  				Eventually(session).Should(Exit(1))
   103  			})
   104  		})
   105  
   106  		When("the app exists", func() {
   107  			Context("with no droplets", func() {
   108  				BeforeEach(func() {
   109  					Eventually(helpers.CF("v3-create-app", appName)).Should(Exit(0))
   110  				})
   111  
   112  				It("displays empty list", func() {
   113  					session := helpers.CF("v3-droplets", appName)
   114  					Eventually(session).Should(Say(`Listing droplets of app %s in org %s / space %s as %s\.\.\.`, appName, orgName, spaceName, userName))
   115  					Eventually(session).Should(Say("No droplets found"))
   116  					Eventually(session).Should(Exit(0))
   117  				})
   118  			})
   119  
   120  			Context("with existing droplets", func() {
   121  				BeforeEach(func() {
   122  					helpers.WithHelloWorldApp(func(dir string) {
   123  						Eventually(helpers.CustomCF(helpers.CFEnv{WorkingDirectory: dir}, "v3-push", appName)).Should(Exit(0))
   124  					})
   125  				})
   126  
   127  				It("displays droplets in the list", func() {
   128  					session := helpers.CF("v3-droplets", appName)
   129  					Eventually(session).Should(Say(`Listing droplets of app %s in org %s / space %s as %s\.\.\.`, appName, orgName, spaceName, userName))
   130  					Eventually(session).Should(Say(`guid\s+state\s+created`))
   131  					Eventually(session).Should(Say(`\s+.*\s+staged\s+%s`, helpers.UserFriendlyDateRegex))
   132  
   133  					Eventually(session).Should(Exit(0))
   134  				})
   135  			})
   136  		})
   137  	})
   138  })