Skip to content

Commit

Permalink
add unit test to check if default image tags for k8s control plane co…
Browse files Browse the repository at this point in the history
…mponents are in sync
  • Loading branch information
hidalgopl committed Aug 7, 2024
1 parent b6b52f2 commit afdb933
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
22 changes: 22 additions & 0 deletions config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package config

import (
_ "embed"
"fmt"
"os"
"strings"
"testing"

Expand Down Expand Up @@ -378,3 +380,23 @@ func TestConfig_IsProFeatureEnabled(t *testing.T) {
})
}
}

func TestIfDefaultImagesVersionsAreInSync(t *testing.T) {
defaultConfig, err := NewDefaultConfig()
assert.NilError(t, err)
initContainersTplFilePath := os.Getenv("REPO_ROOT_DIR") + "/chart/templates/_init-containers.tpl"
tplBytes, err := os.ReadFile(initContainersTplFilePath)

assert.NilError(t, err)
assert.Equal(t, defaultConfig.ControlPlane.Distro.K8S.ControllerManager.Image.Tag, defaultConfig.ControlPlane.Distro.K8S.APIServer.Image.Tag)
assert.Equal(t, defaultConfig.ControlPlane.Distro.K8S.ControllerManager.Image.Tag, defaultConfig.ControlPlane.Distro.K8S.Scheduler.Image.Tag)
assert.Equal(t, defaultConfig.ControlPlane.Distro.K8S.APIServer.Image.Tag, defaultConfig.ControlPlane.Distro.K8S.Scheduler.Image.Tag)
expectedDefaultTag := fmt.Sprintf("{{- $defaultTag := \"%s\" -}}", defaultConfig.ControlPlane.Distro.K8S.ControllerManager.Image.Tag)
got := strings.Count(string(tplBytes), expectedDefaultTag)
assert.Equal(
t, got, 3,
fmt.Sprintf("please update $defaultTag in %s so it's equal to the "+
".Values.controlPlane.distro.k8s.controllerManager.image.tag",
initContainersTplFilePath),
)
}
6 changes: 3 additions & 3 deletions hack/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ export GOFLAGS=-mod=vendor
# Test if we can build the program
echo "Building virtual cluster..."
go generate ./... && CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build cmd/vcluster/main.go || exit 1

# List packages
PKGS=$(go list ./... | grep -v -e /vendor/ -e /test)

REPO_ROOT_DIR=$(git rev-parse --show-toplevel)
echo "Start testing..."
fail=false
for pkg in $PKGS; do
go test -race -coverprofile=profile.out -covermode=atomic $pkg
env REPO_ROOT_DIR="${REPO_ROOT_DIR}" go test -race -coverprofile=profile.out -covermode=atomic $pkg
if [ $? -ne 0 ]; then
fail=true
fi
Expand Down

0 comments on commit afdb933

Please sign in to comment.