diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index ca34cf2..92a794d 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -51,9 +51,9 @@ test: script: - go test $(go list ./... | grep -v /e2e_tests) -v -coverprofile coverage.cov - # exclude Mock files from coverage report - - cat coverage.cov | grep -v Mock.go > coverage.cov || true - - go tool cover -func=coverage.cov - - go tool cover -html=coverage.cov -o coverage_unit.html + - cat coverage.cov | grep -v Mock.go > coverage_cleaned.cov || true + - go tool cover -func=coverage_cleaned.cov + - go tool cover -html=coverage_cleaned.cov -o coverage_unit.html artifacts: paths: - coverage_unit.html diff --git a/README.md b/README.md index 2f97ea9..f3106bc 100644 --- a/README.md +++ b/README.md @@ -88,8 +88,36 @@ $ openssl req -x509 -nodes -newkey rsa:2048 -keyout server.rsa.key -out server.r ## Tests -As testing framework we use the [testify](https://github.com/stretchr/testify) toolkit. -For mocks we use [mockery](https://github.com/vektra/mockery). -With Mockery, you can create mocks by running `mockery -r --name=<>` on a specific interface. -If the interface changes, you can rerun this command. +As testing framework we use the [testify](https://github.com/stretchr/testify) toolkit. + For e2e tests we provide a separate package. E2e tests require the connection to a Nomad cluster. + +### Mocks + +For mocks we use [mockery](https://github.com/vektra/mockery). To generate a mock, first navigate to the package the interface is defined in. +You can then create a mock for the interface of your choice by running + +```bash +mockery \ + --name=<> \ + --structname=<>Mock \ + --filename=<>Mock.go \ + --output=<> \ + --outpkg=<> +``` +on a specific interface. + +For example, for an interface called `ExecutorApi` in the package `nomad`, you might run + +```bash +mockery \ + --name=ExecutorApi \ + --output='.' \ + --structname=ExecutorApiMock \ + --filename=ExecutorApiMock.go \ + --outpkg=nomad +``` + +Note that the default value for `--output` is `./mocks` and the default for `--outpkg` is `mocks`. This will create the mock in a `mocks` sub-folder. However, in some cases (if the mock implements private interface methods), it needs to be in the same package as the interface it is mocking. + +If the interface changes, you can rerun this command.