github.com/sleungcy-sap/cli@v7.1.0+incompatible/integration/v7/push/manifest_location_test.go (about)

     1  package push
     2  
     3  import (
     4  	"os"
     5  	"path/filepath"
     6  
     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("reading of the manifest based on location", func() {
    15  	var (
    16  		appName string
    17  	)
    18  
    19  	BeforeEach(func() {
    20  		appName = helpers.PrefixedRandomName("app")
    21  	})
    22  
    23  	When("the manifest exists in the current directory", func() {
    24  		When("the manifest has a .yml extension", func() {
    25  			It("detects manifests with a .yml suffix", func() {
    26  				helpers.WithHelloWorldApp(func(dir string) {
    27  					pathToManifest := filepath.Join(dir, "manifest.yml")
    28  					helpers.WriteManifest(pathToManifest, map[string]interface{}{
    29  						"applications": []map[string]interface{}{
    30  							{
    31  								"name": appName,
    32  							},
    33  						},
    34  					})
    35  					session := helpers.CustomCF(helpers.CFEnv{WorkingDirectory: dir}, PushCommandName, "--no-start")
    36  					Eventually(session).Should(Say("name:\\s+%s", appName))
    37  					Eventually(session).Should(Exit(0))
    38  				})
    39  			})
    40  		})
    41  
    42  		When("the manifest has a .yaml extension", func() {
    43  			It("detects manifests with a .yaml suffix", func() {
    44  				helpers.WithHelloWorldApp(func(dir string) {
    45  					pathToManifest := filepath.Join(dir, "manifest.yaml")
    46  					helpers.WriteManifest(pathToManifest, map[string]interface{}{
    47  						"applications": []map[string]interface{}{
    48  							{
    49  								"name": appName,
    50  							},
    51  						},
    52  					})
    53  					session := helpers.CustomCF(helpers.CFEnv{WorkingDirectory: dir}, PushCommandName, "--no-start")
    54  					Eventually(session).Should(Say("name:\\s+%s", appName))
    55  					Eventually(session).Should(Exit(0))
    56  				})
    57  			})
    58  		})
    59  	})
    60  
    61  	When("the path to the manifest is specified", func() {
    62  		var workingDir string
    63  
    64  		BeforeEach(func() {
    65  			workingDir = helpers.TempDirAbsolutePath("", "manifest-working-dir")
    66  		})
    67  
    68  		AfterEach(func() {
    69  			Expect(os.RemoveAll(workingDir)).ToNot(HaveOccurred())
    70  		})
    71  
    72  		When("the manifest has a .yml extension", func() {
    73  			BeforeEach(func() {
    74  				pathToManifest := filepath.Join(workingDir, "manifest.yml")
    75  				helpers.WriteManifest(pathToManifest, map[string]interface{}{
    76  					"applications": []map[string]interface{}{
    77  						{
    78  							"name": appName,
    79  						},
    80  					},
    81  				})
    82  			})
    83  
    84  			It("detects manifests with a .yml suffix", func() {
    85  				helpers.WithHelloWorldApp(func(dir string) {
    86  					session := helpers.CustomCF(helpers.CFEnv{WorkingDirectory: dir}, PushCommandName, "-f", workingDir, "--no-start")
    87  					Eventually(session).Should(Say("name:\\s+%s", appName))
    88  					Eventually(session).Should(Exit(0))
    89  				})
    90  			})
    91  		})
    92  
    93  		When("the manifest has a .yaml extension", func() {
    94  			BeforeEach(func() {
    95  				pathToManifest := filepath.Join(workingDir, "manifest.yaml")
    96  				helpers.WriteManifest(pathToManifest, map[string]interface{}{
    97  					"applications": []map[string]interface{}{
    98  						{
    99  							"name": appName,
   100  						},
   101  					},
   102  				})
   103  			})
   104  
   105  			It("detects manifests with a .yaml suffix", func() {
   106  				helpers.WithHelloWorldApp(func(dir string) {
   107  					session := helpers.CustomCF(helpers.CFEnv{WorkingDirectory: dir}, PushCommandName, "-f", workingDir, "--no-start")
   108  					Eventually(session).Should(Say("name:\\s+%s", appName))
   109  					Eventually(session).Should(Exit(0))
   110  				})
   111  			})
   112  		})
   113  
   114  		When("the path to the manifest is a directory", func() {
   115  			When("there's no manifest in that directory", func() {
   116  				It("should give a helpful error", func() {
   117  					session := helpers.CustomCF(helpers.CFEnv{WorkingDirectory: workingDir}, PushCommandName, "-f", workingDir, "--no-start")
   118  					Eventually(session.Err).Should(helpers.SayPath("Incorrect Usage: The specified directory '%s' does not contain a file named 'manifest.yml'.", workingDir))
   119  					Eventually(session).Should(Exit(1))
   120  				})
   121  			})
   122  		})
   123  	})
   124  })