@@ -21,6 +21,24 @@ const (
21
21
mcoImagePullspec = "registry.hostname.com/org/repo@sha256:87980e0edfc86d01182f70c53527f74b5b01df00fe6d47668763d228d4de43a9"
22
22
)
23
23
24
+ // Validates that if an invalid extension is provided that the ConfigMap
25
+ // generation fails and the error contains the names of the invalid extensions.
26
+ func TestBuildRequestInvalidExtensions (t * testing.T ) {
27
+ t .Parallel ()
28
+
29
+ opts := getBuildRequestOpts ()
30
+ opts .MachineConfig .Spec .Extensions = []string {"invalid-ext1" , "invalid-ext2" }
31
+
32
+ br := newBuildRequest (opts )
33
+
34
+ _ , err := br .ConfigMaps ()
35
+ assert .Error (t , err )
36
+
37
+ for _ , ext := range opts .MachineConfig .Spec .Extensions {
38
+ assert .Contains (t , err .Error (), ext )
39
+ }
40
+ }
41
+
24
42
// Tests that the BuildRequest is constructed as expected.
25
43
func TestBuildRequest (t * testing.T ) {
26
44
t .Parallel ()
@@ -42,21 +60,40 @@ func TestBuildRequest(t *testing.T) {
42
60
unexpectedContainerfileContents []string
43
61
}{
44
62
{
45
- name : "With extensions image" ,
46
- optsFunc : getBuildRequestOpts ,
63
+ name : "With extensions image and extensions" ,
64
+ optsFunc : func () BuildRequestOpts {
65
+ opts := getBuildRequestOpts ()
66
+ opts .MachineConfig .Spec .Extensions = []string {"usbguard" }
67
+ return opts
68
+ },
69
+ expectedContainerfileContents : append (expectedContents (), []string {
70
+ fmt .Sprintf ("RUN --mount=type=bind,from=%s" , osImageURLConfig .BaseOSExtensionsContainerImage ),
71
+ `extensions="usbguard"` ,
72
+ }... ),
73
+ },
74
+ {
75
+ name : "With extensions image and resolved extensions packages" ,
76
+ optsFunc : func () BuildRequestOpts {
77
+ opts := getBuildRequestOpts ()
78
+ opts .MachineConfig .Spec .Extensions = []string {"kerberos" , "usbguard" }
79
+ return opts
80
+ },
47
81
expectedContainerfileContents : append (expectedContents (), []string {
48
- fmt .Sprintf ("FROM %s AS extensions" , osImageURLConfig .BaseOSExtensionsContainerImage ),
82
+ fmt .Sprintf ("RUN --mount=type=bind,from=%s" , osImageURLConfig .BaseOSExtensionsContainerImage ),
83
+ `extensions="krb5-workstation libkadm5 usbguard"` ,
49
84
}... ),
50
85
},
51
86
{
52
- name : "Missing extensions image" ,
87
+ name : "Missing extensions image and extensions " ,
53
88
optsFunc : func () BuildRequestOpts {
54
89
opts := getBuildRequestOpts ()
55
90
opts .OSImageURLConfig .BaseOSExtensionsContainerImage = ""
91
+ opts .MachineConfig .Spec .Extensions = []string {"usbguard" }
56
92
return opts
57
93
},
58
94
unexpectedContainerfileContents : []string {
59
- fmt .Sprintf ("FROM %s AS extensions" , osImageURLConfig .BaseOSContainerImage ),
95
+ fmt .Sprintf ("RUN --mount=type=bind,from=%s" , osImageURLConfig .BaseOSContainerImage ),
96
+ "extensions=\" usbguard\" " ,
60
97
},
61
98
},
62
99
{
@@ -100,12 +137,14 @@ func TestBuildRequest(t *testing.T) {
100
137
opts .MachineOSConfig .Spec .BuildInputs .BaseOSImagePullspec = "base-os-image-from-machineosconfig"
101
138
opts .MachineOSConfig .Spec .BuildInputs .BaseOSExtensionsImagePullspec = "base-ext-image-from-machineosconfig"
102
139
opts .MachineOSConfig .Spec .BuildInputs .ReleaseVersion = "release-version-from-machineosconfig"
140
+ opts .MachineConfig .Spec .Extensions = []string {"usbguard" }
103
141
return opts
104
142
},
105
143
expectedContainerfileContents : []string {
106
144
"FROM base-os-image-from-machineosconfig AS extract" ,
107
145
"FROM base-os-image-from-machineosconfig AS configs" ,
108
- "FROM base-ext-image-from-machineosconfig AS extensions" ,
146
+ "RUN --mount=type=bind,from=base-ext-image-from-machineosconfig" ,
147
+ "extensions=\" usbguard\" " ,
109
148
"LABEL releaseversion=release-version-from-machineosconfig" ,
110
149
},
111
150
unexpectedContainerfileContents : expectedContents (),
0 commit comments