Skip to content

Latest commit

 

History

History
44 lines (29 loc) · 1.9 KB

testing.md

File metadata and controls

44 lines (29 loc) · 1.9 KB

OCM Agent Operator Testing

Tests are playing a primary role and we take them seriously. It is expected from PRs to add, modify or delete tests on case by case scenario. To contribute you need to be familiar with:

  • Ginkgo - BDD Testing Framework for Go
  • Gomega - Matcher/assertion library

Prerequisites

Make sure that the tool dependencies are already in place. The ginkgo and mockgen binaries that are required for testing will be installed as part of tool dependencies.

Bootstrapping the tests

$ cd pkg/samplepackage
$ ginkgo bootstrap
$ ginkgo generate samplepackage.go

find .
./samplepackage.go
./samplepackage_suite_test.go
./samplepackage_test.go

How to run the tests

  • You can run the tests using make test or go test ./...

Writing tests

Mocking interfaces

This project makes use of GoMock to mock service interfaces. This comes with the mockgen utility which can be used to generate or re-generate mock interfaces that can be used to simulate the behaviour of an external dependency.

It is considered good practice to include a go generate directive above the interface which defines the specific mockgen command that will generate your mocked interface.

As an example, please see the controller-runtime client.

It is important that generating mocks be done via Boilerplate's build files, as this will ensure that the same version of mockgen is used that would be used during CI build pipeline process, which can have an impact on the content of the files that are built.

$ boilerplate/_lib/container-make generate