forked from openshift/origin
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuild.go
67 lines (57 loc) · 1.66 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
66
67
package test
import (
buildv1 "github.com/openshift/api/build/v1"
)
type TestBuild buildv1.Build
func Build() *TestBuild {
b := (*TestBuild)(&buildv1.Build{})
b.Kind = "Build"
b.APIVersion = "build.openshift.io/v1"
b.Name = "TestBuild"
b.WithDockerStrategy()
b.Spec.Source.Git = &buildv1.GitBuildSource{
URI: "http://test.build/source",
}
b.Spec.TriggeredBy = []buildv1.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 = &buildv1.DockerBuildStrategy{}
return b
}
func (b *TestBuild) WithSourceStrategy() *TestBuild {
b.clearStrategy()
strategy := &buildv1.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 := &buildv1.CustomBuildStrategy{}
strategy.From.Name = "builder/image"
strategy.From.Kind = "DockerImage"
b.Spec.Strategy.CustomStrategy = strategy
return b
}
func (b *TestBuild) WithImageLabels(labels []buildv1.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() *buildv1.Build {
return (*buildv1.Build)(b)
}