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 <hyeongju.lee@intel.com>
  • Loading branch information
hj-johannes-lee committed Oct 5, 2024
1 parent 05ed072 commit f3cd567
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion 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,6 +29,8 @@ 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 {
image string
initimage string
Expand Down Expand Up @@ -61,11 +66,19 @@ func TestUpgrade(test *testing.T) {
expectedInitimage: initimage,
upgrade: false,
},
{
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]

os.Setenv(strings.ReplaceAll(strings.ToUpper(filepath.Base(t.image)), "-", "_")+"_SHA", t.image+"@sha256:"+sha256)
os.Setenv(strings.ReplaceAll(strings.ToUpper(filepath.Base(t.initimage)), "-", "_")+"_SHA", t.initimage+"@sha256:"+sha256)
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 f3cd567

Please sign in to comment.