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