Commit 3071554d authored by Sean Erswell-Liljefelt's avatar Sean Erswell-Liljefelt
Browse files

feat(go_unit_test): add ability to customise test command

parent 1b0e5b25
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -21,3 +21,4 @@ Execute your golang unit tests and have the results fully integrated with the va
| Name | Description | Default |
| ---- | ----------- | ------- |
| `UT_WORK_DIR` | If for any reason (monorepo for example) your go project is not at root of project, specify the relative path to the project | `$CI_PROJECT_DIR` |
| `UT_TEST_CMD` | Customise the test command if needed | `go test -v` |
+2 −1
Original line number Diff line number Diff line
@@ -6,13 +6,14 @@ go_unit_test:
  image: golang:latest
  variables:
    UT_WORK_DIR: $CI_PROJECT_DIR
    UT_TEST_CMD: "go test -v"
  script:
    # Switch to working directory
    - cd "$UT_WORK_DIR"
    # Install job dependencies
    - go get -u github.com/jstemmer/go-junit-report github.com/t-yuki/gocover-cobertura
    # Execute Unit tests to get both the junit report and a coverage file
    - go test -v -coverprofile=coverage.out ./... 2>&1 | go-junit-report -set-exit-code > report.xml
    - "$UT_TEST_CMD" -coverprofile=coverage.out ./... 2>&1 | go-junit-report -set-exit-code > report.xml
    # Output the coverage to stdout for coverage regex to read
    - go tool cover -func=coverage.out
    # Capture coverage in cobertura format for MR highlighting