Skip to content
Merged
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
9 changes: 9 additions & 0 deletions pkg/env/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,12 @@ func GetBool(key string, defaultValue bool) bool {
}
return boolValue
}

func GetInt(key string, defaultValue int) int {
value := Get(key, strconv.Itoa(defaultValue))
intValue, err := strconv.Atoi(value)
if err != nil {
return defaultValue
}
return intValue
}
48 changes: 48 additions & 0 deletions pkg/env/env_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,3 +112,51 @@ func TestGetBool(t *testing.T) {
})
}
}

func TestGetInt(t *testing.T) {
intKey := "ENV_TEST_TEST_GET_INT_VALID"
intValue := "42"
t.Setenv(intKey, intValue)

notIntKey := "ENV_TEST_TEST_GET_INT_INVALID"
notIntValue := "not an int"
t.Setenv(notIntKey, notIntValue)

tests := []struct {
name string
key string
defaultValue int
want int
}{
{
name: "empty-key",
key: "",
defaultValue: 100,
want: 100,
},
{
name: "missing-env-var",
key: "NONEXISTENT_ENV_VAR",
defaultValue: 200,
want: 200,
},
{
name: "int-value",
key: intKey,
defaultValue: 0,
want: 42,
},
{
name: "non-int-value-returns-default",
key: notIntKey,
defaultValue: 300,
want: 300,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got := GetInt(tt.key, tt.defaultValue)
assert.Equalf(t, tt.want, got, "GetInt(%v, %v)", tt.key, tt.defaultValue)
})
}
}
1 change: 1 addition & 0 deletions tests/e2e/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,7 @@ The following environment variables define the behavior of the test run:
* DEPLOYMENT_NAME=sail-operator - The name of the operator deployment.
* EXPECTED_REGISTRY=`^docker\.io|^gcr\.io|^registry\.istio\.io` - Which image registry should the operand images come from. Useful for downstream tests.
* KEEP_ON_FAILURE - If set to true, when using a local KIND cluster, don't clean it up when the test fails. This allows to debug the failure.
* DEFAULT_TEST_TIMEOUT=180 - The default timeout in seconds for `Eventually` assertions. Increase this value when running tests on slow clusters (e.g., `DEFAULT_TEST_TIMEOUT=300` for 5 minutes).

### Customizing the test run

