forked from openshift/origin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
labels.go
134 lines (111 loc) · 4.83 KB
/
labels.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
package builds
import (
"fmt"
g "github.com/onsi/ginkgo"
o "github.com/onsi/gomega"
buildapi "github.com/openshift/origin/pkg/build/api"
eximages "github.com/openshift/origin/test/extended/images"
exutil "github.com/openshift/origin/test/extended/util"
)
var _ = g.Describe("default: Check S2I and Docker build image for proper Docker labels", func() {
defer g.GinkgoRecover()
var (
imageStreamFixture = exutil.FixturePath("..", "integration", "fixtures", "test-image-stream.json")
stiBuildFixture = exutil.FixturePath("fixtures", "test-sti-build.json")
dockerBuildFixture = exutil.FixturePath("fixtures", "test-docker-build.json")
oc = exutil.NewCLI("build-sti-env", exutil.KubeConfigPath())
)
g.Describe("S2I build from a template", func() {
g.It(fmt.Sprintf("should create a image from %q template with proper Docker labels", stiBuildFixture), func() {
oc.SetOutputDir(exutil.TestContext.OutputDir)
g.By(fmt.Sprintf("calling oc create -f %q", imageStreamFixture))
err := oc.Run("create").Args("-f", imageStreamFixture).Execute()
o.Expect(err).NotTo(o.HaveOccurred())
g.By(fmt.Sprintf("calling oc create -f %q", stiBuildFixture))
err = oc.Run("create").Args("-f", stiBuildFixture).Execute()
o.Expect(err).NotTo(o.HaveOccurred())
g.By("starting a test build")
buildName, err := oc.Run("start-build").Args("test").Output()
o.Expect(err).NotTo(o.HaveOccurred())
g.By("o.Expecting the S2I build is in Complete phase")
err = exutil.WaitForABuild(oc.REST().Builds(oc.Namespace()), buildName,
// The build passed
func(b *buildapi.Build) bool {
return b.Name == buildName && b.Status.Phase == buildapi.BuildPhaseComplete
},
// The build failed
func(b *buildapi.Build) bool {
if b.Name != buildName {
return false
}
return b.Status.Phase == buildapi.BuildPhaseFailed || b.Status.Phase == buildapi.BuildPhaseError
},
)
o.Expect(err).NotTo(o.HaveOccurred())
g.By("getting the Docker image reference from ImageStream")
imageRef, err := exutil.GetDockerImageReference(oc.REST().ImageStreams(oc.Namespace()), "test", "latest")
o.Expect(err).NotTo(o.HaveOccurred())
imageLabels, err := eximages.GetImageLabels(oc.REST().ImageStreamImages(oc.Namespace()), "test", imageRef)
o.Expect(err).NotTo(o.HaveOccurred())
g.By("inspecting the new image for proper Docker labels")
err = ExpectOpenShiftLabels(imageLabels)
o.Expect(err).NotTo(o.HaveOccurred())
})
})
g.Describe("Docker build from a template", func() {
g.It(fmt.Sprintf("should create a image from %q template with proper Docker labels", dockerBuildFixture), func() {
oc.SetOutputDir(exutil.TestContext.OutputDir)
g.By(fmt.Sprintf("calling oc create -f %q", imageStreamFixture))
err := oc.Run("create").Args("-f", imageStreamFixture).Execute()
o.Expect(err).NotTo(o.HaveOccurred())
g.By(fmt.Sprintf("calling oc create -f %q", dockerBuildFixture))
err = oc.Run("create").Args("-f", dockerBuildFixture).Execute()
o.Expect(err).NotTo(o.HaveOccurred())
g.By("starting a test build")
buildName, err := oc.Run("start-build").Args("test").Output()
o.Expect(err).NotTo(o.HaveOccurred())
g.By("o.Expecting the Docker build is in Complete phase")
err = exutil.WaitForABuild(oc.REST().Builds(oc.Namespace()), buildName,
// The build passed
func(b *buildapi.Build) bool {
return b.Name == buildName && b.Status.Phase == buildapi.BuildPhaseComplete
},
// The build failed
func(b *buildapi.Build) bool {
if b.Name != buildName {
return false
}
return b.Status.Phase == buildapi.BuildPhaseFailed || b.Status.Phase == buildapi.BuildPhaseError
},
)
o.Expect(err).NotTo(o.HaveOccurred())
g.By("getting the Docker image reference from ImageStream")
imageRef, err := exutil.GetDockerImageReference(oc.REST().ImageStreams(oc.Namespace()), "test", "latest")
o.Expect(err).NotTo(o.HaveOccurred())
imageLabels, err := eximages.GetImageLabels(oc.REST().ImageStreamImages(oc.Namespace()), "test", imageRef)
o.Expect(err).NotTo(o.HaveOccurred())
g.By("inspecting the new image for proper Docker labels")
err = ExpectOpenShiftLabels(imageLabels)
o.Expect(err).NotTo(o.HaveOccurred())
})
})
})
// ExpectOpenShiftLabels tests if builded Docker image contains appropriate
// labels.
func ExpectOpenShiftLabels(labels map[string]string) error {
ExpectedLabels := []string{
"io.openshift.build.commit.author",
"io.openshift.build.commit.date",
"io.openshift.build.commit.id",
"io.openshift.build.commit.ref",
"io.openshift.build.commit.message",
"io.openshift.build.source-location",
"io.openshift.build.source-context-dir",
}
for _, label := range ExpectedLabels {
if labels[label] == "" {
return fmt.Errorf("Builded image doesn't contain proper Docker image labels. Missing %q label", label)
}
}
return nil
}