Skip to content
This repository has been archived by the owner on Oct 15, 2019. It is now read-only.

Separate unit test and integration tests #15

Merged
merged 1 commit into from
Nov 22, 2018
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
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,10 @@ check: $(GOLINT)

.PHONY: test
test:
@$(GO) test -short -v $(SOURCES_DIRS_GO) -coverprofile cover.out

.PHONY: integration
integration:
@$(GO) test -v $(SOURCES_DIRS_GO) -coverprofile cover.out

.PHONY: check
Expand Down
7 changes: 0 additions & 7 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ require (
github.com/imdario/mergo v0.3.6 // indirect
github.com/inconshreveable/mousetrap v1.0.0 // indirect
github.com/json-iterator/go v1.1.5 // indirect
github.com/kubernetes/kubernetes v1.12.1
github.com/kubic-project/kubic-init v0.0.0-20181029092444-8266cfbf30df
github.com/mattbaird/jsonpatch v0.0.0-20171005235357-81af80346b1a // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742 // indirect
Expand All @@ -35,7 +33,6 @@ require (
github.com/stevvooe/resumable v0.0.0-20180830230917-22b14a53ba50 // indirect
github.com/stretchr/testify v1.2.2 // indirect
github.com/ugorji/go v1.1.1 // indirect
github.com/yuroyoro/swalker v0.0.0-20160622113523-0a5950e9162f // indirect
go.uber.org/atomic v1.3.2 // indirect
go.uber.org/multierr v1.1.0 // indirect
go.uber.org/zap v1.9.1 // indirect
Expand All @@ -44,17 +41,13 @@ require (
golang.org/x/oauth2 v0.0.0-20181003184128-c57b0facaced // indirect
golang.org/x/sys v0.0.0-20181005133103-4497e2df6f9e // indirect
golang.org/x/time v0.0.0-20180412165947-fbb02b2291d2 // indirect
golang.org/x/tools v0.0.0-20181101071927-45ff765b4815 // indirect
google.golang.org/appengine v1.2.0 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
k8s.io/api v0.0.0-20180712090710-2d6f90ab1293
k8s.io/apiextensions-apiserver v0.0.0-20180808065829-408db4a50408 // indirect
k8s.io/apimachinery v0.0.0-20180621070125-103fd098999d
k8s.io/apiserver v0.0.0-20180808060109-1844acd6a035
k8s.io/client-go v0.0.0-20180806134042-1f13a808da65
k8s.io/code-generator v0.0.0-20181101090831-772c233fdd26 // indirect
k8s.io/gengo v0.0.0-20181019081622-7338e4bfd691 // indirect
k8s.io/klog v0.1.0
k8s.io/kube-openapi v0.0.0-20180928202339-9dfdf9be683f // indirect
k8s.io/kubernetes v1.11.3
k8s.io/utils v0.0.0-20180918230422-cd34563cd63c // indirect
Expand Down
124 changes: 0 additions & 124 deletions go.sum

This file was deleted.

4 changes: 4 additions & 0 deletions pkg/apis/kubic/v1beta1/registry_types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,17 @@ package v1beta1
import (
"testing"

"github.com/kubic-project/registries-operator/pkg/test"
"github.com/onsi/gomega"
"golang.org/x/net/context"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
)

func TestStorageRegistry(t *testing.T) {

test.SkipUnlessIntegrationTesting(t)

key := types.NamespacedName{
Name: "foo",
Namespace: "default",
Expand Down
36 changes: 23 additions & 13 deletions pkg/apis/kubic/v1beta1/v1beta1_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"path/filepath"
"testing"

"github.com/kubic-project/registries-operator/pkg/test"
"k8s.io/client-go/kubernetes/scheme"
"k8s.io/client-go/rest"
"sigs.k8s.io/controller-runtime/pkg/client"
Expand All @@ -33,24 +34,33 @@ var cfg *rest.Config
var c client.Client

func TestMain(m *testing.M) {
t := &envtest.Environment{
CRDDirectoryPaths: []string{filepath.Join("..", "..", "..", "..", "configs", "crds")},
}

err := SchemeBuilder.AddToScheme(scheme.Scheme)
if err != nil {
log.Fatal(err)
}
var t *envtest.Environment

if cfg, err = t.Start(); err != nil {
log.Fatal(err)
}
if test.ShouldRunIntegrationSetupAndTeardown(m) {
t = &envtest.Environment{
CRDDirectoryPaths: []string{filepath.Join("..", "..", "..", "..", "configs", "crds")},
}

err := SchemeBuilder.AddToScheme(scheme.Scheme)
if err != nil {
log.Fatal(err)
}

if c, err = client.New(cfg, client.Options{Scheme: scheme.Scheme}); err != nil {
log.Fatal(err)
if cfg, err = t.Start(); err != nil {
log.Fatal(err)
}

if c, err = client.New(cfg, client.Options{Scheme: scheme.Scheme}); err != nil {
log.Fatal(err)
}
}

code := m.Run()
t.Stop()

if test.ShouldRunIntegrationSetupAndTeardown(m) {
t.Stop()
}

os.Exit(code)
}
26 changes: 18 additions & 8 deletions pkg/controller/registry/registry_controller_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"testing"

"github.com/kubic-project/registries-operator/pkg/apis"
"github.com/kubic-project/registries-operator/pkg/test"
"github.com/onsi/gomega"
"k8s.io/client-go/kubernetes/scheme"
"k8s.io/client-go/rest"
Expand All @@ -35,18 +36,27 @@ import (
var cfg *rest.Config

func TestMain(m *testing.M) {
t := &envtest.Environment{
CRDDirectoryPaths: []string{filepath.Join("..", "..", "..", "config", "crds")},
}
apis.AddToScheme(scheme.Scheme)

var err error
if cfg, err = t.Start(); err != nil {
log.Fatal(err)
var t *envtest.Environment

if test.ShouldRunIntegrationSetupAndTeardown(m) {
t = &envtest.Environment{
CRDDirectoryPaths: []string{filepath.Join("..", "..", "..", "config", "crds")},
}
apis.AddToScheme(scheme.Scheme)

var err error
if cfg, err = t.Start(); err != nil {
log.Fatal(err)
}
}

code := m.Run()
t.Stop()

if test.ShouldRunIntegrationSetupAndTeardown(m) {
t.Stop()
}

os.Exit(code)
}

Expand Down
4 changes: 4 additions & 0 deletions pkg/controller/registry/registry_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import (
"sigs.k8s.io/controller-runtime/pkg/reconcile"

kubicv1beta1 "github.com/kubic-project/registries-operator/pkg/apis/kubic/v1beta1"
"github.com/kubic-project/registries-operator/pkg/test"
)

var c client.Client
Expand All @@ -42,6 +43,9 @@ var depKey = types.NamespacedName{Name: "foo-deployment", Namespace: "default"}
const timeout = time.Second * 5

func TestReconcile(t *testing.T) {

test.SkipUnlessIntegrationTesting(t)

g := gomega.NewGomegaWithT(t)
instance := &kubicv1beta1.Registry{ObjectMeta: metav1.ObjectMeta{Name: "foo", Namespace: "default"}}

Expand Down
37 changes: 37 additions & 0 deletions pkg/test/util.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* Copyright 2018 SUSE LINUX GmbH, Nuernberg, Germany..
*
* 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 test

import (
"flag"
"testing"
)

// SkipUnlessIntegrationTesting should skip this specific test if we are not running in integration
// testing mode
func SkipUnlessIntegrationTesting(t *testing.T) {
if testing.Short() {
t.SkipNow()
}
}

// ShouldRunIntegrationSetupAndTeardown should skip this specific test if we are not running in
// integration testing mode
func ShouldRunIntegrationSetupAndTeardown(m *testing.M) bool {
flag.Parse()
return !testing.Short()
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

I think that for avoiding this duplication we could create a common operator tools where we put common things.

Copy link
Contributor

@MalloZup MalloZup Nov 21, 2018

Choose a reason for hiding this comment

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

i am ok for this common library shared among operators. It could be test but other stuff too @inercia thoughts about this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree we should use same names. Now, I find SkipIfShort better than SkipIfNotIntegration because the later asumes not short == integration. But there are other usages for short, like skipping long running tests.