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

     1  // +build !windows
     2  
     3  package push
     4  
     5  import (
     6  	"fmt"
     7  	"io/ioutil"
     8  	"os"
     9  	"os/exec"
    10  	"path/filepath"
    11  
    12  	"code.cloudfoundry.org/cli/integration/helpers"
    13  
    14  	. "github.com/onsi/ginkgo"
    15  	. "github.com/onsi/gomega"
    16  	. "github.com/onsi/gomega/gbytes"
    17  	. "github.com/onsi/gomega/gexec"
    18  )
    19  
    20  var _ = Describe("push with a manifest and vars files via process substitution", func() {
    21  	var (
    22  		appName   string
    23  		instances int
    24  
    25  		tmpDir            string
    26  		firstVarsFilePath string
    27  	)
    28  
    29  	BeforeEach(func() {
    30  		appName = helpers.NewAppName()
    31  		instances = 4
    32  
    33  		var err error
    34  		tmpDir, err = ioutil.TempDir("", "vars-files")
    35  		Expect(err).ToNot(HaveOccurred())
    36  
    37  		firstVarsFilePath = filepath.Join(tmpDir, "vars1")
    38  		vars1 := fmt.Sprintf("vars1: %s", appName)
    39  		err = ioutil.WriteFile(firstVarsFilePath, []byte(vars1), 0666)
    40  		Expect(err).ToNot(HaveOccurred())
    41  	})
    42  
    43  	AfterEach(func() {
    44  		Expect(os.RemoveAll(tmpDir)).ToNot(HaveOccurred())
    45  	})
    46  
    47  	It("pushes the app with the interpolated values in the manifest", func() {
    48  		helpers.WithHelloWorldApp(func(dir string) {
    49  			helpers.WriteManifest(filepath.Join(dir, "manifest.yml"), map[string]interface{}{
    50  				"applications": []map[string]interface{}{
    51  					{
    52  						"name":      "((vars1))",
    53  						"instances": "((vars2))",
    54  						"path":      dir,
    55  					},
    56  				},
    57  			})
    58  
    59  			catFileCmd := fmt.Sprintf("<(cat %s)", firstVarsFilePath)
    60  			command := exec.Command("bash", "-c", fmt.Sprintf("cf %s --vars-file %s --vars-file <(echo vars2: 4)", PushCommandName, catFileCmd))
    61  			command.Dir = dir
    62  			session, err := Start(
    63  				command,
    64  				NewPrefixedWriter(helpers.DebugOutPrefix, GinkgoWriter),
    65  				NewPrefixedWriter(helpers.DebugErrPrefix, GinkgoWriter))
    66  			Expect(err).NotTo(HaveOccurred())
    67  			Eventually(session).Should(Say(`Getting app info\.\.\.`))
    68  			Eventually(session).Should(Say(`Creating app with these attributes\.\.\.`))
    69  			Eventually(session).Should(Say(`\+\s+name:\s+%s`, appName))
    70  			Eventually(session).Should(Say(`\+\s+instances:\s+%d`, instances))
    71  			Eventually(session).Should(Say(`Mapping routes\.\.\.`))
    72  			Eventually(session).Should(Say(`Waiting for app to start\.\.\.`))
    73  			Eventually(session).Should(Say(`requested state:\s+started`))
    74  			Eventually(session).Should(Exit(0))
    75  		})
    76  
    77  		session := helpers.CF("app", appName)
    78  		Eventually(session).Should(Exit(0))
    79  	})
    80  })