github.com/loafoe/cli@v7.1.0+incompatible/integration/v6/push/name_only_test.go (about)

     1  package push
     2  
     3  import (
     4  	"fmt"
     5  	"regexp"
     6  	"strings"
     7  
     8  	"code.cloudfoundry.org/cli/integration/helpers"
     9  
    10  	. "github.com/onsi/ginkgo"
    11  	. "github.com/onsi/gomega"
    12  	. "github.com/onsi/gomega/gbytes"
    13  	. "github.com/onsi/gomega/gexec"
    14  )
    15  
    16  var _ = Describe("push with only an app name", func() {
    17  	var (
    18  		appName  string
    19  		username string
    20  	)
    21  
    22  	BeforeEach(func() {
    23  		appName = helpers.NewAppName()
    24  		username, _ = helpers.GetCredentials()
    25  	})
    26  
    27  	Describe("app existence", func() {
    28  		When("the app does not exist", func() {
    29  			It("creates the app", func() {
    30  				helpers.WithHelloWorldApp(func(dir string) {
    31  					session := helpers.CustomCF(helpers.CFEnv{WorkingDirectory: dir}, PushCommandName, appName)
    32  					Eventually(session).Should(Say(`Pushing app %s to org %s / space %s as %s\.\.\.`, appName, organization, space, username))
    33  					Eventually(session).Should(Say(`Getting app info\.\.\.`))
    34  					Eventually(session).Should(Say(`Creating app with these attributes\.\.\.`))
    35  					Eventually(session).Should(Say(`\+\s+name:\s+%s`, appName))
    36  					Eventually(session).Should(Say(`\s+routes:`))
    37  					Eventually(session).Should(Say(`(?i)\+\s+%s.%s`, appName, helpers.DefaultSharedDomain()))
    38  					Eventually(session).Should(Say(`Mapping routes\.\.\.`))
    39  					Eventually(session).Should(Say(`Comparing local files to remote cache\.\.\.`))
    40  					Eventually(session).Should(Say(`Packaging files to upload\.\.\.`))
    41  					Eventually(session).Should(Say(`Uploading files\.\.\.`))
    42  					Eventually(session).Should(Say("100.00%"))
    43  					Eventually(session).Should(Say(`Waiting for API to complete processing files\.\.\.`))
    44  					helpers.ConfirmStagingLogs(session)
    45  					Eventually(session).Should(Say(`Waiting for app to start\.\.\.`))
    46  					Eventually(session).Should(Say(`requested state:\s+started`))
    47  					Eventually(session).Should(Exit(0))
    48  				})
    49  
    50  				session := helpers.CF("app", appName)
    51  				Eventually(session).Should(Say(`name:\s+%s`, appName))
    52  				Eventually(session).Should(Exit(0))
    53  			})
    54  
    55  			When("the app has a non-standard name", func() {
    56  				BeforeEach(func() {
    57  					appName = helpers.PrefixedRandomName("App Name One$")
    58  				})
    59  
    60  				It("sanitizes the name and creates the app", func() {
    61  					sanitizedName := fmt.Sprintf("app-name-one-%s", strings.SplitN(appName, "-", 2)[1])
    62  
    63  					helpers.WithHelloWorldApp(func(dir string) {
    64  						session := helpers.CustomCF(helpers.CFEnv{WorkingDirectory: dir}, PushCommandName, appName)
    65  						Eventually(session).Should(Say(`Pushing app %s to org %s / space %s as %s\.\.\.`, regexp.QuoteMeta(appName), organization, space, username))
    66  						Eventually(session).Should(Say(`Getting app info\.\.\.`))
    67  						Eventually(session).Should(Say(`Creating app with these attributes\.\.\.`))
    68  						Eventually(session).Should(Say(`\+\s+name:\s+%s`, regexp.QuoteMeta(appName)))
    69  						Eventually(session).Should(Say(`\s+routes:`))
    70  						Eventually(session).Should(Say(`(?i)\+\s+%s.%s`, regexp.QuoteMeta(sanitizedName), helpers.DefaultSharedDomain()))
    71  						Eventually(session).Should(Say(`Mapping routes\.\.\.`))
    72  						Eventually(session).Should(Say(`Comparing local files to remote cache\.\.\.`))
    73  						Eventually(session).Should(Say(`Packaging files to upload\.\.\.`))
    74  						Eventually(session).Should(Say(`Uploading files\.\.\.`))
    75  						Eventually(session).Should(Say("100.00%"))
    76  						Eventually(session).Should(Say(`Waiting for API to complete processing files\.\.\.`))
    77  						helpers.ConfirmStagingLogs(session)
    78  						Eventually(session).Should(Say(`Waiting for app to start\.\.\.`))
    79  						Eventually(session).Should(Say(`requested state:\s+started`))
    80  						Eventually(session).Should(Exit(0))
    81  					})
    82  
    83  					session := helpers.CF("app", appName)
    84  					Eventually(session).Should(Say(`name:\s+%s`, regexp.QuoteMeta(appName)))
    85  					Eventually(session).Should(Exit(0))
    86  				})
    87  			})
    88  		})
    89  
    90  		When("the app exists", func() {
    91  			BeforeEach(func() {
    92  				helpers.WithHelloWorldApp(func(dir string) {
    93  					Eventually(helpers.CustomCF(helpers.CFEnv{WorkingDirectory: dir}, PushCommandName, appName)).Should(Exit(0))
    94  				})
    95  			})
    96  
    97  			It("updates the app", func() {
    98  				helpers.WithHelloWorldApp(func(dir string) {
    99  					session := helpers.CustomCF(helpers.CFEnv{WorkingDirectory: dir}, PushCommandName, appName)
   100  					Eventually(session).Should(Say(`Getting app info\.\.\.`))
   101  					Eventually(session).Should(Say(`Updating app with these attributes\.\.\.`))
   102  					Eventually(session).Should(Say(`(?m)^\s+name:\s+%s$`, appName))
   103  					Eventually(session).Should(Say(`\s+routes:`))
   104  					Eventually(session).Should(Say(`(?mi)^\s+%s.%s$`, strings.ToLower(appName), helpers.DefaultSharedDomain()))
   105  					Eventually(session).Should(Say(`Mapping routes\.\.\.`))
   106  					Eventually(session).Should(Say(`Uploading files\.\.\.`))
   107  					Eventually(session).Should(Say("100.00%"))
   108  					Eventually(session).Should(Say(`Waiting for API to complete processing files\.\.\.`))
   109  					Eventually(session).Should(Say(`Stopping app\.\.\.`))
   110  					helpers.ConfirmStagingLogs(session)
   111  					Eventually(session).Should(Say(`Waiting for app to start\.\.\.`))
   112  					Eventually(session).Should(Say(`requested state:\s+started`))
   113  					Eventually(session).Should(Exit(0))
   114  				})
   115  
   116  				session := helpers.CF("app", appName)
   117  				Eventually(session).Should(Say(`name:\s+%s`, appName))
   118  				Eventually(session).Should(Exit(0))
   119  			})
   120  		})
   121  	})
   122  })