Skip to content

Latest commit

 

History

History
101 lines (73 loc) · 3.01 KB

testing.md

File metadata and controls

101 lines (73 loc) · 3.01 KB

Running end-to-end-tests

Setup

The user running the tests must have permission on the cluster to create CRDs. An example role binding setting for configuring the "developer" user is provided in test/e2e/role_binding.yaml

oc --as system:admin apply -f test/e2e/role_binding.yaml

Run the e2e tests

Run the tests using the operator-sdk command line tool

operator-sdk test local ./test/e2e --namespace operator-test --up-local --debug

If the setup steps above have already been run, causing "X already exists" errors, use the --no-setup option to skip that step in the test.

operator-sdk test local ./test/e2e --namespace operator-test --up-local --debug --no-setup

The tests can also be run via make

make test

Run linters test before pushing your commit

make lint

Using the Hack scripts

The repository contains a hack directory which has some very useful scripts for setting up containerized testing environments. It also has Dockerfiles to allow you to generate images for your own use.

All the scripts accept the CONTAINER_RUNTIME environment variable with default of podman. This you can edit to docker as well.

Example of running golint in a Docker container

  1. Start by setting the environment variable appropriately

    export CONTAINER_RUNTIME=docker
  2. From the operator parent dir, you can invoke the hack scripts

    ./hack/golint.sh

    Note It's important to be in the operator parent dir because it contains the Makefile that is used in running the tests for the operator. Otherwise, you'll see the following error

    sh: 0: Can't open /go/src/github.com/metal3-io/baremetal-operator/hack/golint.sh
  3. Upon successful execution, you should see the following output. I already had all the images available from a previous run, you might see the images getting downloaded if you're running for the very first time.

    + IS_CONTAINER=false
    + CONTAINER_RUNTIME=docker
    + [ false != false ]
    + docker run --rm --env IS_CONTAINER=TRUE --volume /home/noor/go/src/github.com/metal3-io/baremetal-operator:/go/src/github.com/metal3-io/baremetal-operator:ro,z\
    --entrypoint sh --workdir /go/src/github.com/metal3-io/baremetal-operator\
    quay.io/metal3-io/golint:latest /go/src/github.com/metal3-io/baremetal-operator/hack/golint.sh
    + IS_CONTAINER=TRUE
    + CONTAINER_RUNTIME=podman
    + [ TRUE != false ]
    + export XDG_CACHE_HOME=/tmp/.cache
    + make lint
    which golint 2>&1 >/dev/null || make OPATH/bin/golint
    find ./pkg ./cmd -type f -name \*.go  |grep -v zz_ | xargs -L1 golint -set_exit_status

Getting the latest tooling

For testing without the hack scripts, make sure you install the latest development tools using go get, e-g

go get golang.org/x/lint/golint

This ensures that the linters you have locally and the ones running in the CI are matched and helps avoid inconsistencies. Happy coding!