Skip to content

Commit

Permalink
operator: add sha256 image upgrade test case in the unit test
Browse files Browse the repository at this point in the history
Signed-off-by: Hyeongju Johannes Lee <[email protected]>
  • Loading branch information
hj-johannes-lee committed Oct 8, 2024
1 parent 05ed072 commit d06711e
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions pkg/controllers/reconciler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ package controllers

import (
"context"
"os"
"path/filepath"
"strings"
"testing"

v1 "k8s.io/api/core/v1"
Expand All @@ -26,7 +29,10 @@ func TestUpgrade(test *testing.T) {
initimage := "intel/intel-idxd-config-initcontainer"
version := ":" + ImageMinVersion.String()
prevVersion := ":" + ImageMinVersion.WithMinor(ImageMinVersion.Minor()-1).String()
sha256 := "updatedrandomsha25642f7ad000a58eecc24ee7b75825227dfe28f23f556f62"
preSha256 := "randomsha25642f7ad000a58eecc24ee7b75825227dfe28f23f556f62ec10f55"
tests := []struct {
envVars map[string]string
image string
initimage string
expectedImage string
Expand Down Expand Up @@ -61,11 +67,24 @@ func TestUpgrade(test *testing.T) {
expectedInitimage: initimage,
upgrade: false,
},
{
envVars: map[string]string{strings.ReplaceAll(strings.ToUpper(filepath.Base(image)), "-", "_") + "_SHA": image + "@sha256:" + sha256,
strings.ReplaceAll(strings.ToUpper(filepath.Base(initimage)), "-", "_") + "_SHA": initimage + "@sha256:" + sha256},
image: image + "@sha256:" + preSha256,
expectedImage: image + "@sha256:" + sha256,
initimage: initimage + "@sha256:" + preSha256,
expectedInitimage: initimage + "@sha256:" + sha256,
upgrade: true,
},
}

for i := range tests {
t := tests[i]

for key, value := range t.envVars {
os.Setenv(key, value)
}

upgrade := UpgradeImages(context.Background(), &t.image, &t.initimage)

if !(upgrade == t.upgrade && t.image == t.expectedImage && t.initimage == t.expectedInitimage) {
Expand Down

0 comments on commit d06711e

Please sign in to comment.