Expand Down
7 changes: 3 additions & 4 deletions tests/e2e/ambient/ambient_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (

"github.com/Masterminds/semver/v3"
v1 "github.com/istio-ecosystem/sail-operator/api/v1"
"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/util/ginkgo"
Expand All @@ -36,12 +37,10 @@ import (
"sigs.k8s.io/controller-runtime/pkg/client"
)

const (
defaultTimeout = 180
)
var defaultTimeout = env.GetInt("DEFAULT_TEST_TIMEOUT", 180)

var _ = Describe("Ambient configuration ", Label("smoke", "ambient"), Ordered, func() {
SetDefaultEventuallyTimeout(defaultTimeout * time.Second)
SetDefaultEventuallyTimeout(time.Duration(defaultTimeout) * time.Second)
SetDefaultEventuallyPollingInterval(time.Second)

debugInfoLogged := false
Expand Down
3 changes: 2 additions & 1 deletion tests/e2e/controlplane/control_plane_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (

"github.com/Masterminds/semver/v3"
v1 "github.com/istio-ecosystem/sail-operator/api/v1"
"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/util/ginkgo"
Expand All @@ -42,7 +43,7 @@ import (
)

var _ = Describe("Control Plane Installation", Label("smoke", "control-plane", "slow"), Ordered, func() {
SetDefaultEventuallyTimeout(180 * time.Second)
SetDefaultEventuallyTimeout(time.Duration(env.GetInt("DEFAULT_TEST_TIMEOUT", 180)) * time.Second)
SetDefaultEventuallyPollingInterval(time.Second)
debugInfoLogged := false

Expand Down
3 changes: 2 additions & 1 deletion tests/e2e/controlplane/control_plane_update_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (

"github.com/Masterminds/semver/v3"
v1 "github.com/istio-ecosystem/sail-operator/api/v1"
"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/util/ginkgo"
Expand All @@ -37,7 +38,7 @@ import (
)

var _ = Describe("Control Plane updates", Label("control-plane", "slow"), Ordered, func() {
SetDefaultEventuallyTimeout(180 * time.Second)
SetDefaultEventuallyTimeout(time.Duration(env.GetInt("DEFAULT_TEST_TIMEOUT", 180)) * time.Second)
SetDefaultEventuallyPollingInterval(time.Second)
debugInfoLogged := false

Expand Down
3 changes: 2 additions & 1 deletion tests/e2e/dualstack/dualstack_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (

"github.com/Masterminds/semver/v3"
v1 "github.com/istio-ecosystem/sail-operator/api/v1"
"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/util/ginkgo"
Expand All @@ -45,7 +46,7 @@ const (
)

var _ = Describe("DualStack configuration ", Label("dualstack"), Ordered, func() {
SetDefaultEventuallyTimeout(180 * time.Second)
SetDefaultEventuallyTimeout(time.Duration(env.GetInt("DEFAULT_TEST_TIMEOUT", 180)) * time.Second)
SetDefaultEventuallyPollingInterval(time.Second)

debugInfoLogged := false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"time"

v1 "github.com/istio-ecosystem/sail-operator/api/v1"
"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/util/ginkgo"
Expand All @@ -44,7 +45,7 @@ const (
)

var _ = Describe("Multicluster deployment models", Label("multicluster", "multicluster-external"), Ordered, func() {
SetDefaultEventuallyTimeout(180 * time.Second)
SetDefaultEventuallyTimeout(time.Duration(env.GetInt("DEFAULT_TEST_TIMEOUT", 180)) * time.Second)
SetDefaultEventuallyPollingInterval(time.Second)

Describe("External Control Plane Multi-Network configuration", func() {
Expand Down
3 changes: 2 additions & 1 deletion tests/e2e/multicluster/multicluster_multiprimary_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"time"

v1 "github.com/istio-ecosystem/sail-operator/api/v1"
"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/util/ginkgo"
Expand All @@ -39,7 +40,7 @@ import (
)

var _ = Describe("Multicluster deployment models", Label("multicluster", "multicluster-multiprimary"), Ordered, func() {
SetDefaultEventuallyTimeout(180 * time.Second)
SetDefaultEventuallyTimeout(time.Duration(env.GetInt("DEFAULT_TEST_TIMEOUT", 180)) * time.Second)
SetDefaultEventuallyPollingInterval(time.Second)

Describe("Multi-Primary Multi-Network configuration", func() {
Expand Down
3 changes: 2 additions & 1 deletion tests/e2e/multicluster/multicluster_primaryremote_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"time"

v1 "github.com/istio-ecosystem/sail-operator/api/v1"
"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/util/ginkgo"
Expand All @@ -40,7 +41,7 @@ import (
)

var _ = Describe("Multicluster deployment models", Label("multicluster", "multicluster-primaryremote"), Ordered, func() {
SetDefaultEventuallyTimeout(180 * time.Second)
SetDefaultEventuallyTimeout(time.Duration(env.GetInt("DEFAULT_TEST_TIMEOUT", 180)) * time.Second)
SetDefaultEventuallyPollingInterval(time.Second)

Describe("Primary-Remote - Multi-Network configuration", func() {
Expand Down
3 changes: 2 additions & 1 deletion tests/e2e/multicontrolplane/multi_control_plane_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"time"

v1 "github.com/istio-ecosystem/sail-operator/api/v1"
"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/util/ginkgo"
Expand All @@ -34,7 +35,7 @@ import (
)

var _ = Describe("Multi control plane deployment model", Label("smoke", "multicontrol-plane"), Ordered, func() {
SetDefaultEventuallyTimeout(180 * time.Second)
SetDefaultEventuallyTimeout(time.Duration(env.GetInt("DEFAULT_TEST_TIMEOUT", 180)) * time.Second)
SetDefaultEventuallyPollingInterval(time.Second)
debugInfoLogged := false
latestVersion := istioversion.GetLatestPatchVersions()[0]
Expand Down
3 changes: 2 additions & 1 deletion tests/e2e/operator/operator_install_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"path/filepath"
"time"

"github.com/istio-ecosystem/sail-operator/pkg/env"
"github.com/istio-ecosystem/sail-operator/pkg/kube"
. "github.com/istio-ecosystem/sail-operator/pkg/test/util/ginkgo"
"github.com/istio-ecosystem/sail-operator/tests/e2e/util/cleaner"
Expand Down Expand Up @@ -57,7 +58,7 @@ var sailCRDs = []string{
}

var _ = Describe("Operator", Label("smoke", "operator"), Ordered, func() {
SetDefaultEventuallyTimeout(180 * time.Second)
SetDefaultEventuallyTimeout(time.Duration(env.GetInt("DEFAULT_TEST_TIMEOUT", 180)) * time.Second)
SetDefaultEventuallyPollingInterval(time.Second)

Describe("installation", func() {
Expand Down
Loading