forked from heroku/cnb-shim
-
Notifications
You must be signed in to change notification settings - Fork 0
/
releaser_test.go
138 lines (114 loc) · 3.48 KB
/
releaser_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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
package cnbshim_test
import (
"io/ioutil"
"os"
"path/filepath"
"testing"
"github.com/buildpack/libbuildpack/logger"
"github.com/BurntSushi/toml"
"github.com/buildpack/libbuildpack/layers"
releaser "github.com/heroku/cnb-shim"
)
func TestReadProcfileWithWebAndWorker(t *testing.T) {
appWithProcfile := filepath.Join("test", "fixtures", "app_with_procfile")
got, err := releaser.ReadProcfile(appWithProcfile)
if err != nil {
t.Error(err.Error())
}
if got["web"] != "node index.js" {
t.Errorf("Expected 'web' process type of 'node index.js'; got %s", got)
}
if got["worker"] != "node worker.js" {
t.Errorf("Expected 'web' process type of 'node worker.js'; got %s", got)
}
}
func TestReadProcfileWithoutProcfile(t *testing.T) {
appWithProcfile := filepath.Join("test", "fixtures", "app_without_procfile")
got, err := releaser.ReadProcfile(appWithProcfile)
if err != nil {
t.Error(err.Error())
}
if len(got) != 0 {
t.Errorf("Expected no process types; got %s", got)
}
}
func TestReadProcfileWithEmptyProcfile(t *testing.T) {
appWithProcfile := filepath.Join("test", "fixtures", "app_with_empty_procfile")
got, err := releaser.ReadProcfile(appWithProcfile)
if err != nil {
t.Error(err.Error())
}
if len(got) != 0 {
t.Errorf("Expected no process types; got %s", got)
}
}
func TestExecReleaseWithoutDefaultProcs(t *testing.T) {
buildpack := filepath.Join("test", "fixtures", "buildpack_without_default_procs")
app := filepath.Join("test", "fixtures", "app_with_empty_procfile")
got, err := releaser.ExecReleaseScript(app, buildpack)
if err != nil {
t.Error(err.Error())
}
if len(got.DefaultProcessTypes) != 0 {
t.Errorf("Expected no process types; got %s", got)
}
}
func TestExecReleaseWithDefaultProcs(t *testing.T) {
buildpack := filepath.Join("test", "fixtures", "buildpack_with_default_procs")
app := filepath.Join("test", "fixtures", "app_with_empty_procfile")
got, err := releaser.ExecReleaseScript(app, buildpack)
if err != nil {
t.Error(err.Error())
}
expected := "java -jar myapp.jar"
if got.DefaultProcessTypes["web"] != expected {
t.Errorf("Expected 'web' process type of '%s'; got %s", expected, got)
}
}
func TestWriteLaunchMetadata(t *testing.T) {
buildpack := filepath.Join("test", "fixtures", "buildpack_with_default_procs")
app := filepath.Join("test", "fixtures", "app_with_procfile")
layersDir, err := ioutil.TempDir("", "layers")
if err != nil {
t.Error(err.Error())
}
log, err := logger.DefaultLogger(os.TempDir())
if err != nil {
t.Error(err.Error())
}
err = releaser.WriteLaunchMetadata(app, layersDir, buildpack, log)
if err != nil {
t.Error(err.Error())
}
l := layers.Metadata{}
_, err = toml.DecodeFile(filepath.Join(layersDir, "launch.toml"), &l)
if err != nil {
t.Error(err.Error())
}
if len(l.Processes) != 2 {
t.Errorf("Expected 2 process type; got %d", len(l.Processes))
}
foundWeb := false
foundWorker := false
for _, p := range l.Processes {
if p.Type == "web" {
foundWeb = true
expected := "node index.js"
if p.Command != expected {
t.Errorf("Expected 'web' process type of '%s'; got %s", expected, p.Command)
}
} else if p.Type == "worker" {
foundWorker = true
expected := "node worker.js"
if p.Command != expected {
t.Errorf("Expected 'worker' process type of '%s'; got %s", expected, p.Command)
}
}
}
if !foundWeb {
t.Errorf("Expected 'web' process type; got %s", l.Processes)
}
if !foundWorker {
t.Errorf("Expected 'worker' process type; got %s", l.Processes)
}
}