forked from whalebrew/whalebrew
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main_test.go
54 lines (48 loc) · 1.48 KB
/
main_test.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
package main
import (
"bytes"
"os"
"os/exec"
"strings"
"testing"
"github.com/stretchr/testify/assert"
"github.com/whalebrew/whalebrew/packages"
)
func TestRun(t *testing.T) {
defer os.RemoveAll(".whalebrew-tests")
os.Setenv("RUN_WHALEBREW", "true")
os.Setenv("WHALEBREW_INSTALL_PATH", ".whalebrew-tests")
assert.NoError(t, os.MkdirAll(".whalebrew-tests", 0777))
if err := exec.Command("docker", "pull", "alpine").Run(); err != nil {
t.Skipf("Unable to pull alpine image: %v, this test needs a running docker daemon", err)
return
}
c := exec.Command(os.Args[0], "install", "-y", "-f", "whalebrew/awscli")
c.Stdout = os.Stdout
c.Stderr = os.Stderr
assert.NoError(t, c.Run())
assert.NoError(t, packages.NewPackageManager(".whalebrew-tests").ForceInstall(&packages.Package{
Image: "alpine",
Name: "alpine",
Entrypoint: []string{"sh", "-c"},
}))
wd, err := os.Getwd()
assert.NoError(t, err)
// running in whalebrew performs an exec, we need to fork to be able
// to execute the rest of the tests
assert.NoError(t, exec.Command("docker", "pull", "alpine").Run())
c = exec.Command(os.Args[0], wd+"/.whalebrew-tests/alpine", "pwd;ls -al .")
stdout := bytes.NewBuffer(nil)
c.Stdout = stdout
c.Stderr = os.Stderr
assert.NoError(t, c.Run())
assert.Contains(t, stdout.String(), "main.go")
assert.True(t, strings.HasPrefix(stdout.String(), "/workdir"))
}
func TestMain(m *testing.M) {
if os.Getenv("RUN_WHALEBREW") == "true" {
main()
os.Exit(0)
}
os.Exit(m.Run())
}