@@ -16,6 +16,7 @@ package controllers
1616
1717import (
1818 "context"
19+ "os"
1920 "testing"
2021
2122 v1 "k8s.io/api/core/v1"
@@ -27,6 +28,7 @@ func TestUpgrade(test *testing.T) {
2728 version := ":" + ImageMinVersion .String ()
2829 prevVersion := ":" + ImageMinVersion .WithMinor (ImageMinVersion .Minor ()- 1 ).String ()
2930 tests := []struct {
31+ envVars map [string ]string
3032 image string
3133 initimage string
3234 expectedImage string
@@ -61,18 +63,48 @@ func TestUpgrade(test *testing.T) {
6163 expectedInitimage : initimage ,
6264 upgrade : false ,
6365 },
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+ },
6488 }
6589
6690 for i := range tests {
6791 t := tests [i ]
6892
93+ for key , value := range t .envVars {
94+ os .Setenv (key , value )
95+ }
96+
6997 upgrade := UpgradeImages (context .Background (), & t .image , & t .initimage )
7098
7199 if ! (upgrade == t .upgrade && t .image == t .expectedImage && t .initimage == t .expectedInitimage ) {
72100 test .Errorf ("expectedUpgrade: %v, received: %v" , t .upgrade , upgrade )
73101 test .Errorf ("expectedImage: %s, received: %s" , t .expectedImage , t .image )
74102 test .Errorf ("expectedInitimage: %s, received: %s" , t .expectedInitimage , t .initimage )
75103 }
104+
105+ for key := range t .envVars {
106+ os .Unsetenv (key )
107+ }
76108 }
77109}
78110
0 commit comments