Skip to content

Commit

Permalink
chore(tests) convert remaining tests to new E2E
Browse files Browse the repository at this point in the history
Convert tests other than the webhook tests to the new E2E environment
helper.

Refactor image loads to always succeed during builder construction.
  • Loading branch information
rainest committed Nov 1, 2022
1 parent 0a89160 commit eeb615e
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 118 deletions.
47 changes: 10 additions & 37 deletions test/e2e/all_in_one_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ import (

"github.com/kong/kubernetes-testing-framework/pkg/clusters"
"github.com/kong/kubernetes-testing-framework/pkg/clusters/addons/kong"
"github.com/kong/kubernetes-testing-framework/pkg/clusters/addons/metallb"
"github.com/kong/kubernetes-testing-framework/pkg/environments"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
autoscalingv1 "k8s.io/api/autoscaling/v1"
Expand Down Expand Up @@ -107,13 +105,8 @@ func TestDeployAndUpgradeAllInOneDBLESS(t *testing.T) {
defer cancel()

t.Log("building test cluster and environment")
addons := []clusters.Addon{}
addons = append(addons, metallb.New())

addons = append(addons, buildImageLoadAddons(t, imageLoad, kongImageLoad)...)

builder := setBuilderKubernetesVersion(t,
environments.NewBuilder().WithAddons(addons...), clusterVersionStr)
builder, err := getEnvironmentBuilder(ctx)
require.NoError(t, err)

env, err := builder.Build(ctx)
require.NoError(t, err)
Expand Down Expand Up @@ -159,13 +152,8 @@ func TestDeployAllInOneEnterpriseDBLESS(t *testing.T) {
defer cancel()

t.Log("building test cluster and environment")
addons := []clusters.Addon{}
addons = append(addons, metallb.New())

addons = append(addons, buildImageLoadAddons(t, imageLoad, kongImageLoad)...)

builder := setBuilderKubernetesVersion(t,
environments.NewBuilder().WithAddons(addons...), clusterVersionStr)
builder, err := getEnvironmentBuilder(ctx)
require.NoError(t, err)
env, err := builder.Build(ctx)
require.NoError(t, err)

Expand Down Expand Up @@ -215,13 +203,8 @@ func TestDeployAllInOnePostgres(t *testing.T) {
defer cancel()

t.Log("building test cluster and environment")
addons := []clusters.Addon{}
addons = append(addons, metallb.New())

addons = append(addons, buildImageLoadAddons(t, imageLoad, kongImageLoad)...)

builder := setBuilderKubernetesVersion(t,
environments.NewBuilder().WithAddons(addons...), clusterVersionStr)
builder, err := getEnvironmentBuilder(ctx)
require.NoError(t, err)
env, err := builder.Build(ctx)
require.NoError(t, err)

Expand Down Expand Up @@ -256,13 +239,8 @@ func TestDeployAllInOnePostgresWithMultipleReplicas(t *testing.T) {
defer cancel()

t.Log("building test cluster and environment")
addons := []clusters.Addon{}
addons = append(addons, metallb.New())

addons = append(addons, buildImageLoadAddons(t, imageLoad, kongImageLoad)...)

builder := setBuilderKubernetesVersion(t,
environments.NewBuilder().WithAddons(addons...), clusterVersionStr)
builder, err := getEnvironmentBuilder(ctx)
require.NoError(t, err)
env, err := builder.Build(ctx)
require.NoError(t, err)

Expand Down Expand Up @@ -412,13 +390,8 @@ func TestDeployAllInOneEnterprisePostgres(t *testing.T) {
defer cancel()

t.Log("building test cluster and environment")
addons := []clusters.Addon{}
addons = append(addons, metallb.New())

addons = append(addons, buildImageLoadAddons(t, imageLoad, kongImageLoad)...)

builder := setBuilderKubernetesVersion(t,
environments.NewBuilder().WithAddons(addons...), clusterVersionStr)
builder, err := getEnvironmentBuilder(ctx)
require.NoError(t, err)
env, err := builder.Build(ctx)
require.NoError(t, err)
createKongImagePullSecret(ctx, t, env)
Expand Down
71 changes: 19 additions & 52 deletions test/e2e/features_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,18 @@ func TestWebhookUpdate(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()

// on KIND, this test requires webhookKINDConfig. the generic getEnvironmentBuilder we use for most tests doesn't
// support this: the configuration is specific to KIND but should not be used by default, and the scaffolding isn't
// flexible enough to support tests building their own clusters or passing additional builder functions. this still
// uses the setup style from before getEnvironmentBuilder/GKE support as such, and just skips if it's attempting
// to run on GKE
if existingCluster != "" {
clusterType := strings.Split(existingCluster, ":")[0]
if clusterType != string(kind.KindClusterType) {
t.Skip("test not supported on non-KIND clusters")
}
}

t.Log("building test cluster and environment")
configFile, err := os.CreateTemp(os.TempDir(), "webhook-kind-config-")
require.NoError(t, err)
Expand Down Expand Up @@ -302,14 +314,8 @@ func TestDeployAllInOneDBLESSGateway(t *testing.T) {
defer cancel()

t.Log("building test cluster and environment")
addons := []clusters.Addon{}
addons = append(addons, metallb.New())
if b, err := loadimage.NewBuilder().WithImage(imageLoad); err == nil {
addons = append(addons, b.Build())
}

builder := setBuilderKubernetesVersion(t,
environments.NewBuilder().WithAddons(addons...), clusterVersionStr)
builder, err := getEnvironmentBuilder(ctx)
require.NoError(t, err)
env, err := builder.Build(ctx)
require.NoError(t, err)

Expand Down Expand Up @@ -498,13 +504,8 @@ func TestDeployAllInOneDBLESSNoLoadBalancer(t *testing.T) {
defer cancel()

t.Log("building test cluster and environment")
addons := []clusters.Addon{}
if b, err := loadimage.NewBuilder().WithImage(imageLoad); err == nil {
addons = append(addons, b.Build())
}

builder := setBuilderKubernetesVersion(t,
environments.NewBuilder().WithAddons(addons...), clusterVersionStr)
builder, err := getEnvironmentBuilder(ctx)
require.NoError(t, err)
env, err := builder.Build(ctx)
require.NoError(t, err)
cleaner := clusters.NewCleaner(env.Cluster())
Expand Down Expand Up @@ -568,29 +569,8 @@ func TestDefaultIngressClass(t *testing.T) {
defer cancel()

t.Log("building test cluster and environment")
configFile, err := os.CreateTemp(os.TempDir(), "test-default-ingress-class")
require.NoError(t, err)
defer os.Remove(configFile.Name())
defer configFile.Close()
written, err := configFile.Write([]byte(webhookKINDConfig))
builder, err := getEnvironmentBuilder(ctx)
require.NoError(t, err)
require.Equal(t, len(webhookKINDConfig), written)

clusterBuilder := kind.NewBuilder()
clusterBuilder.WithConfig(configFile.Name())
if clusterVersionStr != "" {
clusterVersion, err := semver.ParseTolerant(clusterVersionStr)
require.NoError(t, err)
clusterBuilder.WithClusterVersion(clusterVersion)
}
cluster, err := clusterBuilder.Build(ctx)
require.NoError(t, err)
addons := []clusters.Addon{}
addons = append(addons, metallb.New())
if b, err := loadimage.NewBuilder().WithImage(imageLoad); err == nil {
addons = append(addons, b.Build())
}
builder := environments.NewBuilder().WithExistingCluster(cluster).WithAddons(addons...)
env, err := builder.Build(ctx)
require.NoError(t, err)

Expand Down Expand Up @@ -712,21 +692,8 @@ func TestMissingCRDsDontCrashTheController(t *testing.T) {
defer cancel()

t.Log("building test cluster and environment")
clusterBuilder := kind.NewBuilder()
if clusterVersionStr != "" {
clusterVersion, err := semver.ParseTolerant(clusterVersionStr)
require.NoError(t, err)
clusterBuilder.WithClusterVersion(clusterVersion)
}
cluster, err := clusterBuilder.Build(ctx)
builder, err := getEnvironmentBuilder(ctx)
require.NoError(t, err)
addons := []clusters.Addon{metallb.New()}

if b, err := loadimage.NewBuilder().WithImage(imageLoad); err == nil {
addons = append(addons, b.Build())
}

builder := environments.NewBuilder().WithExistingCluster(cluster).WithAddons(addons...)
env, err := builder.Build(ctx)
require.NoError(t, err)

Expand All @@ -739,7 +706,7 @@ func TestMissingCRDsDontCrashTheController(t *testing.T) {
t.Logf("%s failed, dumped diagnostics to %s", t.Name(), output)
}
}
assert.NoError(t, cluster.Cleanup(ctx))
assert.NoError(t, cleaner.Cleanup(ctx))
}()

t.Log("deploying kong components")
Expand Down
16 changes: 6 additions & 10 deletions test/e2e/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,15 +102,13 @@ func getEnvironmentBuilder(ctx context.Context) (*environments.Builder, error) {
func createDefaultKINDBuilder() *environments.Builder {
builder := environments.NewBuilder()
clusterBuilder := kind.NewBuilder()
if false { // condition on image loads
// TODO load image but refactored
}
if clusterVersionStr != "" {
clusterVersion := semver.MustParse(strings.TrimPrefix(clusterVersionStr, "v"))
clusterBuilder = clusterBuilder.WithClusterVersion(clusterVersion)
}
builder = builder.WithClusterBuilder(clusterBuilder)
builder = builder.WithAddons(metallb.New())
builder = builder.WithAddons(buildImageLoadAddons(imageLoad, kongImageLoad)...)
return builder
}

Expand All @@ -120,11 +118,9 @@ func createExistingKINDBuilder(name string) (*environments.Builder, error) {
if err != nil {
return nil, err
}
if false { // condition on image loads
// TODO load image but refactored
}
builder = builder.WithExistingCluster(cluster)
builder = builder.WithAddons(metallb.New())
builder = builder.WithAddons(buildImageLoadAddons(imageLoad, kongImageLoad)...)
return builder, nil
}

Expand Down Expand Up @@ -404,13 +400,13 @@ func killKong(ctx context.Context, t *testing.T, env environments.Environment, p
}

// buildImageLoadAddons creates addons to load KIC and kong images.
func buildImageLoadAddons(t *testing.T, images ...string) []clusters.Addon {
func buildImageLoadAddons(images ...string) []clusters.Addon {
addons := []clusters.Addon{}
for _, image := range images {
if image != "" {
t.Logf("load image %s", image)
b, err := loadimage.NewBuilder().WithImage(image)
require.NoError(t, err)
// https://github.com/Kong/kubernetes-testing-framework/issues/440 this error only occurs if image == ""
// it will eventually be removed from the WithImage return signature
b, _ := loadimage.NewBuilder().WithImage(image)
addons = append(addons, b.Build())
}
}
Expand Down
25 changes: 6 additions & 19 deletions test/e2e/kuma_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ import (

"github.com/kong/kubernetes-testing-framework/pkg/clusters"
"github.com/kong/kubernetes-testing-framework/pkg/clusters/addons/kuma"
"github.com/kong/kubernetes-testing-framework/pkg/clusters/addons/metallb"
"github.com/kong/kubernetes-testing-framework/pkg/environments"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
autoscalingv1 "k8s.io/api/autoscaling/v1"
Expand All @@ -26,15 +24,9 @@ func TestDeployAllInOneDBLESSKuma(t *testing.T) {
defer cancel()

t.Log("building test cluster and environment")
addons := []clusters.Addon{}
addons = append(addons, metallb.New())

addons = append(addons, buildImageLoadAddons(t, imageLoad, kongImageLoad)...)

addons = append(addons, kuma.New())

builder := setBuilderKubernetesVersion(t,
environments.NewBuilder().WithAddons(addons...), clusterVersionStr)
builder, err := getEnvironmentBuilder(ctx)
require.NoError(t, err)
builder = builder.WithAddons(kuma.New())
env, err := builder.Build(ctx)
require.NoError(t, err)

Expand Down Expand Up @@ -113,14 +105,9 @@ func TestDeployAllInOnePostgresKuma(t *testing.T) {
defer cancel()

t.Log("building test cluster and environment")
addons := []clusters.Addon{}
addons = append(addons, metallb.New())
addons = append(addons, kuma.New())

addons = append(addons, buildImageLoadAddons(t, imageLoad, kongImageLoad)...)

builder := setBuilderKubernetesVersion(t,
environments.NewBuilder().WithAddons(addons...), clusterVersionStr)
builder, err := getEnvironmentBuilder(ctx)
require.NoError(t, err)
builder = builder.WithAddons(kuma.New())
env, err := builder.Build(ctx)
require.NoError(t, err)
defer func() {
Expand Down

0 comments on commit eeb615e

Please sign in to comment.