@@ -16,6 +16,9 @@ package controllers
1616
1717import (
1818 "context"
19+ "os"
20+ "path/filepath"
21+ "strings"
1922 "testing"
2023
2124 v1 "k8s.io/api/core/v1"
@@ -26,7 +29,10 @@ func TestUpgrade(test *testing.T) {
2629 initimage := "intel/intel-idxd-config-initcontainer"
2730 version := ":" + ImageMinVersion .String ()
2831 prevVersion := ":" + ImageMinVersion .WithMinor (ImageMinVersion .Minor ()- 1 ).String ()
32+ sha256 := "updatedrandomsha25642f7ad000a58eecc24ee7b75825227dfe28f23f556f62"
33+ preSha256 := "randomsha25642f7ad000a58eecc24ee7b75825227dfe28f23f556f62ec10f55"
2934 tests := []struct {
35+ envVars map [string ]string
3036 image string
3137 initimage string
3238 expectedImage string
@@ -61,11 +67,24 @@ func TestUpgrade(test *testing.T) {
6167 expectedInitimage : initimage ,
6268 upgrade : false ,
6369 },
70+ {
71+ envVars : map [string ]string {strings .ReplaceAll (strings .ToUpper (filepath .Base (image )), "-" , "_" ) + "_SHA" : image + "@sha256:" + sha256 ,
72+ strings .ReplaceAll (strings .ToUpper (filepath .Base (initimage )), "-" , "_" ) + "_SHA" : initimage + "@sha256:" + sha256 },
73+ image : image + "@sha256:" + preSha256 ,
74+ expectedImage : image + "@sha256:" + sha256 ,
75+ initimage : initimage + "@sha256:" + preSha256 ,
76+ expectedInitimage : initimage + "@sha256:" + sha256 ,
77+ upgrade : true ,
78+ },
6479 }
6580
6681 for i := range tests {
6782 t := tests [i ]
6883
84+ for key , value := range t .envVars {
85+ os .Setenv (key , value )
86+ }
87+
6988 upgrade := UpgradeImages (context .Background (), & t .image , & t .initimage )
7089
7190 if ! (upgrade == t .upgrade && t .image == t .expectedImage && t .initimage == t .expectedInitimage ) {
0 commit comments