forked from buildpacks/lifecycle
-
Notifications
You must be signed in to change notification settings - Fork 0
/
metadata_test.go
75 lines (63 loc) · 1.85 KB
/
metadata_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
package lifecycle_test
import (
"testing"
"github.com/sclevine/spec"
"github.com/buildpacks/lifecycle"
h "github.com/buildpacks/lifecycle/testhelpers"
)
func TestStackMetadata(t *testing.T) {
spec.Run(t, "Test StackMetadata", testMetadata)
}
func testMetadata(t *testing.T, when spec.G, it spec.S) {
when("BestRunImageMirror", func() {
var stackMD *lifecycle.StackMetadata
it.Before(func() {
stackMD = &lifecycle.StackMetadata{RunImage: lifecycle.StackRunImageMetadata{
Image: "first.com/org/repo",
Mirrors: []string{
"myorg/myrepo",
"zonal.gcr.io/org/repo",
"gcr.io/org/repo",
},
}}
})
when("repoName is dockerhub", func() {
it("returns the dockerhub image", func() {
name, err := stackMD.BestRunImageMirror("index.docker.io")
h.AssertNil(t, err)
h.AssertEq(t, name, "myorg/myrepo")
})
})
when("registry is gcr.io", func() {
it("returns the gcr.io image", func() {
name, err := stackMD.BestRunImageMirror("gcr.io")
h.AssertNil(t, err)
h.AssertEq(t, name, "gcr.io/org/repo")
})
when("registry is zonal.gcr.io", func() {
it("returns the gcr image", func() {
name, err := stackMD.BestRunImageMirror("zonal.gcr.io")
h.AssertNil(t, err)
h.AssertEq(t, name, "zonal.gcr.io/org/repo")
})
})
when("registry is missingzone.gcr.io", func() {
it("returns the run image", func() {
name, err := stackMD.BestRunImageMirror("missingzone.gcr.io")
h.AssertNil(t, err)
h.AssertEq(t, name, "first.com/org/repo")
})
})
})
when("one of the images is non-parsable", func() {
it.Before(func() {
stackMD.RunImage.Mirrors = []string{"as@ohd@as@op", "gcr.io/myorg/myrepo"}
})
it("skips over it", func() {
name, err := stackMD.BestRunImageMirror("gcr.io")
h.AssertNil(t, err)
h.AssertEq(t, name, "gcr.io/myorg/myrepo")
})
})
})
}