Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP]Add new test verifying helm charts versions #729

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions pkg/tests/ossm/operator/version_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package operator

import (
"os/exec"
"strings"
"testing"

"github.com/maistra/maistra-test-tool/pkg/util/env"
"github.com/maistra/maistra-test-tool/pkg/util/pod"
"github.com/maistra/maistra-test-tool/pkg/util/test"
)

const EXPECTED_VERSION = "v2.5" // Replace with the expected version

func TestVersion(t *testing.T) {
test.NewTest(t).Run(func(t test.TestHelper) {
t.Log("Test to verify helm chart version matches expected version")

operatorPod := pod.MatchingSelector("name=istio-operator", env.GetOperatorNamespace())
if operatorPod == nil {
t.Fatalf("Failed to find istio-operator pod in namespace %s", env.GetOperatorNamespace())
}

cmd := exec.Command("kubectl", "exec", "deploy/istio-operator", "-n", env.GetOperatorNamespace(),
"--", "cat", "/usr/local/share/istio-operator/helm/", env.GetSMCPVersion().String(),
"/istio-control/istio-discovery/templates/deployment.yaml", "|", "grep", "maistra-version", "|", "awk", "'{print $2}'")

outputBytes, err := cmd.Output()
if err != nil {
t.Fatalf("Failed to execute command: %v", err)
}

output := strings.TrimSpace(string(outputBytes))

if output != EXPECTED_VERSION {
t.Fatalf("Version mismatch: expected %s, got %s", EXPECTED_VERSION, output)
}

t.Logf("Version matches expected version: %s", EXPECTED_VERSION)
})
}
4 changes: 4 additions & 0 deletions pkg/util/env/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,3 +107,7 @@ func GetOutputDir() string {
func IsMetalLBInternalIPEnabled() bool {
return getenv("METALLB_INTERNAL_IP_ENABLED", "false") == "true"
}

func GetExpectedVersion() string {
return getenv("EXPECTED_VERSION", "")
}
11 changes: 11 additions & 0 deletions scripts/runtests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,17 @@ runTestsAgainstVersion() {
echo "ERROR: must specify version in SMCP_VERSION env var"
exit 1
fi

unset EXPECTED_VERSION

if [ -n "$EXPECTED_VERSIONS" ]; then
for version in "${EXPECTED_VERSIONS[@]}"; do
if [[ "$version" == "$SMCP_VERSION"* ]]; then
export EXPECTED_VERSION="$version"
break
fi
done
fi

echo "Output dir: $OUTPUT_DIR"
mkdir -p "$OUTPUT_DIR"
Expand Down