diff --git a/tests/e2e/util/env/env.go b/pkg/env/env.go similarity index 84% rename from tests/e2e/util/env/env.go rename to pkg/env/env.go index 84b33c1ae..55e1618ab 100644 --- a/tests/e2e/util/env/env.go +++ b/pkg/env/env.go @@ -1,12 +1,10 @@ -//go:build e2e - // Copyright Istio Authors // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // -// http://www.apache.org/licenses/LICENSE-2.0 +// http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, @@ -19,8 +17,6 @@ package env import ( "os" "strconv" - - g "github.com/onsi/ginkgo/v2" ) func Get(key, defaultValue string) string { @@ -28,9 +24,6 @@ func Get(key, defaultValue string) string { if value == "" { return defaultValue } - - g.GinkgoWriter.Printf("Env variable %s is set to %s\n", key, value) - return value } diff --git a/pkg/istioversion/version.go b/pkg/istioversion/version.go index 3482367bd..902ba9625 100644 --- a/pkg/istioversion/version.go +++ b/pkg/istioversion/version.go @@ -17,9 +17,9 @@ package istioversion import ( "embed" "fmt" - "os" "github.com/Masterminds/semver/v3" + "github.com/istio-ecosystem/sail-operator/pkg/env" "gopkg.in/yaml.v3" "istio.io/istio/pkg/log" @@ -29,17 +29,10 @@ var ( //go:embed *.yaml versionsFiles embed.FS - versionsFilename = getenv("VERSIONS_YAML_FILE", "versions.yaml") + // versionsFilename is set via ldflags when building the binary and via an environment variable when running tests + versionsFilename = env.Get("VERSIONS_YAML_FILE", "versions.yaml") ) -func getenv(key string, defaultValue string) string { - value := os.Getenv(key) - if value == "" { - return defaultValue - } - return value -} - // Versions represents the top-level structure of versions.yaml type Versions struct { Versions []VersionInfo `json:"versions"` diff --git a/tests/e2e/ambient/ambient_suite_test.go b/tests/e2e/ambient/ambient_suite_test.go index eecfccab4..9db77bed1 100644 --- a/tests/e2e/ambient/ambient_suite_test.go +++ b/tests/e2e/ambient/ambient_suite_test.go @@ -19,9 +19,9 @@ package ambient import ( "testing" + "github.com/istio-ecosystem/sail-operator/pkg/env" k8sclient "github.com/istio-ecosystem/sail-operator/tests/e2e/util/client" "github.com/istio-ecosystem/sail-operator/tests/e2e/util/common" - "github.com/istio-ecosystem/sail-operator/tests/e2e/util/env" "github.com/istio-ecosystem/sail-operator/tests/e2e/util/kubectl" . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" diff --git a/tests/e2e/controlplane/control_plane_suite_test.go b/tests/e2e/controlplane/control_plane_suite_test.go index e73d01a11..e69ffc08e 100644 --- a/tests/e2e/controlplane/control_plane_suite_test.go +++ b/tests/e2e/controlplane/control_plane_suite_test.go @@ -19,9 +19,9 @@ package controlplane import ( "testing" + "github.com/istio-ecosystem/sail-operator/pkg/env" k8sclient "github.com/istio-ecosystem/sail-operator/tests/e2e/util/client" "github.com/istio-ecosystem/sail-operator/tests/e2e/util/common" - "github.com/istio-ecosystem/sail-operator/tests/e2e/util/env" "github.com/istio-ecosystem/sail-operator/tests/e2e/util/kubectl" . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" diff --git a/tests/e2e/dualstack/dualstack_suite_test.go b/tests/e2e/dualstack/dualstack_suite_test.go index a18166cc4..32ab24842 100644 --- a/tests/e2e/dualstack/dualstack_suite_test.go +++ b/tests/e2e/dualstack/dualstack_suite_test.go @@ -19,9 +19,9 @@ package dualstack import ( "testing" + "github.com/istio-ecosystem/sail-operator/pkg/env" k8sclient "github.com/istio-ecosystem/sail-operator/tests/e2e/util/client" "github.com/istio-ecosystem/sail-operator/tests/e2e/util/common" - "github.com/istio-ecosystem/sail-operator/tests/e2e/util/env" "github.com/istio-ecosystem/sail-operator/tests/e2e/util/kubectl" . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" diff --git a/tests/e2e/multicluster/multicluster_suite_test.go b/tests/e2e/multicluster/multicluster_suite_test.go index d00b9c64e..4ca3f5fb1 100644 --- a/tests/e2e/multicluster/multicluster_suite_test.go +++ b/tests/e2e/multicluster/multicluster_suite_test.go @@ -22,10 +22,10 @@ import ( "path/filepath" "testing" + "github.com/istio-ecosystem/sail-operator/pkg/env" "github.com/istio-ecosystem/sail-operator/tests/e2e/util/certs" k8sclient "github.com/istio-ecosystem/sail-operator/tests/e2e/util/client" "github.com/istio-ecosystem/sail-operator/tests/e2e/util/common" - "github.com/istio-ecosystem/sail-operator/tests/e2e/util/env" "github.com/istio-ecosystem/sail-operator/tests/e2e/util/kubectl" . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" diff --git a/tests/e2e/operator/operator_suite_test.go b/tests/e2e/operator/operator_suite_test.go index 11063b486..ad4f2a88d 100644 --- a/tests/e2e/operator/operator_suite_test.go +++ b/tests/e2e/operator/operator_suite_test.go @@ -19,9 +19,9 @@ package operator import ( "testing" + "github.com/istio-ecosystem/sail-operator/pkg/env" k8sclient "github.com/istio-ecosystem/sail-operator/tests/e2e/util/client" "github.com/istio-ecosystem/sail-operator/tests/e2e/util/common" - "github.com/istio-ecosystem/sail-operator/tests/e2e/util/env" "github.com/istio-ecosystem/sail-operator/tests/e2e/util/kubectl" . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" diff --git a/tests/e2e/util/common/e2e_utils.go b/tests/e2e/util/common/e2e_utils.go index 5b92915a3..2d64bbbe6 100644 --- a/tests/e2e/util/common/e2e_utils.go +++ b/tests/e2e/util/common/e2e_utils.go @@ -26,10 +26,10 @@ import ( "time" "github.com/Masterminds/semver/v3" + "github.com/istio-ecosystem/sail-operator/pkg/env" "github.com/istio-ecosystem/sail-operator/pkg/istioversion" "github.com/istio-ecosystem/sail-operator/pkg/kube" "github.com/istio-ecosystem/sail-operator/pkg/test/project" - "github.com/istio-ecosystem/sail-operator/tests/e2e/util/env" . "github.com/istio-ecosystem/sail-operator/tests/e2e/util/gomega" "github.com/istio-ecosystem/sail-operator/tests/e2e/util/helm" "github.com/istio-ecosystem/sail-operator/tests/e2e/util/kubectl" diff --git a/tests/e2e/util/istioctl/istioctl.go b/tests/e2e/util/istioctl/istioctl.go index 7186ed6b1..c880c819f 100644 --- a/tests/e2e/util/istioctl/istioctl.go +++ b/tests/e2e/util/istioctl/istioctl.go @@ -19,7 +19,7 @@ package istioctl import ( "fmt" - "github.com/istio-ecosystem/sail-operator/tests/e2e/util/env" + "github.com/istio-ecosystem/sail-operator/pkg/env" "github.com/istio-ecosystem/sail-operator/tests/e2e/util/shell" )