/
allure_report.go
67 lines (58 loc) · 1.62 KB
/
allure_report.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package allure_report
import (
"bytes"
"fmt"
"os"
"path/filepath"
"time"
"github.com/lamoda/gonkey/models"
"github.com/lamoda/gonkey/output"
)
type AllureReportOutput struct {
output.OutputInterface
reportLocation string
allure Allure
}
func NewOutput(suiteName, reportLocation string) *AllureReportOutput {
resultsDir, _ := filepath.Abs(reportLocation)
if err := os.Mkdir(resultsDir, 0777); err != nil {
// likely dir is already exists
}
a := Allure{
Suites: nil,
TargetDir: resultsDir,
}
a.StartSuite(suiteName, time.Now())
return &AllureReportOutput{
reportLocation: reportLocation,
allure: a,
}
}
func (o *AllureReportOutput) Process(t models.TestInterface, result *models.Result) error {
testCase := o.allure.StartCase(t.GetName(), time.Now())
testCase.AddLabel("story", result.Path)
o.allure.AddAttachment(
*bytes.NewBufferString("Request"),
*bytes.NewBufferString(fmt.Sprintf(`Query: %s \n Body: %s`, result.Query, result.RequestBody)),
"txt")
o.allure.AddAttachment(
*bytes.NewBufferString("Response"),
*bytes.NewBufferString(fmt.Sprintf(`Body: %s`, result.ResponseBody)),
"txt")
if result.DbQuery != "" {
o.allure.AddAttachment(
*bytes.NewBufferString("Db Query"),
*bytes.NewBufferString(fmt.Sprintf(`SQL string: %s`, result.DbQuery)),
"txt")
o.allure.AddAttachment(
*bytes.NewBufferString("Db Response"),
*bytes.NewBufferString(fmt.Sprintf(`Respone: %s`, result.DbResponse)),
"txt")
}
status, err := result.AllureStatus()
o.allure.EndCase(status, err, time.Now())
return nil
}
func (o *AllureReportOutput) Finalize() {
o.allure.EndSuite(time.Now())
}