github.com/arunkumar7540/cli@v6.45.0+incompatible/integration/v7/push/manifest_with_path_test.go (about)

     1  package push
     2  
     3  import (
     4  	"io/ioutil"
     5  	"os"
     6  	"path/filepath"
     7  	"runtime"
     8  
     9  	"code.cloudfoundry.org/cli/integration/helpers"
    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 manifest with a path", func() {
    17  	var (
    18  		appName string
    19  
    20  		secondName string
    21  		tempDir    string
    22  	)
    23  
    24  	BeforeEach(func() {
    25  		appName = helpers.NewAppName()
    26  		secondName = helpers.NewAppName()
    27  		var err error
    28  		tempDir, err = ioutil.TempDir("", "simple-manifest-test")
    29  		Expect(err).ToNot(HaveOccurred())
    30  	})
    31  
    32  	AfterEach(func() {
    33  		Expect(os.RemoveAll(tempDir)).ToNot(HaveOccurred())
    34  	})
    35  
    36  	It("pushes the apps using the relative path to the manifest specified", func() {
    37  		helpers.WithHelloWorldApp(func(dir string) {
    38  			nestedDir := filepath.Join(dir, "nested")
    39  			err := os.Mkdir(nestedDir, os.FileMode(0777))
    40  			if err != nil {
    41  				Expect(err).NotTo(HaveOccurred())
    42  			}
    43  			manifestPath := filepath.Join(nestedDir, "manifest.yml")
    44  			helpers.WriteManifest(manifestPath, map[string]interface{}{
    45  				"applications": []map[string]interface{}{
    46  					{
    47  						"name": appName,
    48  						"path": "..",
    49  					},
    50  					{
    51  						"name": secondName,
    52  						"path": dir,
    53  					},
    54  				},
    55  			})
    56  			session := helpers.CustomCF(
    57  				helpers.CFEnv{
    58  					EnvVars: map[string]string{"CF_LOG_LEVEL": "debug"},
    59  				},
    60  				PushCommandName,
    61  				appName,
    62  				"-f", manifestPath,
    63  			)
    64  
    65  			if runtime.GOOS == "windows" {
    66  				// The paths in windows logging have extra escaping that is difficult
    67  				// to match. Instead match on uploading the right number of files.
    68  				Eventually(session.Err).Should(Say("zipped_file_count=3"))
    69  			} else {
    70  				Eventually(session.Err).Should(helpers.SayPath(`msg="creating archive"\s+Path="?%s"?`, dir))
    71  			}
    72  			Eventually(session).Should(Exit(0))
    73  		})
    74  	})
    75  
    76  	When("a single path is not valid", func() {
    77  		It("errors", func() {
    78  			manifestPath := filepath.Join(tempDir, "manifest.yml")
    79  			helpers.WriteManifest(manifestPath, map[string]interface{}{
    80  				"applications": []map[string]interface{}{
    81  					{
    82  						"name": appName,
    83  						"path": "/I/am/a/potato",
    84  					},
    85  					{
    86  						"name": secondName,
    87  						"path": "/baboaboaboaobao/foo",
    88  					},
    89  				},
    90  			})
    91  			session := helpers.CF(PushCommandName, appName, "-f", manifestPath)
    92  			Eventually(session.Err).Should(Say("File not found locally, make sure the file exists at given path /I/am/a/potato"))
    93  			Eventually(session).Should(Exit(1))
    94  		})
    95  	})
    96  })