Skip to content

Commit

Permalink
Refactor tm integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Tim Schrodi committed Aug 28, 2019
1 parent 5046e46 commit 0be2bee
Show file tree
Hide file tree
Showing 19 changed files with 1,309 additions and 974 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ install-controller-local:

.PHONY: run-it-tests
run-it-tests:
@TM_NAMESPACE=${NS} TM_KUBECONFIG_PATH=${KUBECONFIG} GIT_COMMIT_SHA=${current_sha} ginkgo ./test/...
@TM_NAMESPACE=${NS} TM_KUBECONFIG_PATH=${KUBECONFIG} GIT_COMMIT_SHA=${current_sha} ginkgo ./test/validationwebhook -v -progress -- --namespace=""

.PHONY: code-gen
code-gen:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,54 @@
package garbagecollection_test

import (
"github.com/gardener/test-infra/test/framework"
"github.com/minio/minio-go"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"sigs.k8s.io/controller-runtime/pkg/log/zap"
"time"

"testing"
)

func TestValidationWebhook(t *testing.T) {
func TestGarbageCollection(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecs(t, "Garbage collection Integration Test Suite")
}

const (
InitializationTimeout = 20 * time.Minute
ClusterReadinessTimeout = 10 * time.Minute
MinioServiceReadinessTimeout = 5 * time.Minute
CleanupTimeout = 1 * time.Minute
)

var (
cfg *framework.Config
operation *framework.Operation
minioClient *minio.Client
minioBucket string
)

func init() {
cfg = framework.InitFlags(nil)
}

var _ = BeforeSuite(func() {
var err error

operation, err = framework.New(zap.LoggerTo(GinkgoWriter, true), cfg)
Expect(err).ToNot(HaveOccurred())
Expect(operation.WaitForClusterReadiness(ClusterReadinessTimeout)).ToNot(HaveOccurred())

osConfig, err := operation.WaitForMinioServiceReadiness(MinioServiceReadinessTimeout)
Expect(err).ToNot(HaveOccurred())

minioBucket = osConfig.BucketName
minioClient, err = minio.New(osConfig.Endpoint, osConfig.AccessKey, osConfig.SecretKey, false)
Expect(err).ToNot(HaveOccurred())
}, InitializationTimeout.Seconds())

var _ = AfterSuite(func() {
operation.AfterSuite()
}, CleanupTimeout.Seconds())
47 changes: 5 additions & 42 deletions test/controller/garbagecollection/garbagecollection_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,8 @@ import (
"fmt"
"github.com/gardener/gardener/pkg/utils/retry"
"net/http"
"os"
"time"

"github.com/gardener/test-infra/pkg/testmachinery"

"github.com/gardener/gardener/pkg/client/kubernetes"
"sigs.k8s.io/controller-runtime/pkg/client"

argov1 "github.com/argoproj/argo/pkg/apis/workflow/v1alpha1"
Expand All @@ -37,52 +33,19 @@ import (
"github.com/gardener/test-infra/test/utils"
)

var (
maxWaitTime = 300 * time.Second
)

var _ = Describe("Garbage collection tests", func() {

var (
commitSha string
namespace string
tmClient kubernetes.Interface
minioClient *minio.Client
minioBucket string
)

BeforeSuite(func() {
var err error
commitSha = os.Getenv("GIT_COMMIT_SHA")
tmKubeconfig := os.Getenv("TM_KUBECONFIG_PATH")
namespace = os.Getenv("TM_NAMESPACE")
minioEndpoint := os.Getenv("S3_ENDPOINT")

tmClient, err = kubernetes.NewClientFromFile("", tmKubeconfig, client.Options{
Scheme: testmachinery.TestMachineryScheme,
})
Expect(err).ToNot(HaveOccurred())

Expect(utils.WaitForClusterReadiness(tmClient, namespace, maxWaitTime)).ToNot(HaveOccurred())
osConfig, err := utils.WaitForMinioService(tmClient, minioEndpoint, namespace, maxWaitTime)
Expect(err).ToNot(HaveOccurred())

minioBucket = osConfig.BucketName
minioClient, err = minio.New(osConfig.Endpoint, osConfig.AccessKey, osConfig.SecretKey, false)
Expect(err).ToNot(HaveOccurred())
})

It("should cleanup all artifacts when a TestDef is deleted", func() {
ctx := context.Background()
defer ctx.Done()
tr := resources.GetBasicTestrun(namespace, commitSha)
tr := resources.GetBasicTestrun(operation.TestNamespace(), operation.Commit())

tr, wf, err := utils.RunTestrun(ctx, tmClient, tr, argov1.NodeSucceeded, namespace, maxWaitTime)
tr, wf, err := utils.RunTestrun(ctx, operation.Client(), tr, argov1.NodeSucceeded, operation.TestNamespace(), InitializationTimeout)
Expect(err).ToNot(HaveOccurred())
utils.DeleteTestrun(tmClient, tr)
utils.DeleteTestrun(operation.Client(), tr)

err = retry.UntilTimeout(ctx, 5*time.Second, maxWaitTime, func(ctx context.Context) (bool, error) {
if err := tmClient.Client().Get(ctx, client.ObjectKey{Namespace: namespace, Name: tr.Name}, tr); err != nil {
err = retry.UntilTimeout(ctx, 5*time.Second, InitializationTimeout, func(ctx context.Context) (bool, error) {
if err := operation.Client().Client().Get(ctx, client.ObjectKey{Namespace: operation.TestNamespace(), Name: tr.Name}, tr); err != nil {
if errors.IsNotFound(err) {
return retry.Ok()
}
Expand Down
72 changes: 17 additions & 55 deletions test/controller/locations/locations_locationset_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,78 +16,40 @@ package locations_test

import (
"context"
"github.com/gardener/test-infra/pkg/testmachinery"
"os"
"testing"
"time"

"github.com/gardener/gardener/pkg/client/kubernetes"

"sigs.k8s.io/controller-runtime/pkg/client"

argov1 "github.com/argoproj/argo/pkg/apis/workflow/v1alpha1"
tmv1beta1 "github.com/gardener/test-infra/pkg/apis/testmachinery/v1beta1"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"

"github.com/gardener/test-infra/test/resources"
"github.com/gardener/test-infra/test/utils"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)

var (
maxWaitTime = 300 * time.Second
)

var (
commitSha string
namespace string
tmClient kubernetes.Interface
)

func TestTestflowWebhook(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecs(t, "Testrun locations Integration Test Suite")
}

var _ = Describe("Locations LocationSets tests", func() {

BeforeSuite(func() {
var err error
commitSha = os.Getenv("GIT_COMMIT_SHA")
tmKubeconfig := os.Getenv("TM_KUBECONFIG_PATH")
namespace = os.Getenv("TM_NAMESPACE")

tmClient, err = kubernetes.NewClientFromFile("", tmKubeconfig, client.Options{
Scheme: testmachinery.TestMachineryScheme,
})
Expect(err).ToNot(HaveOccurred())
Expect(utils.WaitForClusterReadiness(tmClient, namespace, maxWaitTime)).ToNot(HaveOccurred())
})

Context("LocationSets", func() {
It("should run a test with one location set and a specific default location", func() {
ctx := context.Background()
defer ctx.Done()
tr := resources.GetBasicTestrun(namespace, commitSha)
tr := resources.GetBasicTestrun(operation.TestNamespace(), operation.Commit())

tr, _, err := utils.RunTestrun(ctx, tmClient, tr, argov1.NodeSucceeded, namespace, maxWaitTime)
defer utils.DeleteTestrun(tmClient, tr)
tr, _, err := utils.RunTestrun(ctx, operation.Client(), tr, argov1.NodeSucceeded, operation.TestNamespace(), InitializationTimeout)
defer utils.DeleteTestrun(operation.Client(), tr)
Expect(err).ToNot(HaveOccurred())

})

It("should use the first location set as default", func() {
ctx := context.Background()
defer ctx.Done()
tr := resources.GetBasicTestrun(namespace, commitSha)
tr := resources.GetBasicTestrun(operation.TestNamespace(), operation.Commit())
tr.Spec.LocationSets = []tmv1beta1.LocationSet{
{
Name: "default",
Locations: []tmv1beta1.TestLocation{
{
Type: tmv1beta1.LocationTypeGit,
Repo: "https://github.com/gardener/test-infra.git",
Revision: commitSha,
Revision: operation.Commit(),
},
},
},
Expand All @@ -103,15 +65,15 @@ var _ = Describe("Locations LocationSets tests", func() {
},
}

tr, _, err := utils.RunTestrun(ctx, tmClient, tr, argov1.NodeSucceeded, namespace, maxWaitTime)
defer utils.DeleteTestrun(tmClient, tr)
tr, _, err := utils.RunTestrun(ctx, operation.Client(), tr, argov1.NodeSucceeded, operation.TestNamespace(), InitializationTimeout)
defer utils.DeleteTestrun(operation.Client(), tr)
Expect(err).ToNot(HaveOccurred())
})

It("should use the second location set as default", func() {
ctx := context.Background()
defer ctx.Done()
tr := resources.GetBasicTestrun(namespace, commitSha)
tr := resources.GetBasicTestrun(operation.TestNamespace(), operation.Commit())
tr.Spec.LocationSets = []tmv1beta1.LocationSet{
{
Name: "non-default",
Expand All @@ -130,14 +92,14 @@ var _ = Describe("Locations LocationSets tests", func() {
{
Type: tmv1beta1.LocationTypeGit,
Repo: "https://github.com/gardener/test-infra.git",
Revision: commitSha,
Revision: operation.Commit(),
},
},
},
}

tr, _, err := utils.RunTestrun(ctx, tmClient, tr, argov1.NodeSucceeded, namespace, maxWaitTime)
defer utils.DeleteTestrun(tmClient, tr)
tr, _, err := utils.RunTestrun(ctx, operation.Client(), tr, argov1.NodeSucceeded, operation.TestNamespace(), InitializationTimeout)
defer utils.DeleteTestrun(operation.Client(), tr)
Expect(err).ToNot(HaveOccurred())
})
})
Expand All @@ -148,7 +110,7 @@ var _ = Describe("Locations LocationSets tests", func() {
defer ctx.Done()

setName := "default"
tr := resources.GetBasicTestrun(namespace, commitSha)
tr := resources.GetBasicTestrun(operation.TestNamespace(), operation.Commit())
tr.Spec.LocationSets = []tmv1beta1.LocationSet{
{
Name: "non-default",
Expand All @@ -166,15 +128,15 @@ var _ = Describe("Locations LocationSets tests", func() {
{
Type: tmv1beta1.LocationTypeGit,
Repo: "https://github.com/gardener/test-infra.git",
Revision: commitSha,
Revision: operation.Commit(),
},
},
},
}
tr.Spec.TestFlow[0].Definition.LocationSet = &setName

tr, _, err := utils.RunTestrun(ctx, tmClient, tr, argov1.NodeSucceeded, namespace, maxWaitTime)
defer utils.DeleteTestrun(tmClient, tr)
tr, _, err := utils.RunTestrun(ctx, operation.Client(), tr, argov1.NodeSucceeded, operation.TestNamespace(), InitializationTimeout)
defer utils.DeleteTestrun(operation.Client(), tr)
Expect(err).ToNot(HaveOccurred())
})
})
Expand Down
55 changes: 55 additions & 0 deletions test/controller/locations/locations_suite_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// Copyright 2019 Copyright (c) 2019 SAP SE or an SAP affiliate company. All rights reserved. This file is licensed under the Apache Software License, v. 2 except as noted otherwise in the LICENSE file.
//
// 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
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package locations_test

import (
"github.com/gardener/test-infra/test/framework"
"sigs.k8s.io/controller-runtime/pkg/log/zap"
"testing"
"time"

. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)

func TestLocations(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecs(t, "Testrun locations Integration Test Suite")
}

const (
InitializationTimeout = 10 * time.Minute
CleanupTimeout = 1 * time.Minute
)

var (
cfg *framework.Config
operation *framework.Operation
)

func init() {
cfg = framework.InitFlags(nil)
}

var _ = BeforeSuite(func() {
var err error
operation, err = framework.New(zap.LoggerTo(GinkgoWriter, true), cfg)
Expect(err).ToNot(HaveOccurred())
Expect(operation.WaitForClusterReadiness(InitializationTimeout)).ToNot(HaveOccurred())
})

var _ = AfterSuite(func() {
operation.AfterSuite()
}, CleanupTimeout.Seconds())
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,18 @@ var _ = Describe("Locations TestLocations tests", func() {
It("should run a test with a TestLocations", func() {
ctx := context.Background()
defer ctx.Done()
tr := resources.GetBasicTestrun(namespace, commitSha)
tr := resources.GetBasicTestrun(operation.TestNamespace(), operation.Commit())
tr.Spec.LocationSets = nil
tr.Spec.TestLocations = []tmv1beta1.TestLocation{
{
Type: tmv1beta1.LocationTypeGit,
Repo: "https://github.com/gardener/test-infra.git",
Revision: commitSha,
Revision: operation.Commit(),
},
}

tr, _, err := utils.RunTestrun(ctx, tmClient, tr, tmv1beta1.PhaseStatusSuccess, namespace, maxWaitTime)
defer utils.DeleteTestrun(tmClient, tr)
tr, _, err := utils.RunTestrun(ctx, operation.Client(), tr, tmv1beta1.PhaseStatusSuccess, operation.TestNamespace(), InitializationTimeout)
defer utils.DeleteTestrun(operation.Client(), tr)
Expect(err).ToNot(HaveOccurred())
})
})
Loading

0 comments on commit 0be2bee

Please sign in to comment.