forked from openshift/origin
-
Notifications
You must be signed in to change notification settings - Fork 1
/
build.go
65 lines (55 loc) · 1.62 KB
/
build.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
package test
import (
buildapi "github.com/openshift/origin/pkg/build/api"
)
type TestBuild buildapi.Build
func Build() *TestBuild {
b := (*TestBuild)(&buildapi.Build{})
b.Name = "TestBuild"
b.WithDockerStrategy()
b.Spec.Source.Git = &buildapi.GitBuildSource{
URI: "http://test.build/source",
}
b.Spec.TriggeredBy = []buildapi.BuildTriggerCause{}
return b
}
// clearStrategy nil all strategies in the Spec since it is a
// common pattern to detect strategy by testing for non-nil.
func (b *TestBuild) clearStrategy() {
b.Spec.Strategy.DockerStrategy = nil
b.Spec.Strategy.SourceStrategy = nil
b.Spec.Strategy.CustomStrategy = nil
b.Spec.Strategy.JenkinsPipelineStrategy = nil
}
func (b *TestBuild) WithDockerStrategy() *TestBuild {
b.clearStrategy()
b.Spec.Strategy.DockerStrategy = &buildapi.DockerBuildStrategy{}
return b
}
func (b *TestBuild) WithSourceStrategy() *TestBuild {
b.clearStrategy()
strategy := &buildapi.SourceBuildStrategy{}
strategy.From.Name = "builder/image"
strategy.From.Kind = "DockerImage"
b.Spec.Strategy.SourceStrategy = strategy
return b
}
func (b *TestBuild) WithCustomStrategy() *TestBuild {
b.clearStrategy()
strategy := &buildapi.CustomBuildStrategy{}
strategy.From.Name = "builder/image"
strategy.From.Kind = "DockerImage"
b.Spec.Strategy.CustomStrategy = strategy
return b
}
func (b *TestBuild) WithImageLabels(labels []buildapi.ImageLabel) *TestBuild {
b.Spec.Output.ImageLabels = labels
return b
}
func (b *TestBuild) WithNodeSelector(ns map[string]string) *TestBuild {
b.Spec.NodeSelector = ns
return b
}
func (b *TestBuild) AsBuild() *buildapi.Build {
return (*buildapi.Build)(b)
}