@@ -16,6 +16,9 @@ package controllers
16
16
17
17
import (
18
18
"context"
19
+ "os"
20
+ "path/filepath"
21
+ "strings"
19
22
"testing"
20
23
21
24
v1 "k8s.io/api/core/v1"
@@ -26,11 +29,14 @@ func TestUpgrade(test *testing.T) {
26
29
initimage := "intel/intel-idxd-config-initcontainer"
27
30
version := ":" + ImageMinVersion .String ()
28
31
prevVersion := ":" + ImageMinVersion .WithMinor (ImageMinVersion .Minor ()- 1 ).String ()
32
+ sha256 := "updatedrandomsha25642f7ad000a58eecc24ee7b75825227dfe28f23f556f62"
33
+ preSha256 := "randomsha25642f7ad000a58eecc24ee7b75825227dfe28f23f556f62ec10f55"
29
34
tests := []struct {
30
35
image string
31
36
initimage string
32
37
expectedImage string
33
38
expectedInitimage string
39
+ envVars map [string ]string
34
40
upgrade bool
35
41
}{
36
42
{
@@ -61,11 +67,24 @@ func TestUpgrade(test *testing.T) {
61
67
expectedInitimage : initimage ,
62
68
upgrade : false ,
63
69
},
70
+ {
71
+ image : image + "@sha256:" + preSha256 ,
72
+ expectedImage : image + "@sha256:" + sha256 ,
73
+ initimage : initimage + "@sha256:" + preSha256 ,
74
+ expectedInitimage : initimage + "@sha256:" + sha256 ,
75
+ upgrade : true ,
76
+ envVars : map [string ]string {strings .ReplaceAll (strings .ToUpper (filepath .Base (image )), "-" , "_" ) + "_SHA" : image + "@sha256:" + sha256 ,
77
+ strings .ReplaceAll (strings .ToUpper (filepath .Base (initimage )), "-" , "_" ) + "_SHA" : initimage + "@sha256:" + sha256 },
78
+ },
64
79
}
65
80
66
81
for i := range tests {
67
82
t := tests [i ]
68
83
84
+ for key , value := range t .envVars {
85
+ os .Setenv (key , value )
86
+ }
87
+
69
88
upgrade := UpgradeImages (context .Background (), & t .image , & t .initimage )
70
89
71
90
if ! (upgrade == t .upgrade && t .image == t .expectedImage && t .initimage == t .expectedInitimage ) {
0 commit comments