Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make sure to call ctx.cleanup if prepare() fails #389

Merged
merged 1 commit into from
May 3, 2019
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
7 changes: 6 additions & 1 deletion test/e2e/all_in_one_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,12 @@ type AllInOneTestSuite struct {

func(suite *AllInOneTestSuite) SetupSuite() {
t = suite.T()
ctx = prepare(t)
var err error
ctx, err = prepare(t)
if (err != nil) {
ctx.Cleanup()
require.FailNow(t, "Failed in prepare")
}
fw = framework.Global
namespace, _ = ctx.GetNamespace()
require.NotNil(t, namespace, "GetNamespace failed")
Expand Down
7 changes: 6 additions & 1 deletion test/e2e/cassandra.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"testing"

"github.com/stretchr/testify/require"
framework "github.com/operator-framework/operator-sdk/pkg/test"
"github.com/operator-framework/operator-sdk/pkg/test/e2eutil"
log "github.com/sirupsen/logrus"
Expand All @@ -15,7 +16,11 @@ import (

// Cassandra runs a test with Cassandra as the backing storage
func Cassandra(t *testing.T) {
ctx := prepare(t)
ctx, err := prepare(t)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we call prepare in the caller so each test would not have to repeat this block?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pavolloffay Once I finish the other changes I am making for reporting it will be called in the Setup method, only once per suite. https://github.com/jaegertracing/jaeger-operator/blob/master/test/e2e/all_in_one_test.go#L36-L44

I've run into this bug a few times though, so I wanted to get this done first.

if (err != nil) {
ctx.Cleanup()
require.FailNow(t, "Failed in prepare")
}
defer ctx.Cleanup()

if err := cassandraTest(t, framework.Global, ctx); err != nil {
Expand Down
7 changes: 6 additions & 1 deletion test/e2e/daemonset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,12 @@ type DaemonSetTestSuite struct {

func(suite *DaemonSetTestSuite) SetupSuite() {
t = suite.T()
ctx = prepare(t)
var err error
ctx, err = prepare(t)
if (err != nil) {
ctx.Cleanup()
require.FailNow(t, "Failed in prepare")
}
fw = framework.Global
namespace, _ = ctx.GetNamespace()
require.NotNil(t, namespace, "GetNamespace failed")
Expand Down
7 changes: 6 additions & 1 deletion test/e2e/es_index_cleaner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"strings"
"testing"

"github.com/stretchr/testify/require"
framework "github.com/operator-framework/operator-sdk/pkg/test"
"github.com/operator-framework/operator-sdk/pkg/test/e2eutil"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand All @@ -17,7 +18,11 @@ import (
)

func EsIndexCleaner(t *testing.T) {
testCtx := prepare(t)
testCtx, err := prepare(t)
if (err != nil) {
ctx.Cleanup()
require.FailNow(t, "Failed in prepare")
}
defer testCtx.Cleanup()
if err := esIndexCleanerTest(t, framework.Global, testCtx); err != nil {
t.Fatal(err)
Expand Down
7 changes: 6 additions & 1 deletion test/e2e/production_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"testing"

"github.com/stretchr/testify/require"
framework "github.com/operator-framework/operator-sdk/pkg/test"
"github.com/operator-framework/operator-sdk/pkg/test/e2eutil"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand All @@ -13,7 +14,11 @@ import (
)

func SimpleProd(t *testing.T) {
ctx := prepare(t)
ctx, err := prepare(t)
if (err != nil) {
ctx.Cleanup()
require.FailNow(t, "Failed in prepare")
}
defer ctx.Cleanup()

if err := simpleProd(t, framework.Global, ctx); err != nil {
Expand Down
7 changes: 6 additions & 1 deletion test/e2e/self_provisioned_elasticsearch.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"fmt"
"testing"

"github.com/stretchr/testify/require"
framework "github.com/operator-framework/operator-sdk/pkg/test"
"github.com/operator-framework/operator-sdk/pkg/test/e2eutil"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand All @@ -14,7 +15,11 @@ import (
)

func SelfProvisionedESSmokeTest(t *testing.T) {
ctx := prepare(t)
ctx, err := prepare(t)
if (err != nil) {
ctx.Cleanup()
require.FailNow(t, "Failed in prepare")
}
defer ctx.Cleanup()

if err := selfProvisionedESSmokeTest(t, framework.Global, ctx); err != nil {
Expand Down
7 changes: 6 additions & 1 deletion test/e2e/sidecar_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,12 @@ type SidecarTestSuite struct {

func(suite *SidecarTestSuite) SetupSuite() {
t = suite.T()
ctx = prepare(t)
var err error
ctx, err = prepare(t)
if (err != nil) {
ctx.Cleanup()
require.FailNow(t, "Failed in prepare")
}
fw = framework.Global
namespace, _ = ctx.GetNamespace()
require.NotNil(t, namespace, "GetNamespace failed")
Expand Down
7 changes: 6 additions & 1 deletion test/e2e/simplest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"testing"

"github.com/stretchr/testify/require"
framework "github.com/operator-framework/operator-sdk/pkg/test"
"github.com/operator-framework/operator-sdk/pkg/test/e2eutil"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand All @@ -13,7 +14,11 @@ import (
)

func SimplestJaeger(t *testing.T) {
ctx := prepare(t)
ctx, err := prepare(t)
if (err != nil) {
ctx.Cleanup()
require.FailNow(t, "Failed in prepare")
}
defer ctx.Cleanup()

if err := simplest(t, framework.Global, ctx); err != nil {
Expand Down
13 changes: 11 additions & 2 deletions test/e2e/spark_dependencies_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"testing"

"github.com/stretchr/testify/require"
framework "github.com/operator-framework/operator-sdk/pkg/test"
"github.com/operator-framework/operator-sdk/pkg/test/e2eutil"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand All @@ -13,7 +14,11 @@ import (
)

func SparkDependenciesElasticsearch(t *testing.T) {
testCtx := prepare(t)
testCtx, err := prepare(t)
if (err != nil) {
testCtx.Cleanup()
require.FailNow(t, "Failed in prepare")
}
defer testCtx.Cleanup()
storage := v1.JaegerStorageSpec{
Type: "elasticsearch",
Expand All @@ -27,7 +32,11 @@ func SparkDependenciesElasticsearch(t *testing.T) {
}

func SparkDependenciesCassandra(t *testing.T) {
testCtx := prepare(t)
testCtx, err := prepare(t)
if (err != nil) {
testCtx.Cleanup()
require.FailNow(t, "Failed in prepare")
}
defer testCtx.Cleanup()

storage := v1.JaegerStorageSpec{
Expand Down
18 changes: 9 additions & 9 deletions test/e2e/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,19 @@ import (
"testing"
"time"

"github.com/stretchr/testify/assert"
"k8s.io/client-go/discovery"
"k8s.io/client-go/rest"
osv1 "github.com/openshift/api/route/v1"
osv1sec "github.com/openshift/api/security/v1"
framework "github.com/operator-framework/operator-sdk/pkg/test"
"github.com/operator-framework/operator-sdk/pkg/test/e2eutil"
"github.com/stretchr/testify/assert"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
osv1 "github.com/openshift/api/route/v1"
osv1sec "github.com/openshift/api/security/v1"
"k8s.io/client-go/discovery"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/rest"

"github.com/jaegertracing/jaeger-operator/pkg/apis/jaegertracing/v1"
"github.com/jaegertracing/jaeger-operator/pkg/apis"
"github.com/jaegertracing/jaeger-operator/pkg/apis/jaegertracing/v1"
)

var (
Expand Down Expand Up @@ -52,7 +52,7 @@ func GetPod(namespace, namePrefix, containsImage string, kubeclient kubernetes.I
return corev1.Pod{}, fmt.Errorf("could not find pod with image %s", containsImage)
}

func prepare(t *testing.T) *framework.TestCtx {
func prepare(t *testing.T) (*framework.TestCtx, error) {
ctx := framework.NewTestCtx(t)
err := ctx.InitializeClusterResources(&framework.CleanupOptions{TestContext: ctx, Timeout: timeout, RetryInterval: retryInterval})
if err != nil {
Expand All @@ -70,10 +70,10 @@ func prepare(t *testing.T) *framework.TestCtx {
// wait for the operator to be ready
err = e2eutil.WaitForDeployment(t, f.KubeClient, namespace, "jaeger-operator", 1, retryInterval, timeout)
if err != nil {
t.Fatal(err)
return nil, err
}

return ctx
return ctx, nil
}

func isOpenShift(t *testing.T) bool {
Expand Down