forked from convox/rack
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrelease_test.go
84 lines (68 loc) · 1.85 KB
/
release_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
package models
import (
"fmt"
"io/ioutil"
"os"
"strings"
"testing"
"github.com/aryann/difflib"
"github.com/convox/rack/test"
"github.com/stretchr/testify/require"
)
func Diff(t *testing.T, name, s1, s2 string) {
diff1 := strings.Split(strings.TrimSpace(s1), "\n")
diff2 := strings.Split(strings.TrimSpace(s2), "\n")
diff := difflib.Diff(diff1, diff2)
diffs := []string{}
// bigger than max
prev := 1000000
for l, d := range diff {
switch d.Delta {
case difflib.LeftOnly:
if (l - prev) > 1 {
diffs = append(diffs, "")
}
diffs = append(diffs, fmt.Sprintf("%04d - %s", l, d.Payload))
prev = l
case difflib.RightOnly:
if (l - prev) > 1 {
diffs = append(diffs, "")
}
diffs = append(diffs, fmt.Sprintf("%04d + %s", l, d.Payload))
prev = l
}
}
if len(diffs) > 0 {
t.Errorf("Unexpected results for %s:\n%s", name, strings.Join(diffs, "\n"))
}
}
func TestLinks(t *testing.T) {
t.Skip("skipping until we have a strategy for stubbing out the registry dependency")
os.Setenv("RACK", "convox-test")
os.Setenv("CLUSTER", "convox-test")
resp, err := ioutil.ReadFile("fixtures/get-app-template-response.xml")
require.NoError(t, err)
fixData, err := ioutil.ReadFile("fixtures/web_redis.json")
require.NoError(t, err)
yamlData, err := ioutil.ReadFile("fixtures/web_redis.yml")
require.NoError(t, err)
getAppTemplateCycle := test.GetAppTemplateCycle("web")
getAppTemplateCycle.Response.Body = string(resp)
stubAws := test.StubAws(
getAppTemplateCycle,
test.DescribeAppStackCycle("web"),
)
defer stubAws.Close()
release := &Release{
Id: "DEADBEEF",
App: "web",
Build: "DEADBEEF",
Env: "",
Manifest: string(yamlData),
}
ManifestRandomPorts = false
formation, err := release.Formation()
require.NoError(t, err)
ManifestRandomPorts = true
Diff(t, "web_redis", string(fixData), formation)
}