Skip to content

Commit

Permalink
Add allure formatter (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
vearutop committed Aug 17, 2021
1 parent 7be6c0d commit 6546d6f
Show file tree
Hide file tree
Showing 11 changed files with 541 additions and 15 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/gorelease.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
gorelease:
strategy:
matrix:
go-version: [ 1.16.x ]
go-version: [ 1.17.x ]
runs-on: ubuntu-latest
steps:
- name: Install Go
Expand Down Expand Up @@ -38,7 +38,7 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
header: gorelease
message: |
### Exported API Changes Report
### API Changes
<pre>
${{ steps.gorelease.outputs.report }}
Expand Down
12 changes: 6 additions & 6 deletions .github/workflows/test-unit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
test:
strategy:
matrix:
go-version: [ 1.13.x, 1.14.x, 1.15.x, 1.16.x ]
go-version: [ 1.13.x, 1.14.x, 1.15.x, 1.16.x, 1.17.x ]
runs-on: ubuntu-latest
steps:
- name: Install Go
Expand All @@ -35,21 +35,21 @@ jobs:
restore-keys: |
${{ runner.os }}-go-cache
- name: Restore base test coverage
if: matrix.go-version == '1.16.x'
if: matrix.go-version == '1.17.x'
uses: actions/cache@v2
with:
path: |
unit-base.txt
# Use base sha for PR or new commit hash for master/main push in test result key.
key: ${{ runner.os }}-unit-test-coverage-${{ (github.event.pull_request.base.sha != github.event.after) && github.event.pull_request.base.sha || github.event.after }}
- name: Checkout base code
if: matrix.go-version == '1.16.x' && env.RUN_BASE_COVERAGE == 'on' && steps.benchmark-base.outputs.cache-hit != 'true' && github.event.pull_request.base.sha != ''
if: matrix.go-version == '1.17.x' && env.RUN_BASE_COVERAGE == 'on' && steps.benchmark-base.outputs.cache-hit != 'true' && github.event.pull_request.base.sha != ''
uses: actions/checkout@v2
with:
ref: ${{ github.event.pull_request.base.sha }}
path: __base
- name: Run test for base code
if: matrix.go-version == '1.16.x' && env.RUN_BASE_COVERAGE == 'on' && steps.benchmark-base.outputs.cache-hit != 'true' && github.event.pull_request.base.sha != ''
if: matrix.go-version == '1.17.x' && env.RUN_BASE_COVERAGE == 'on' && steps.benchmark-base.outputs.cache-hit != 'true' && github.event.pull_request.base.sha != ''
run: |
cd __base
make | grep test-unit && (make test-unit && go tool cover -func=./unit.coverprofile | sed -e 's/.go:[0-9]*:\t/.go\t/g' | sed -e 's/\t\t*/\t/g' > ../unit-base.txt) || echo "No test-unit in base"
Expand All @@ -69,7 +69,7 @@ jobs:
if: ${{ github.ref == 'refs/heads/master' || github.ref == 'refs/heads/main' }}
run: cp unit.txt unit-base.txt
- name: Comment Test Coverage
if: matrix.go-version == '1.16.x'
if: matrix.go-version == '1.17.x'
uses: marocchino/sticky-pull-request-comment@v2
with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand All @@ -85,7 +85,7 @@ jobs:
</details>
- name: Upload code coverage
if: matrix.go-version == '1.16.x'
if: matrix.go-version == '1.17.x'
uses: codecov/codecov-action@v1
with:
file: ./unit.coverprofile
Expand Down
34 changes: 34 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,37 @@ failing scenarios.
skipped steps after the failure was encountered.

You can enable it by calling `godogx.RegisterPrettyFailedFormatter()`.

## Allure Formatter

[Allure](https://github.com/allure-framework/allure2) is convenient UI to expose test results.

You can enable it by calling `allure.RegisterFormatter()`.

Additional configuration can be added with env vars before test run.

`ALLURE_ENV_*` are added to allure environment report.

`ALLURE_EXECUTOR_*` configure `Executor` info.

`ALLURE_RESULTS_PATH` can change default `./allure-results` destination.

Example:
```bash
export ALLURE_ENV_TICKET=JIRA-1234
export ALLURE_ENV_APP=todo-list
export ALLURE_EXECUTOR_NAME=IntegrationTest
export ALLURE_EXECUTOR_TYPE=github
```

Then you can run test with
```bash
# Optionally clean up current result (if you have it).
rm -rf ./allure-results/*
# Optionally copy history from previous report.
cp -r ./allure-report/history ./allure-results/history
# Run suite with godog CLI tool or with go test.
godog -f allure
# Generate report with allure CLI tool.
allure generate --clean
```
33 changes: 33 additions & 0 deletions allure/allure_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package allure_test

import (
"bytes"
"errors"
"testing"

"github.com/bool64/godogx/allure"
"github.com/cucumber/godog"
"github.com/stretchr/testify/assert"
)

func TestRegister(t *testing.T) {
allure.RegisterFormatter()

out := bytes.NewBuffer(nil)

suite := godog.TestSuite{
ScenarioInitializer: func(s *godog.ScenarioContext) {
s.Step("I pass", func() {})
s.Step("I fail", func() error { return errors.New("failed") })
},
Options: &godog.Options{
Format: "allure",
Output: out,
NoColors: true,
Paths: []string{"../_testdata"},
},
}

st := suite.Run()
assert.Equal(t, 1, st) // Failed.
}
2 changes: 2 additions & 0 deletions allure/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// Package allure provides allure formatter for godog.
package allure
25 changes: 25 additions & 0 deletions allure/executor.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package allure

// Executor describes execution context.
type Executor struct {
Name string `json:"name,omitempty" example:"Jenkins"`
// Type may be one of [github, gitlab, teamcity, bamboo, jenkins] or a custom one.
Type string `json:"type,omitempty" example:"jenkins"`
URL string `json:"url,omitempty" example:"url"`
BuildOrder int `json:"buildOrder,omitempty" example:"13"`
BuildName string `json:"buildName,omitempty" example:"allure-report_deploy#13"`
BuildURL string `json:"buildUrl,omitempty" example:"http://example.org/build#13"`
ReportURL string `json:"reportUrl,omitempty" example:"http://example.org/build#13/AllureReport"`
ReportName string `json:"reportName,omitempty" example:"Demo allure report"`
}

//{
// "name": "Jenkins",
// "type": "jenkins",
// "url": "http://example.org",
// "buildOrder": 13,
// "buildName": "allure-report_deploy#13",
// "buildUrl": "http://example.org/build#13",
// "reportUrl": "http://example.org/build#13/AllureReport",
// "reportName": "Demo allure report"
//}
Loading

0 comments on commit 6546d6f

Please sign in to comment.