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

Conversation

pablochacin
Copy link
Contributor

Skip tests that require environement sutup (e.g. k8s cluster)
when running tests in short mode. Add an additional 'integarion'
target to Makefile for running those tests.

Signed-off-by: Pablo Chacin pchacin@suse.com

Copy link
Contributor

@MalloZup MalloZup left a comment

Choose a reason for hiding this comment

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

i would align with the same framework then all operators here.
https://github.com/kubic-project/dex-operator/blob/master/pkg/test/util.go#L18

(including name of functions, structure and pkg)

log.Print("Skipping tests in short mode")
}
os.Exit(0)
}
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.

@@ -33,6 +33,12 @@ var cfg *rest.Config
var c client.Client

func TestMain(m *testing.M) {

if testing.Short() {
log.Print("Skippig integration tests in short mode")
Copy link
Contributor

Choose a reason for hiding this comment

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

Typo, Skipping, and double space.


if testing.Short() {
log.Print("Skippig integration tests in short mode")
return
Copy link
Contributor

Choose a reason for hiding this comment

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

This return does not do what we expect. If you are in testing.Short() it will skip the whole test suite, and you just want to run this suite because unit tests could exist inside (https://github.com/kubic-project/dex-operator/blob/master/pkg/apis/kubic/v1beta1/v1beta1_suite_test.go#L38-L65)


test.SkipSetupIfShort(m)

log.Print("Still here")
Copy link
Contributor

Choose a reason for hiding this comment

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

This should be removed.

@@ -35,6 +36,11 @@ import (
var cfg *rest.Config

func TestMain(m *testing.M) {

test.SkipSetupIfShort(m)
Copy link
Contributor

@ereslibre ereslibre Nov 21, 2018

Choose a reason for hiding this comment

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

We should only avoid start the integration control plane in the suite test, but really execute m.Run so all tests that are not skipped within are actually executed.

Something like: https://github.com/kubic-project/dex-operator/blob/master/pkg/controller/dex/dex_controller_suite_test.go#L40-L60

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

func TestReconcile(t *testing.T) {

test.SkipTestIfShort(t)
Copy link
Contributor

Choose a reason for hiding this comment

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

Indentation is weird.

pkg/test/util.go Outdated
if testing.Short() {
log.Print("Skipping tests in short mode")
}
os.Exit(0)
Copy link
Contributor

Choose a reason for hiding this comment

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

Since m.Run() needs to be called, this os.Exit(0) will avoid that, and you could be skipping unit tests, because you won't reach m.Run() in TestMain in the suite test.

Aside from that, here we are always running os.Exit(0) :)

Copy link
Contributor

@ereslibre ereslibre left a comment

Choose a reason for hiding this comment

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

Aside from the comments LGTM, good to merge

Makefile Outdated
@@ -167,6 +167,10 @@ check: $(GOLINT)

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

Choose a reason for hiding this comment

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

Minor: extra space before -v

@@ -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)
Copy link
Contributor

Choose a reason for hiding this comment

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

This indentation is weird.

@MalloZup
Copy link
Contributor

@pablochacin @ereslibre for the format things and syntax,

https://github.com/kubic-project/registries-operator/blob/e06cc9cdcb1b32b47a18e31ac10c6faae44bda2c/Makefile#L164

for the golint and fmt we should check really and make them fail. otherwise in all operator we are keeping reviewing syntax/lint thing which is a pain, it should be done automagically for this

@ereslibre
Copy link
Contributor

There's a conflict with go.sum, you can just remove this file as we did on the dex-operator for now and squash the commits and it should be good to go!

@ereslibre
Copy link
Contributor

for the golint and fmt we should check really and make them fail. otherwise in all operator we are keeping reviewing syntax/lint thing which is a pain, it should be done automagically for this

Yes, @pablochacin wants to make this changes in a different PR, I'm fine with that, once the conflict is resolved and commits squashed.

Copy link
Contributor

@ereslibre ereslibre left a comment

Choose a reason for hiding this comment

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

Looks great!

Skip tests that require environement sutup (e.g. k8s cluster)
when running tests in short mode. Add an additional 'integarion'
target to Makefile for running those tests.

Signed-off-by: Pablo Chacin <pchacin@suse.com>
@ereslibre ereslibre merged commit 321ac82 into master Nov 22, 2018
@ereslibre ereslibre deleted the separate-tests branch November 22, 2018 09:17
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants