Skip to content

Commit

Permalink
Add a test marker for integration test:
Browse files Browse the repository at this point in the history
Tests with this marker will require the env
INTEGRATION_TESTS_ENABLED=true to be set. Updated
all tests accordingly.

Signed-off-by: Jacob Weinstock <jakobweinstock@gmail.com>
  • Loading branch information
jacobweinstock committed Sep 27, 2023
1 parent 3e1bd59 commit 58c4344
Show file tree
Hide file tree
Showing 27 changed files with 218 additions and 179 deletions.
34 changes: 9 additions & 25 deletions controllers/cloudstack_datacenter_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package controllers_test
import (
"context"
"errors"
"os"
"testing"
"time"

Expand All @@ -17,16 +16,15 @@ import (
"sigs.k8s.io/controller-runtime/pkg/reconcile"

"github.com/aws/eks-anywhere/controllers"
"github.com/aws/eks-anywhere/internal/test"
anywherev1 "github.com/aws/eks-anywhere/pkg/api/v1alpha1"
"github.com/aws/eks-anywhere/pkg/constants"
"github.com/aws/eks-anywhere/pkg/providers/cloudstack"
"github.com/aws/eks-anywhere/pkg/providers/cloudstack/decoder"
)

func TestCloudStackDatacenterReconcilerSetupWithManager(t *testing.T) {
if os.Getenv(integrationTestEnvVar) != "true" {
t.Skipf("set env var '%v=true' to run this test", integrationTestEnvVar)
}
test.MarkIntegration(t)
client := env.Client()
r := controllers.NewCloudStackDatacenterReconciler(client, nil)

Expand All @@ -35,9 +33,7 @@ func TestCloudStackDatacenterReconcilerSetupWithManager(t *testing.T) {
}

func TestCloudStackDatacenterReconcilerSuccess(t *testing.T) {
if os.Getenv(integrationTestEnvVar) != "true" {
t.Skipf("set env var '%v=true' to run this test", integrationTestEnvVar)
}
test.MarkIntegration(t)
g := NewWithT(t)
ctx := context.Background()

Expand Down Expand Up @@ -86,9 +82,7 @@ func TestCloudStackDatacenterReconcilerSuccess(t *testing.T) {
}

func TestCloudStackDatacenterReconcilerSetDefaultSuccess(t *testing.T) {
if os.Getenv(integrationTestEnvVar) != "true" {
t.Skipf("set env var '%v=true' to run this test", integrationTestEnvVar)
}
test.MarkIntegration(t)
g := NewWithT(t)
ctx := context.Background()

Expand Down Expand Up @@ -156,9 +150,7 @@ func TestCloudStackDatacenterReconcilerSetDefaultSuccess(t *testing.T) {
}

func TestCloudstackDatacenterConfigReconcilerDelete(t *testing.T) {
if os.Getenv(integrationTestEnvVar) != "true" {
t.Skipf("set env var '%v=true' to run this test", integrationTestEnvVar)
}
test.MarkIntegration(t)
g := NewWithT(t)
ctx := context.Background()

Expand All @@ -183,9 +175,7 @@ func TestCloudstackDatacenterConfigReconcilerDelete(t *testing.T) {
}

func TestCloudstackDatacenterConfigGetValidatorFailure(t *testing.T) {
if os.Getenv(integrationTestEnvVar) != "true" {
t.Skipf("set env var '%v=true' to run this test", integrationTestEnvVar)
}
test.MarkIntegration(t)
g := NewWithT(t)
ctx := context.Background()

Expand Down Expand Up @@ -214,9 +204,7 @@ func TestCloudstackDatacenterConfigGetValidatorFailure(t *testing.T) {
}

func TestCloudstackDatacenterConfigGetDatacenterFailure(t *testing.T) {
if os.Getenv(integrationTestEnvVar) != "true" {
t.Skipf("set env var '%v=true' to run this test", integrationTestEnvVar)
}
test.MarkIntegration(t)
g := NewWithT(t)
ctx := context.Background()
client := fake.NewClientBuilder().WithScheme(runtime.NewScheme()).Build()
Expand All @@ -236,9 +224,7 @@ func TestCloudstackDatacenterConfigGetDatacenterFailure(t *testing.T) {
}

func TestCloudstackDatacenterConfigGetExecConfigFailure(t *testing.T) {
if os.Getenv(integrationTestEnvVar) != "true" {
t.Skipf("set env var '%v=true' to run this test", integrationTestEnvVar)
}
test.MarkIntegration(t)
g := NewWithT(t)
ctx := context.Background()

Expand All @@ -265,9 +251,7 @@ func TestCloudstackDatacenterConfigGetExecConfigFailure(t *testing.T) {
}

func TestCloudstackDatacenterConfigAccountNotPresentFailure(t *testing.T) {
if os.Getenv(integrationTestEnvVar) != "true" {
t.Skipf("set env var '%v=true' to run this test", integrationTestEnvVar)
}
test.MarkIntegration(t)
g := NewWithT(t)
ctx := context.Background()
dcConfig := createCloudstackDatacenterConfig()
Expand Down
6 changes: 2 additions & 4 deletions controllers/cluster_controller_test_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package controllers_test
import (
"context"
"errors"
"os"
"testing"

"github.com/go-logr/logr"
Expand Down Expand Up @@ -32,9 +31,7 @@ import (
)

func TestClusterReconcilerEnsureOwnerReferences(t *testing.T) {
if os.Getenv(integrationTestEnvVar) != "true" {
t.Skipf("set env var '%v=true' to run this test", integrationTestEnvVar)
}
test.MarkIntegration(t)
g := NewWithT(t)
ctx := context.Background()

Expand Down Expand Up @@ -208,6 +205,7 @@ func TestClusterReconcilerReconcileChildObjectNotFound(t *testing.T) {
}

func TestClusterReconcilerSetupWithManager(t *testing.T) {
test.MarkIntegration(t)
client := env.Client()
r := controllers.NewClusterReconciler(client, newRegistryForDummyProviderReconciler(), newMockAWSIamConfigReconciler(t), newMockClusterValidator(t), nil, nil)

Expand Down
7 changes: 4 additions & 3 deletions controllers/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,16 @@ import (
"os"
"testing"

"github.com/aws/eks-anywhere/internal/test"
"github.com/aws/eks-anywhere/internal/test/envtest"
)

const integrationTestEnvVar = "INTEGRATION_TESTS_ENABLED"

var env *envtest.Environment

func TestMain(m *testing.M) {
if os.Getenv(integrationTestEnvVar) == "true" {
if os.Getenv(test.IntegrationTestEnvVar) == "true" {
os.Exit(envtest.RunWithEnvironment(m, envtest.WithAssignment(&env)))
} else {
os.Exit(m.Run())
}
}
2 changes: 2 additions & 0 deletions controllers/nutanix_datacenter_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@ import (
"sigs.k8s.io/controller-runtime/pkg/reconcile"

"github.com/aws/eks-anywhere/controllers"
"github.com/aws/eks-anywhere/internal/test"
anywherev1 "github.com/aws/eks-anywhere/pkg/api/v1alpha1"
"github.com/aws/eks-anywhere/pkg/providers/nutanix"
)

func TestNutanixDatacenterConfigReconcilerSetupWithManager(t *testing.T) {
test.MarkIntegration(t)
client := env.Client()
r := controllers.NewNutanixDatacenterReconciler(client, nutanix.NewDefaulter())

Expand Down
2 changes: 2 additions & 0 deletions controllers/snow_machineconfig_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (

"github.com/aws/eks-anywhere/controllers"
"github.com/aws/eks-anywhere/controllers/mocks"
"github.com/aws/eks-anywhere/internal/test"
anywherev1 "github.com/aws/eks-anywhere/pkg/api/v1alpha1"
)

Expand All @@ -27,6 +28,7 @@ var (
)

func TestSnowMachineConfigReconcilerSetupWithManager(t *testing.T) {
test.MarkIntegration(t)
client := env.Client()
r := controllers.NewSnowMachineConfigReconciler(client, nil)

Expand Down
2 changes: 2 additions & 0 deletions controllers/tinkerbell_datacenter_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@ import (
. "github.com/onsi/gomega"

"github.com/aws/eks-anywhere/controllers"
"github.com/aws/eks-anywhere/internal/test"
)

func TestTinkerbellDatacenterReconcilerSetupWithManager(t *testing.T) {
test.MarkIntegration(t)
client := env.Client()
r := controllers.NewTinkerbellDatacenterReconciler(client)

Expand Down
15 changes: 15 additions & 0 deletions internal/test/markers.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package test

import (
"os"
"testing"
)

const IntegrationTestEnvVar = "INTEGRATION_TESTS_ENABLED"

Check warning on line 8 in internal/test/markers.go

View workflow job for this annotation

GitHub Actions / lint

exported: exported const IntegrationTestEnvVar should have comment or be unexported (revive)

func MarkIntegration(t *testing.T) {

Check warning on line 10 in internal/test/markers.go

View workflow job for this annotation

GitHub Actions / lint

exported: exported function MarkIntegration should have comment or be unexported (revive)
t.Helper()
if os.Getenv(IntegrationTestEnvVar) != "true" {
t.Skipf("set env var '%v=true' to run this test", IntegrationTestEnvVar)
}
}
11 changes: 2 additions & 9 deletions pkg/clients/kubernetes/runtimeclient_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package kubernetes_test
import (
"context"
"errors"
"os"
"reflect"
"testing"

Expand All @@ -18,12 +17,8 @@ import (
"github.com/aws/eks-anywhere/pkg/clients/kubernetes"
)

const integrationTestEnvVar = "INTEGRATION_TESTS_ENABLED"

func TestNewRuntimeClient(t *testing.T) {
if os.Getenv(integrationTestEnvVar) != "true" {
t.Skipf("set env var '%v=true' to run this test", integrationTestEnvVar)
}
test.MarkIntegration(t)
g := NewWithT(t)
cfg := test.UseEnvTest(t)
rc := kubernetes.RestConfigurator(func(_ []byte) (*rest.Config, error) { return cfg, nil })
Expand Down Expand Up @@ -57,9 +52,7 @@ func TestNewRuntimeClientInvalidRestConfig(t *testing.T) {
}

func TestNewRuntimeClientInvalidScheme(t *testing.T) {
if os.Getenv(integrationTestEnvVar) != "true" {
t.Skipf("set env var '%v=true' to run this test", integrationTestEnvVar)
}
test.MarkIntegration(t)
g := NewWithT(t)
cfg := test.UseEnvTest(t)
rc := kubernetes.RestConfigurator(func(_ []byte) (*rest.Config, error) { return cfg, nil })
Expand Down
6 changes: 6 additions & 0 deletions pkg/controller/clusters/controlplane_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
)

func TestReconcileControlPlaneStackedEtcd(t *testing.T) {
test.MarkIntegration(t)
g := NewWithT(t)
c := env.Client()
api := envtest.NewAPIExpecter(t, c)
Expand All @@ -42,6 +43,7 @@ func TestReconcileControlPlaneStackedEtcd(t *testing.T) {
}

func TestReconcileControlPlaneExternalEtcdNewCluster(t *testing.T) {
test.MarkIntegration(t)
g := NewWithT(t)
c := env.Client()
api := envtest.NewAPIExpecter(t, c)
Expand Down Expand Up @@ -72,6 +74,7 @@ func TestReconcileControlPlaneExternalEtcdNewCluster(t *testing.T) {
}

func TestReconcileControlPlaneExternalEtcdUpgradeWithDiff(t *testing.T) {
test.MarkIntegration(t)
g := NewWithT(t)
c := env.Client()
api := envtest.NewAPIExpecter(t, c)
Expand Down Expand Up @@ -129,6 +132,7 @@ func TestReconcileControlPlaneExternalEtcdUpgradeWithDiff(t *testing.T) {
}

func TestReconcileControlPlaneExternalEtcdNotReady(t *testing.T) {
test.MarkIntegration(t)
g := NewWithT(t)
c := env.Client()
api := envtest.NewAPIExpecter(t, c)
Expand Down Expand Up @@ -166,6 +170,7 @@ func TestReconcileControlPlaneExternalEtcdNotReady(t *testing.T) {
}

func TestReconcileControlPlaneExternalEtcdReadyControlPlaneUpgrade(t *testing.T) {
test.MarkIntegration(t)
g := NewWithT(t)
c := env.Client()
api := envtest.NewAPIExpecter(t, c)
Expand Down Expand Up @@ -223,6 +228,7 @@ func TestReconcileControlPlaneExternalEtcdReadyControlPlaneUpgrade(t *testing.T)
}

func TestReconcileControlPlaneExternalEtcdUpgradeWithNoNamespace(t *testing.T) {
test.MarkIntegration(t)
g := NewWithT(t)
c := env.Client()
api := envtest.NewAPIExpecter(t, c)
Expand Down
7 changes: 4 additions & 3 deletions pkg/controller/clusters/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,16 @@ import (
"os"
"testing"

"github.com/aws/eks-anywhere/internal/test"
"github.com/aws/eks-anywhere/internal/test/envtest"
)

const integrationTestEnvVar = "INTEGRATION_TESTS_ENABLED"

var env *envtest.Environment

func TestMain(m *testing.M) {
if os.Getenv(integrationTestEnvVar) == "true" {
if os.Getenv(test.IntegrationTestEnvVar) == "true" {
os.Exit(envtest.RunWithEnvironment(m, envtest.WithAssignment(&env)))
} else {
os.Exit(m.Run())
}
}
5 changes: 5 additions & 0 deletions pkg/controller/clusters/workers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
)

func TestReconcileWorkersSuccess(t *testing.T) {
test.MarkIntegration(t)
g := NewWithT(t)
c := env.Client()
api := envtest.NewAPIExpecter(t, c)
Expand Down Expand Up @@ -66,6 +67,7 @@ func TestReconcileWorkersSuccess(t *testing.T) {
}

func TestReconcileWorkersErrorApplyingObjects(t *testing.T) {
test.MarkIntegration(t)
g := NewWithT(t)
c := env.Client()
ctx := context.Background()
Expand Down Expand Up @@ -192,6 +194,7 @@ func dockerMachineTemplate(name, namespace string) *dockerv1.DockerMachineTempla
}

func TestReconcileWorkersForEKSAErrorGettingCAPICluster(t *testing.T) {
test.MarkIntegration(t)
g := NewWithT(t)
c := fake.NewClientBuilder().WithScheme(runtime.NewScheme()).Build()
ctx := context.Background()
Expand All @@ -210,6 +213,7 @@ func TestReconcileWorkersForEKSAErrorGettingCAPICluster(t *testing.T) {
}

func TestReconcileWorkersForEKSANoCAPICluster(t *testing.T) {
test.MarkIntegration(t)
g := NewWithT(t)
c := env.Client()
ctx := context.Background()
Expand All @@ -228,6 +232,7 @@ func TestReconcileWorkersForEKSANoCAPICluster(t *testing.T) {
}

func TestReconcileWorkersForEKSASuccess(t *testing.T) {
test.MarkIntegration(t)
g := NewWithT(t)
c := env.Client()
api := envtest.NewAPIExpecter(t, c)
Expand Down
14 changes: 4 additions & 10 deletions pkg/controller/serverside/applier_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,20 @@ package serverside_test
import (
"context"
"errors"
"os"
"testing"

. "github.com/onsi/gomega"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

"github.com/aws/eks-anywhere/internal/test"
"github.com/aws/eks-anywhere/pkg/clients/kubernetes"
"github.com/aws/eks-anywhere/pkg/controller"
"github.com/aws/eks-anywhere/pkg/controller/serverside"
)

func TestObjectApplierApplySuccess(t *testing.T) {
if os.Getenv(integrationTestEnvVar) != "true" {
t.Skipf("set env var '%v=true' to run this test", integrationTestEnvVar)
}
test.MarkIntegration(t)
g := NewWithT(t)
ctx := context.Background()
namespace := env.CreateNamespaceForTest(ctx, t)
Expand All @@ -31,9 +29,7 @@ func TestObjectApplierApplySuccess(t *testing.T) {
}

func TestObjectApplierApplyErrorFromGenerator(t *testing.T) {
if os.Getenv(integrationTestEnvVar) != "true" {
t.Skipf("set env var '%v=true' to run this test", integrationTestEnvVar)
}
test.MarkIntegration(t)
g := NewWithT(t)
ctx := context.Background()

Expand All @@ -45,9 +41,7 @@ func TestObjectApplierApplyErrorFromGenerator(t *testing.T) {
}

func TestObjectApplierApplyErrorApplying(t *testing.T) {
if os.Getenv(integrationTestEnvVar) != "true" {
t.Skipf("set env var '%v=true' to run this test", integrationTestEnvVar)
}
test.MarkIntegration(t)
g := NewWithT(t)
ctx := context.Background()

Expand Down
Loading

0 comments on commit 58c4344

Please sign in to comment.