github.com/loggregator/cli@v6.33.1-0.20180224010324-82334f081791+incompatible/integration/push/start_command_test.go (about) 1 package push 2 3 import ( 4 "fmt" 5 "path/filepath" 6 "regexp" 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 different start command values", func() { 17 var ( 18 appName string 19 ) 20 21 BeforeEach(func() { 22 appName = helpers.NewAppName() 23 }) 24 25 Context("when the start command flag is provided", func() { 26 It("sets the start command correctly for the pushed app", func() { 27 helpers.WithHelloWorldApp(func(dir string) { 28 By("pushing the app with no provided start command uses detected command") 29 session := helpers.CustomCF(helpers.CFEnv{WorkingDirectory: dir}, PushCommandName, appName) 30 Eventually(session).Should(Say("start command:\\s+%s", regexp.QuoteMeta(helpers.StaticfileBuildpackStartCommand))) 31 Eventually(session).Should(Exit(0)) 32 33 By("pushing the app with a start command uses provided start command") 34 session = helpers.CustomCF(helpers.CFEnv{WorkingDirectory: dir}, 35 PushCommandName, appName, 36 "-c", fmt.Sprintf("%s && echo hello", helpers.StaticfileBuildpackStartCommand)) 37 Eventually(session).Should(Say("start command:\\s+%s && echo hello", regexp.QuoteMeta(helpers.StaticfileBuildpackStartCommand))) 38 Eventually(session).Should(Exit(0)) 39 40 By("pushing the app with no provided start command again uses previously set command") 41 session = helpers.CustomCF(helpers.CFEnv{WorkingDirectory: dir}, PushCommandName, appName) 42 Eventually(session).Should(Say("start command:\\s+%s && echo hello", regexp.QuoteMeta(helpers.StaticfileBuildpackStartCommand))) 43 Eventually(session).Should(Exit(0)) 44 45 By("pushing the app with default uses detected command") 46 session = helpers.CustomCF(helpers.CFEnv{WorkingDirectory: dir}, 47 PushCommandName, appName, 48 "-c", "default") 49 Eventually(session).Should(Say("(?m)start command:\\s+%s", regexp.QuoteMeta(helpers.StaticfileBuildpackStartCommand))) 50 Eventually(session).Should(Exit(0)) 51 52 By("pushing the app with null uses detected command") 53 session = helpers.CustomCF(helpers.CFEnv{WorkingDirectory: dir}, 54 PushCommandName, appName, 55 "-c", "null") 56 Eventually(session).Should(Say("(?m)start command:\\s+%s", regexp.QuoteMeta(helpers.StaticfileBuildpackStartCommand))) 57 Eventually(session).Should(Exit(0)) 58 }) 59 }) 60 }) 61 62 Context("when the start command is provided in the manifest", func() { 63 It("sets the start command correctly for the pushed app", func() { 64 helpers.WithHelloWorldApp(func(dir string) { 65 By("pushing the app with no provided start command uses detected command") 66 helpers.WriteManifest(filepath.Join(dir, "manifest.yml"), map[string]interface{}{ 67 "applications": []map[string]interface{}{ 68 { 69 "name": appName, 70 "path": dir, 71 }, 72 }, 73 }) 74 session := helpers.CustomCF(helpers.CFEnv{WorkingDirectory: dir}, PushCommandName, appName) 75 Eventually(session).Should(Say("start command:\\s+%s", regexp.QuoteMeta(helpers.StaticfileBuildpackStartCommand))) 76 Eventually(session).Should(Exit(0)) 77 78 By("pushing the app with a start command uses provided start command") 79 helpers.WriteManifest(filepath.Join(dir, "manifest.yml"), map[string]interface{}{ 80 "applications": []map[string]interface{}{ 81 { 82 "name": appName, 83 "path": dir, 84 "command": fmt.Sprintf("%s && echo hello", helpers.StaticfileBuildpackStartCommand), 85 }, 86 }, 87 }) 88 session = helpers.CustomCF(helpers.CFEnv{WorkingDirectory: dir}, PushCommandName, appName) 89 Eventually(session).Should(Say("start command:\\s+%s && echo hello", regexp.QuoteMeta(helpers.StaticfileBuildpackStartCommand))) 90 Eventually(session).Should(Exit(0)) 91 92 By("pushing the app with no provided start command again uses previously set command") 93 helpers.WriteManifest(filepath.Join(dir, "manifest.yml"), map[string]interface{}{ 94 "applications": []map[string]interface{}{ 95 { 96 "name": appName, 97 "path": dir, 98 }, 99 }, 100 }) 101 session = helpers.CustomCF(helpers.CFEnv{WorkingDirectory: dir}, PushCommandName, appName) 102 Eventually(session).Should(Say("start command:\\s+%s && echo hello", regexp.QuoteMeta(helpers.StaticfileBuildpackStartCommand))) 103 Eventually(session).Should(Exit(0)) 104 105 By("pushing the app with default uses detected command") 106 helpers.WriteManifest(filepath.Join(dir, "manifest.yml"), map[string]interface{}{ 107 "applications": []map[string]interface{}{ 108 { 109 "name": appName, 110 "path": dir, 111 "command": "default", 112 }, 113 }, 114 }) 115 session = helpers.CustomCF(helpers.CFEnv{WorkingDirectory: dir}, PushCommandName, appName) 116 Eventually(session).Should(Say("(?m)start command:\\s+%s", regexp.QuoteMeta(helpers.StaticfileBuildpackStartCommand))) 117 Eventually(session).Should(Exit(0)) 118 119 By("pushing the app with null uses detected command") 120 helpers.WriteManifest(filepath.Join(dir, "manifest.yml"), map[string]interface{}{ 121 "applications": []map[string]interface{}{ 122 { 123 "name": appName, 124 "path": dir, 125 "command": nil, 126 }, 127 }, 128 }) 129 session = helpers.CustomCF(helpers.CFEnv{WorkingDirectory: dir}, PushCommandName, appName) 130 Eventually(session).Should(Say("(?m)start command:\\s+%s", regexp.QuoteMeta(helpers.StaticfileBuildpackStartCommand))) 131 Eventually(session).Should(Exit(0)) 132 }) 133 }) 134 }) 135 })