github.com/dcarley/cf-cli@v6.24.1-0.20170220111324-4225ff346898+incompatible/integration/helpers/app.go (about)

     1  package helpers
     2  
     3  import (
     4  	"io/ioutil"
     5  	"os"
     6  	"path/filepath"
     7  	"strings"
     8  
     9  	. "github.com/onsi/gomega"
    10  	"github.com/onsi/gomega/gexec"
    11  )
    12  
    13  // WithHelloWorldApp creates a simple application to use with your CLI command
    14  // (typically CF Push). When pushing, be aware of specifying '-b
    15  // staticfile_buildpack" so that your app will correctly start up with the
    16  // proper buildpack.
    17  func WithHelloWorldApp(f func(dir string)) {
    18  	dir, err := ioutil.TempDir("", "simple-app")
    19  	Expect(err).ToNot(HaveOccurred())
    20  	defer os.RemoveAll(dir)
    21  
    22  	tempfile := filepath.Join(dir, "index.html")
    23  	err = ioutil.WriteFile(tempfile, []byte("hello world"), 0666)
    24  	Expect(err).ToNot(HaveOccurred())
    25  
    26  	f(dir)
    27  }
    28  
    29  // WithBananaPantsApp creates a simple application to use with your CLI command
    30  // (typically CF Push). When pushing, be aware of specifying '-b
    31  // staticfile_buildpack" so that your app will correctly start up with the
    32  // proper buildpack.
    33  func WithBananaPantsApp(f func(dir string)) {
    34  	dir, err := ioutil.TempDir("", "simple-app")
    35  	Expect(err).ToNot(HaveOccurred())
    36  	defer os.RemoveAll(dir)
    37  
    38  	tempfile := filepath.Join(dir, "index.html")
    39  	err = ioutil.WriteFile(tempfile, []byte("Banana Pants"), 0666)
    40  	Expect(err).ToNot(HaveOccurred())
    41  
    42  	f(dir)
    43  }
    44  
    45  // AppGUID returns the GUID for an app in the currently targeted space.
    46  func AppGUID(appName string) string {
    47  	session := CF("app", appName, "--guid")
    48  	Eventually(session).Should(gexec.Exit(0))
    49  	return strings.TrimSpace(string(session.Out.Contents()))
    50  }