Building and Testing

So you want to build your own Maesh binary from the sources? Let’s see how.

Building

To build Maesh from the sources you need either Docker and make, or Go.

With Docker and make

Maesh can be built from the sources by using the make command. This will create a binary for the Linux platform in the dist directory and a Docker image:

  1. $ make
  2. #[...]
  3. Successfully tagged containous/maesh:latest
  4. docker run --name=build -t "containous/maesh:latest" version
  5. version:
  6. version : 04789a3
  7. commit : 04789a3
  8. build date : 2020-04-09_10:24:49AM
  9. go version : go1.14.1
  10. go compiler : gc
  11. platform : linux/amd64
  12. #[...]
  13. $ ls dist/
  14. maesh

Note

The default make target invokes the clean, check, test and build targets.

With Go

Requirements:

  • Go v1.14+
  • Environment variable GO111MODULE=on

One your Go environment is set up, you can build Maesh from the sources by using the go build command. The Go compiler will build an executable for your platform.

  1. $ go build -o dist/maesh cmd/maesh/*.go
  2. $ ./dist/maesh version
  3. version:
  4. version : dev
  5. commit : I don't remember exactly
  6. build date : I don't remember exactly
  7. go version : go1.14.1
  8. go compiler : gc
  9. platform : darwin/amd64

Testing

With Docker and make

Run unit tests by using the test target:

  1. $ make test
  2. docker build --tag "containous/maesh:test" --target maker --build-arg="MAKE_TARGET=local-test" /home/user/maesh/
  3. #[...]
  4. --- PASS: TestBuildConfiguration (0.00s)
  5. --- PASS: TestBuildConfiguration/simple_configuration_build_with_HTTP_service (0.20s)
  6. PASS
  7. coverage: 69.7% of statements
  8. ok github.com/containous/maesh/pkg/providers/smi 1.982s coverage: 69.7% of statements
  9. ? github.com/containous/maesh/pkg/signals [no test files]
  10. Removing intermediate container 4e887c16ddee
  11. ---> 75d44229a46e
  12. Successfully built 75d44229a46e
  13. Successfully tagged containous/maesh:test

Run the integration tests by using the test-integration target. For development purposes, you can specify which tests to run by using the TESTFLAGS environment variable (only works with the test-integration target):

  1. # Run every tests in the MyTest suite
  2. $ TESTFLAGS="-check.f MyTestSuite" make test-integration
  3. # Run the test "MyTest" in the MyTest suite
  4. $ TESTFLAGS="-check.f MyTestSuite.MyTest" make test-integration
  5. # Run every tests starting with "My", in the MyTest suite
  6. $ TESTFLAGS="-check.f MyTestSuite.My" make test-integration
  7. # Run every tests ending with "Test", in the MyTest suite
  8. $ TESTFLAGS="-check.f MyTestSuite.*Test" make test-integration

More on https://labix.org/gocheck.

With Go

Run the unit tests by using the go test command:

  1. $ go test -v ./...
  2. #[...]
  3. === RUN TestGroupTrafficTargetsByDestination
  4. --- PASS: TestGroupTrafficTargetsByDestination (0.20s)
  5. === RUN TestBuildConfiguration
  6. === RUN TestBuildConfiguration/simple_configuration_build_with_HTTP_service
  7. === PAUSE TestBuildConfiguration/simple_configuration_build_with_HTTP_service
  8. === CONT TestBuildConfiguration/simple_configuration_build_with_HTTP_service
  9. time="2020-04-09T16:09:16+04:00" level=debug msg="Found traffictargets for service default/demo-service: [0xc0009004e0]"
  10. time="2020-04-09T16:09:16+04:00" level=debug msg="Found applicable traffictargets for service default/demo-service: [0xc0009004e0]"
  11. time="2020-04-09T16:09:16+04:00" level=debug msg="Found grouped traffictargets for service default/demo-service: map[{name:api-service namespace:default port:}:[0xc000900820]]"
  12. time="2020-04-09T16:09:16+04:00" level=debug msg="No TrafficSplits in namespace: default"
  13. time="2020-04-09T16:09:16+04:00" level=debug msg="Found trafficsplits for service default/demo-service: []"
  14. --- PASS: TestBuildConfiguration (0.00s)
  15. --- PASS: TestBuildConfiguration/simple_configuration_build_with_HTTP_service (0.21s)
  16. PASS
  17. ok github.com/containous/maesh/pkg/providers/smi 3.634s
  18. ? github.com/containous/maesh/pkg/signals [no test files]

Run the integration tests in the integration directory by using the go test ./integration -integration command:

  1. $ go test -v ./integration -integration -check.f HelmSuite
  2. #[...]
  3. OK: 2 passed
  4. --- PASS: Test (161.20s)
  5. PASS
  6. ok github.com/containous/maesh/integration 162.695s

Important

Before running the integration tests, build the Maesh Docker image. Check out the Building section for more details.