@@ -27,15 +27,60 @@ import (
27
27
)
28
28
29
29
func TestKanikoBuildSpec (t * testing.T ) {
30
- artifact := & latest.Artifact {
31
- ArtifactType : latest.ArtifactType {
32
- KanikoArtifact : & latest.KanikoArtifact {
30
+ tests := []struct {
31
+ description string
32
+ artifact * latest.KanikoArtifact
33
+ expectedArgs []string
34
+ }{
35
+ {
36
+ description : "simple build" ,
37
+ artifact : & latest.KanikoArtifact {
38
+ DockerfilePath : "Dockerfile" ,
39
+ },
40
+ expectedArgs : []string {},
41
+ },
42
+ {
43
+ description : "with BuildArgs" ,
44
+ artifact : & latest.KanikoArtifact {
33
45
DockerfilePath : "Dockerfile" ,
34
46
BuildArgs : map [string ]* string {
35
47
"arg1" : util .StringPtr ("value1" ),
36
48
"arg2" : nil ,
37
49
},
38
- Cache : & latest.KanikoCache {},
50
+ },
51
+ expectedArgs : []string {
52
+ "--build-arg" , "arg1=value1" ,
53
+ "--build-arg" , "arg2" ,
54
+ },
55
+ },
56
+ {
57
+ description : "with cache layer" ,
58
+ artifact : & latest.KanikoArtifact {
59
+ DockerfilePath : "Dockerfile" ,
60
+ Cache : & latest.KanikoCache {},
61
+ },
62
+ expectedArgs : []string {
63
+ "--cache" ,
64
+ },
65
+ },
66
+ {
67
+ description : "with reproduceible" ,
68
+ artifact : & latest.KanikoArtifact {
69
+ DockerfilePath : "Dockerfile" ,
70
+ Reproducible : true ,
71
+ },
72
+ expectedArgs : []string {
73
+ "--reproducible" ,
74
+ },
75
+ },
76
+ {
77
+ description : "with target" ,
78
+ artifact : & latest.KanikoArtifact {
79
+ DockerfilePath : "Dockerfile" ,
80
+ Target : "builder" ,
81
+ },
82
+ expectedArgs : []string {
83
+ "--target" , "builder" ,
39
84
},
40
85
},
41
86
}
@@ -46,32 +91,42 @@ func TestKanikoBuildSpec(t *testing.T) {
46
91
MachineType : "n1-standard-1" ,
47
92
Timeout : "10m" ,
48
93
})
49
- desc , err := builder .buildSpec (artifact , "nginx" , "bucket" , "object" )
50
94
51
- expected := cloudbuild.Build {
52
- LogsBucket : "bucket" ,
53
- Source : & cloudbuild.Source {
54
- StorageSource : & cloudbuild.StorageSource {
55
- Bucket : "bucket" ,
56
- Object : "object" ,
57
- },
58
- },
59
- Steps : []* cloudbuild.BuildStep {{
60
- Name : "gcr.io/kaniko-project/executor" ,
61
- Args : []string {
62
- "--destination" , "nginx" ,
63
- "--dockerfile" , "Dockerfile" ,
64
- "--build-arg" , "arg1=value1" ,
65
- "--build-arg" , "arg2" ,
66
- "--cache" ,
67
- },
68
- }},
69
- Options : & cloudbuild.BuildOptions {
70
- DiskSizeGb : 100 ,
71
- MachineType : "n1-standard-1" ,
72
- },
73
- Timeout : "10m" ,
95
+ defaultExpectedArgs := []string {
96
+ "--destination" , "nginx" ,
97
+ "--dockerfile" , "Dockerfile" ,
74
98
}
75
99
76
- testutil .CheckErrorAndDeepEqual (t , false , err , expected , desc )
100
+ for _ , test := range tests {
101
+ testutil .Run (t , test .description , func (t * testutil.T ) {
102
+ artifact := & latest.Artifact {
103
+ ArtifactType : latest.ArtifactType {
104
+ KanikoArtifact : test .artifact ,
105
+ },
106
+ }
107
+
108
+ desc , err := builder .buildSpec (artifact , "nginx" , "bucket" , "object" )
109
+
110
+ expected := cloudbuild.Build {
111
+ LogsBucket : "bucket" ,
112
+ Source : & cloudbuild.Source {
113
+ StorageSource : & cloudbuild.StorageSource {
114
+ Bucket : "bucket" ,
115
+ Object : "object" ,
116
+ },
117
+ },
118
+ Steps : []* cloudbuild.BuildStep {{
119
+ Name : "gcr.io/kaniko-project/executor" ,
120
+ Args : append (defaultExpectedArgs , test .expectedArgs ... ),
121
+ }},
122
+ Options : & cloudbuild.BuildOptions {
123
+ DiskSizeGb : 100 ,
124
+ MachineType : "n1-standard-1" ,
125
+ },
126
+ Timeout : "10m" ,
127
+ }
128
+
129
+ t .CheckErrorAndDeepEqual (false , err , expected , desc )
130
+ })
131
+ }
77
132
}
0 commit comments