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

Add initial test structure. #3

Merged
merged 21 commits into from
Oct 29, 2019
Merged

Add initial test structure. #3

merged 21 commits into from
Oct 29, 2019

Conversation

mpereira
Copy link
Contributor

@mpereira mpereira commented Oct 18, 2019

To run tests: ./tests/run.sh (or ./run-tests.sh if you don't have a Go environment set up).

Example run:

$ ./tests/run.sh
+++ dirname ./tests/run.sh
++ cd ./tests
++ pwd
+ readonly SCRIPT_DIRECTORY=/Users/murilo/mesosphere/kudo-cassandra-operator/tests
+ SCRIPT_DIRECTORY=/Users/murilo/mesosphere/kudo-cassandra-operator/tests
++ readlink -f /Users/murilo/mesosphere/kudo-cassandra-operator/tests/..
+ readonly PROJECT_DIRECTORY=/Users/murilo/mesosphere/kudo-cassandra-operator
+ PROJECT_DIRECTORY=/Users/murilo/mesosphere/kudo-cassandra-operator
+ source /Users/murilo/mesosphere/kudo-cassandra-operator/metadata.sh
++++ dirname /Users/murilo/mesosphere/kudo-cassandra-operator/metadata.sh
+++ cd /Users/murilo/mesosphere/kudo-cassandra-operator
+++ pwd
++ script_directory=/Users/murilo/mesosphere/kudo-cassandra-operator
+++ readlink -f /Users/murilo/mesosphere/kudo-cassandra-operator
++ project_directory=/Users/murilo/mesosphere/kudo-cassandra-operator
++ export PROJECT_NAME=kudo-cassandra-operator
++ PROJECT_NAME=kudo-cassandra-operator
++ export OPERATOR_NAME=cassandra
++ OPERATOR_NAME=cassandra
++ export OPERATOR_VERSION=0.1.0
++ OPERATOR_VERSION=0.1.0
++ export OPERATOR_DIRECTORY=/Users/murilo/mesosphere/kudo-cassandra-operator/operator
++ OPERATOR_DIRECTORY=/Users/murilo/mesosphere/kudo-cassandra-operator/operator
++ export VENDOR_DIRECTORY=/Users/murilo/mesosphere/kudo-cassandra-operator/shared/vendor
++ VENDOR_DIRECTORY=/Users/murilo/mesosphere/kudo-cassandra-operator/shared/vendor
++ export CASSANDRA_VERSION=3.11.4
++ CASSANDRA_VERSION=3.11.4
++ export KUDO_VERSION=0.7.4
++ KUDO_VERSION=0.7.4
++ export KUBERNETES_VERSION=1.15.0
++ KUBERNETES_VERSION=1.15.0
++ export CASSANDRA_DOCKER_IMAGE_NAMESPACE=mesosphere
++ CASSANDRA_DOCKER_IMAGE_NAMESPACE=mesosphere
++ export CASSANDRA_DOCKER_IMAGE_NAME=cassandra
++ CASSANDRA_DOCKER_IMAGE_NAME=cassandra
++ export CASSANDRA_DOCKER_IMAGE_TAG=0.1.0-3.11.4
++ CASSANDRA_DOCKER_IMAGE_TAG=0.1.0-3.11.4
++ export CASSANDRA_DOCKER_IMAGE=mesosphere/cassandra:0.1.0-3.11.4
++ CASSANDRA_DOCKER_IMAGE=mesosphere/cassandra:0.1.0-3.11.4
++ export INTEGRATION_TESTS_DOCKER_IMAGE=golang:1.13.1-stretch
++ INTEGRATION_TESTS_DOCKER_IMAGE=golang:1.13.1-stretch
+ export KUBECONFIG=/Users/murilo/.kube/config
+ KUBECONFIG=/Users/murilo/.kube/config
+ export OPERATOR_DIRECTORY=/Users/murilo/mesosphere/kudo-cassandra-operator/operator
+ OPERATOR_DIRECTORY=/Users/murilo/mesosphere/kudo-cassandra-operator/operator
+ export VENDOR_DIRECTORY=/Users/murilo/mesosphere/kudo-cassandra-operator/shared/vendor
+ VENDOR_DIRECTORY=/Users/murilo/mesosphere/kudo-cassandra-operator/shared/vendor
+ export KUBECTL_PATH=/Users/murilo/mesosphere/kudo-cassandra-operator/shared/vendor/kubectl.sh
+ KUBECTL_PATH=/Users/murilo/mesosphere/kudo-cassandra-operator/shared/vendor/kubectl.sh
+ export DS_KUDO_VERSION=v0.7.4
+ DS_KUDO_VERSION=v0.7.4
+ '[' -n '' ']'
+ export GINKGO_PATH=/Users/murilo/go/bin/ginkgo
+ GINKGO_PATH=/Users/murilo/go/bin/ginkgo
+ export PATH=/Users/murilo/mesosphere/kudo-cassandra-operator/shared/vendor:/Users/murilo/.yarn/bin:/Users/murilo/.config/yarn/global/node_modules/.bin:/usr/local/opt/gettext/bin:/usr/local/opt/gnu-getopt/bin:/usr/local/opt/coreutils/libexec/gnubin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/TeX/texbin:/usr/local/go/bin:/opt/X11/bin:/Users/murilo/.yarn/bin:/Users/murilo/.config/yarn/global/node_modules/.bin:/usr/local/opt/gnu-getopt/bin:/usr/local/opt/coreutils/libexec/gnubin:/Applications/Emacs-26.3.app/Contents/MacOS/bin-x86_64-10_14:/Applications/Emacs-26.3.app/Contents/MacOS/libexec-x86_64-10_14:/opt/local/bin:/Applications/Postgres.app/Contents/Versions/latest/bin:/Applications/CMake.app/Contents/bin:/Users/murilo/Library/Python/3.7/bin:/Library/Frameworks/Python.framework/Versions/3.7/bin:/Users/murilo/.go/bin:/Users/murilo/.cargo/bin:/Applications/MacVim.app/Contents/bin:/Applications/GraalVM-19.0.2.app/Contents/Home/bin:/Users/murilo/mesosphere/bin:/usr/local/bin:/opt/local/bin:/Applications/Postgres.app/Contents/Versions/latest/bin:/Applications/CMake.app/Contents/bin:/Users/murilo/Library/Python/3.7/bin:/Library/Frameworks/Python.framework/Versions/3.7/bin:/usr/local/go/bin:/Users/murilo/.go/bin:/Users/murilo/.cargo/bin:/Applications/MacVim.app/Contents/bin:/Applications/GraalVM-19.0.2.app/Contents/Home/bin:/Users/murilo/mesosphere/bin
+ PATH=/Users/murilo/mesosphere/kudo-cassandra-operator/shared/vendor:/Users/murilo/.yarn/bin:/Users/murilo/.config/yarn/global/node_modules/.bin:/usr/local/opt/gettext/bin:/usr/local/opt/gnu-getopt/bin:/usr/local/opt/coreutils/libexec/gnubin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/TeX/texbin:/usr/local/go/bin:/opt/X11/bin:/Users/murilo/.yarn/bin:/Users/murilo/.config/yarn/global/node_modules/.bin:/usr/local/opt/gnu-getopt/bin:/usr/local/opt/coreutils/libexec/gnubin:/Applications/Emacs-26.3.app/Contents/MacOS/bin-x86_64-10_14:/Applications/Emacs-26.3.app/Contents/MacOS/libexec-x86_64-10_14:/opt/local/bin:/Applications/Postgres.app/Contents/Versions/latest/bin:/Applications/CMake.app/Contents/bin:/Users/murilo/Library/Python/3.7/bin:/Library/Frameworks/Python.framework/Versions/3.7/bin:/Users/murilo/.go/bin:/Users/murilo/.cargo/bin:/Applications/MacVim.app/Contents/bin:/Applications/GraalVM-19.0.2.app/Contents/Home/bin:/Users/murilo/mesosphere/bin:/usr/local/bin:/opt/local/bin:/Applications/Postgres.app/Contents/Versions/latest/bin:/Applications/CMake.app/Contents/bin:/Users/murilo/Library/Python/3.7/bin:/Library/Frameworks/Python.framework/Versions/3.7/bin:/usr/local/go/bin:/Users/murilo/.go/bin:/Users/murilo/.cargo/bin:/Applications/MacVim.app/Contents/bin:/Applications/GraalVM-19.0.2.app/Contents/Home/bin:/Users/murilo/mesosphere/bin
+ cd /Users/murilo/mesosphere/kudo-cassandra-operator/tests
+ go mod edit -require github.com/kudobuilder/[email protected]
+ go install github.com/onsi/ginkgo/ginkgo
+ /Users/murilo/mesosphere/kudo-cassandra-operator/shared/vendor/kubectl.sh kudo version
KUDO Version: version.Info{GitVersion:"0.7.4", GitCommit:"81b14cb3", BuildDate:"2019-10-11T16:44:30Z", GoVersion:"go1.13.1", Compiler:"gc", Platform:"darwin/amd64"}
+ /Users/murilo/go/bin/ginkgo ./suites/...
Running Suite: simple-install-uninstall-test
============================================
Random Seed: 1571923335
Will run 2 of 2 specs

time="2019-10-24T15:22:20+02:00" level=info msg="Configuring kubectl using config file '/Users/murilo/.kube/config' with context ''"
time="2019-10-24T15:22:20+02:00" level=info msg="Using kubeconfig at '/Users/murilo/.kube/config'"
time="2019-10-24T15:22:20+02:00" level=info msg="Uninstalling 'cassandra' (instance='cassandra-instance', namespace='simple-install-uninstall-test-namespace')"
time="2019-10-24T15:22:25+02:00" level=info msg="exit status: 0\nstdout:\n\nstderr:\nError from server (NotFound): instances.kudo.dev \"cassandra-instance\" not found\nError from server (NotFound): operatorversions.kudo.dev \"cassandra-0.1.0\" not found\nError from server (NotFound): operators.kudo.dev \"cassandra\" not found\n"
time="2019-10-24T15:22:25+02:00" level=info msg="Successfully uninstalled 'cassandra' (instance='cassandra-instance', namespace='simple-install-uninstall-test-namespace')"
time="2019-10-24T15:22:25+02:00" level=info msg="Creating namespace 'simple-install-uninstall-test-namespace'"
time="2019-10-24T15:22:26+02:00" level=info msg="Created namespace 'simple-install-uninstall-test-namespace'"
time="2019-10-24T15:22:26+02:00" level=info msg="Installing operator from path: '/Users/murilo/mesosphere/kudo-cassandra-operator/operator' (instance='cassandra-instance', namespace='simple-install-uninstall-test-namespace')"
time="2019-10-24T15:22:30+02:00" level=info msg="exit status: 0\nstdout:\ninstance.kudo.dev/v1alpha1/cassandra-instance created\n\n\nstderr:\n"
time="2019-10-24T15:22:30+02:00" level=info msg="Started operator installation from path: '/Users/murilo/mesosphere/kudo-cassandra-operator/operator' (instance='cassandra-instance', namespace='simple-install-uninstall-test-namespace')"
time="2019-10-24T15:22:30+02:00" level=info msg="Operator (instance='cassandra-instance', namespace='simple-install-uninstall-test-namespace') deploy status is 'IN_PROGRESS'"
time="2019-10-24T15:22:31+02:00" level=info msg="Waiting for operator (instance='cassandra-instance', namespace='simple-install-uninstall-test-namespace') deploy status to be 'COMPLETE', is 'IN_PROGRESS'"
time="2019-10-24T15:22:41+02:00" level=info msg="Waiting for operator (instance='cassandra-instance', namespace='simple-install-uninstall-test-namespace') deploy status to be 'COMPLETE', is 'IN_PROGRESS'"
time="2019-10-24T15:22:51+02:00" level=info msg="Waiting for operator (instance='cassandra-instance', namespace='simple-install-uninstall-test-namespace') deploy status to be 'COMPLETE', is 'IN_PROGRESS'"
time="2019-10-24T15:23:01+02:00" level=info msg="Waiting for operator (instance='cassandra-instance', namespace='simple-install-uninstall-test-namespace') deploy status to be 'COMPLETE', is 'IN_PROGRESS'"
time="2019-10-24T15:23:11+02:00" level=info msg="Waiting for operator (instance='cassandra-instance', namespace='simple-install-uninstall-test-namespace') deploy status to be 'COMPLETE', is 'IN_PROGRESS'"
time="2019-10-24T15:23:21+02:00" level=info msg="Waiting for operator (instance='cassandra-instance', namespace='simple-install-uninstall-test-namespace') deploy status to be 'COMPLETE', is 'IN_PROGRESS'"
time="2019-10-24T15:23:32+02:00" level=info msg="Operator (instance='cassandra-instance', namespace='simple-install-uninstall-test-namespace') deploy status is 'COMPLETE'"
• [SLOW TEST:65.716 seconds]
simple-install-uninstall-test
/Users/murilo/mesosphere/kudo-cassandra-operator/tests/suites/simple_install_uninstall_test.go:35
  Installs the operator from a directory
  /Users/murilo/mesosphere/kudo-cassandra-operator/tests/suites/simple_install_uninstall_test.go:36
------------------------------
time="2019-10-24T15:23:32+02:00" level=info msg="Uninstalling 'cassandra' (instance='cassandra-instance', namespace='simple-install-uninstall-test-namespace')"
time="2019-10-24T15:23:52+02:00" level=info msg="exit status: 0\nstdout:\ninstance.kudo.dev \"cassandra-instance\" deleted\noperatorversion.kudo.dev \"cassandra-0.1.0\" deleted\noperator.kudo.dev \"cassandra\" deleted\npersistentvolumeclaim \"var-lib-cassandra-cassandra-instance-node-0\" deleted\npersistentvolumeclaim \"var-lib-cassandra-cassandra-instance-node-1\" deleted\npersistentvolumeclaim \"var-lib-cassandra-cassandra-instance-node-2\" deleted\n\nstderr:\n"
time="2019-10-24T15:23:52+02:00" level=info msg="Successfully uninstalled 'cassandra' (instance='cassandra-instance', namespace='simple-install-uninstall-test-namespace')"
• [SLOW TEST:20.102 seconds]
simple-install-uninstall-test
/Users/murilo/mesosphere/kudo-cassandra-operator/tests/suites/simple_install_uninstall_test.go:35
  Uninstalls the operator
  /Users/murilo/mesosphere/kudo-cassandra-operator/tests/suites/simple_install_uninstall_test.go:44
------------------------------
time="2019-10-24T15:23:52+02:00" level=info msg="Deleting namespace 'simple-install-uninstall-test-namespace'"
time="2019-10-24T15:23:53+02:00" level=info msg="Deleted namespace 'simple-install-uninstall-test-namespace'"

Ran 2 of 2 Specs in 93.214 seconds
SUCCESS! -- 2 Passed | 0 Failed | 0 Pending | 0 Skipped
PASS

Ginkgo ran 1 suite in 1m37.941930753s
Test Suite Passed

@mpereira mpereira force-pushed the initial-test-structure branch 3 times, most recently from 1eff034 to b8fe450 Compare October 18, 2019 21:37
@mpereira mpereira force-pushed the initial-test-structure branch 3 times, most recently from 167fd0f to d5b9563 Compare October 24, 2019 12:29
Copy link

@samvantran samvantran left a comment

Choose a reason for hiding this comment

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

Code looks great! You might want to ask Marcin to take a look at this PR as he's got a sharp eye for shell scripts and could offer better feedback wrt Golang/k8s!

Not too many comments my side. Locally though, I did run into 1 test failure myself when I gave the tests/run.sh.

  • edit: nvm me, I'm dumb and didn't k kudo init first though I had figured that would be taken care of based on this line

Anyhow, tests worked!

Ran 2 of 2 Specs in 106.554 seconds
SUCCESS! -- 2 Passed | 0 Failed | 0 Pending | 0 Skipped
PASS

But it's worth pointing out that default konvoy cluster size was not adequate to run tests. I had to add another 3 free nodes to account for the cassandra nodes cpu requirements as the konvoy addons take up a pretty big amount of space.

&metav1.DeleteOptions{},
)
if err != nil {
log.Warnf("Error deleting namespace '%s': %s", namespaceName, err)

Choose a reason for hiding this comment

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

Might want to add retrying and make this a Fatal error. Not successfully deleting a namespace can result in subsequent test failures.

See kudo-spark PR d2iq-archive/kudo-spark-operator#32

Copy link
Contributor

@zmalik zmalik Oct 25, 2019

Choose a reason for hiding this comment

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

Instead of a fatal, we should return err and handle the error
tests should be failing with a clear reason and using log.Fatalf inside tests can lead to test terminate abruptly where it's hard to understand what happened. As we will only see that namespace deletion was failed. Instead of that t.Fatalf is preferred that will mark the test as failed. Or even better are the asserts that are being used in these tests.

But we don't need it here to obscure the code execution with fatals, and here its would be even simpler and understandable with
Expect(k8s.DeleteNamespace(TestNamespace)).To(BeNil())

On the other side of test structure re-using namespace shouldn't be the way to go for testing unless we are testing to re-use the namespace

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agree with returning and handling error vs using fatal, from a library perspective it makes more sense imo.

Regarding re-using namespaces, my idea is to create namespaces based on the test module name, like in the simple-install-uninstall-test.

Choose a reason for hiding this comment

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

@akirillov @rpalaznik, perhaps this approach should be done in kudo-spark?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The general ideas for this testing structure are in the proposal document I shared earlier if you haven't seen it yet.

@mpereira mpereira force-pushed the initial-test-structure branch 3 times, most recently from e9e1242 to c9a0f68 Compare October 28, 2019 18:12
@mpereira
Copy link
Contributor Author

Check failed on CI cluster teardown flake. Merging.

@mpereira mpereira merged commit 87e2067 into master Oct 29, 2019
@mpereira mpereira deleted the initial-test-structure branch October 29, 2019 13:47
mpereira added a commit that referenced this pull request Oct 29, 2019
* Create initial testing structure and tests.

* Build docker image.

* Format with `goimports -w .`.

* Get operator name from environment variable.

* Script improvements.

* Document command for building Docker images.

* Add usage to uninstall_operator.sh script.

* Add tooling to check formatting and format go code.

* Update data-services-kudo module to the latest master.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants