@@ -16,6 +16,7 @@ package controllers
16
16
17
17
import (
18
18
"context"
19
+ "os"
19
20
"testing"
20
21
21
22
v1 "k8s.io/api/core/v1"
@@ -27,6 +28,7 @@ func TestUpgrade(test *testing.T) {
27
28
version := ":" + ImageMinVersion .String ()
28
29
prevVersion := ":" + ImageMinVersion .WithMinor (ImageMinVersion .Minor ()- 1 ).String ()
29
30
tests := []struct {
31
+ envVars map [string ]string
30
32
image string
31
33
initimage string
32
34
expectedImage string
@@ -61,18 +63,48 @@ func TestUpgrade(test *testing.T) {
61
63
expectedInitimage : initimage ,
62
64
upgrade : false ,
63
65
},
66
+ {
67
+ envVars : map [string ]string {
68
+ "INTEL_DSA_PLUGIN_SHA" : "intel/intel-dsa-plugin@sha256:000000000000000000000000000000000000000000000000000000000000000b" ,
69
+ "INTEL_IDXD_CONFIG_INITCONTAINER_SHA" : "intel/intel-idxd-config-initcontainer@sha256:000000000000000000000000000000000000000000000000000000000000000b" ,
70
+ },
71
+ image : image + "@sha256:000000000000000000000000000000000000000000000000000000000000000a" ,
72
+ expectedImage : image + "@sha256:000000000000000000000000000000000000000000000000000000000000000b" ,
73
+ initimage : initimage + "@sha256:000000000000000000000000000000000000000000000000000000000000000a" ,
74
+ expectedInitimage : initimage + "@sha256:000000000000000000000000000000000000000000000000000000000000000b" ,
75
+ upgrade : true ,
76
+ },
77
+ {
78
+ envVars : map [string ]string {
79
+ "INTEL_DSA_PLUGIN_SHA" : "intel/intel-dsa-plugin@sha256:000000000000000000000000000000000000000000000000000000000000000a" ,
80
+ "INTEL_IDXD_CONFIG_INITCONTAINER_SHA" : "intel/intel-idxd-config-initcontainer@sha256:000000000000000000000000000000000000000000000000000000000000000a" ,
81
+ },
82
+ image : image + "@sha256:000000000000000000000000000000000000000000000000000000000000000a" ,
83
+ expectedImage : image + "@sha256:000000000000000000000000000000000000000000000000000000000000000a" ,
84
+ initimage : initimage + "@sha256:000000000000000000000000000000000000000000000000000000000000000a" ,
85
+ expectedInitimage : initimage + "@sha256:000000000000000000000000000000000000000000000000000000000000000a" ,
86
+ upgrade : false ,
87
+ },
64
88
}
65
89
66
90
for i := range tests {
67
91
t := tests [i ]
68
92
93
+ for key , value := range t .envVars {
94
+ os .Setenv (key , value )
95
+ }
96
+
69
97
upgrade := UpgradeImages (context .Background (), & t .image , & t .initimage )
70
98
71
99
if ! (upgrade == t .upgrade && t .image == t .expectedImage && t .initimage == t .expectedInitimage ) {
72
100
test .Errorf ("expectedUpgrade: %v, received: %v" , t .upgrade , upgrade )
73
101
test .Errorf ("expectedImage: %s, received: %s" , t .expectedImage , t .image )
74
102
test .Errorf ("expectedInitimage: %s, received: %s" , t .expectedInitimage , t .initimage )
75
103
}
104
+
105
+ for key := range t .envVars {
106
+ os .Unsetenv (key )
107
+ }
76
108
}
77
109
}
78
110
0 commit comments