Skip to content

Commit

Permalink
Merge pull request #151 from Mania-c/issues-147
Browse files Browse the repository at this point in the history
issues-147: add description to tests
  • Loading branch information
fetinin authored Jan 9, 2023
2 parents 95be036 + 28fbd0d commit 53a1c84
Show file tree
Hide file tree
Showing 9 changed files with 29 additions and 1 deletion.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,7 @@ Also, "?" in query is optional
You can use variables in the description of the test, the following fields are supported:

- method
- description
- path
- query
- headers
Expand All @@ -349,6 +350,7 @@ Example:

```yaml
- method: "{{ $method }}"
description: "{{ $description }}"
path: "/some/path/{{ $pathPart }}"
query: "{{ $query }}"
headers:
Expand Down
1 change: 1 addition & 0 deletions models/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ type TestInterface interface {
GetResponse(code int) (string, bool)
GetResponseHeaders(code int) (map[string]string, bool)
GetName() string
GetDescription() string
GetStatus() string
SetStatus(string)
Fixtures() []string
Expand Down
2 changes: 2 additions & 0 deletions output/allure_report/allure_report.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ func NewOutput(suiteName, reportLocation string) *AllureReportOutput {

func (o *AllureReportOutput) Process(t models.TestInterface, result *models.Result) error {
testCase := o.allure.StartCase(t.GetName(), time.Now())
testCase.SetDescriptionOrDefaultValue(t.GetDescription(), "No description")
testCase.AddLabel("story", result.Path)

o.allure.AddAttachment(
*bytes.NewBufferString("Request"),
*bytes.NewBufferString(fmt.Sprintf(`Query: %s \n Body: %s`, result.Query, result.RequestBody)),
Expand Down
8 changes: 8 additions & 0 deletions output/allure_report/beans/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,14 @@ func (t *TestCase) SetDescription(desc string) {
t.Desc = desc
}

func (t *TestCase) SetDescriptionOrDefaultValue(desc string, defVal string) {
if desc == "" {
t.Desc = defVal
} else {
t.Desc = desc
}
}

func (t *TestCase) AddLabel(name, value string) {
t.addLabel(&Label{
Name: name,
Expand Down
2 changes: 2 additions & 0 deletions output/console_colored/console_colored.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ func (o *ConsoleColoredOutput) Process(t models.TestInterface, result *models.Re
func renderResult(result *models.Result) (string, error) {
text := `
Name: {{ green .Test.GetName }}
Description:
{{- if .Test.GetDescription }}{{ green .Test.GetDescription }}{{ else }}{{ green " No description" }}{{ end }}
File: {{ green .Test.GetFileName }}
Request:
Expand Down
2 changes: 2 additions & 0 deletions output/testing/testing.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ func (o *TestingOutput) Process(t models.TestInterface, result *models.Result) e
func renderResult(result *models.Result) (string, error) {
text := `
Name: {{ .Test.GetName }}
Description:
{{- if .Test.GetDescription }}{{ .Test.GetDescription }}{{ else }}{{ " No description" }}{{ end }}
File: {{ .Test.GetFileName }}
Request:
Expand Down
7 changes: 6 additions & 1 deletion testloader/yaml_file/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ func makeTestFromDefinition(filePath string, testDefinition TestDefinition) ([]T
// test definition has no cases, so using request/response as is
if len(testDefinition.Cases) == 0 {
test := Test{TestDefinition: testDefinition, Filename: filePath}
test.Description = testDefinition.Description
test.Request = testDefinition.RequestTmpl
test.Responses = testDefinition.ResponseTmpls
test.ResponseHeaders = testDefinition.ResponseHeaders
Expand Down Expand Up @@ -121,7 +122,11 @@ func makeTestFromDefinition(filePath string, testDefinition TestDefinition) ([]T
// produce as many tests as cases defined
for caseIdx, testCase := range testDefinition.Cases {
test := Test{TestDefinition: testDefinition, Filename: filePath}
test.Name = fmt.Sprintf("%s #%d", test.Name, caseIdx)
test.Name = fmt.Sprintf("%s #%d", test.Name, caseIdx+1)

if testCase.Description != "" {
test.Description = testCase.Description
}

// substitute RequestArgs to different parts of request
test.RequestURL, err = substituteArgs(requestURLTmpl, testCase.RequestArgs)
Expand Down
4 changes: 4 additions & 0 deletions testloader/yaml_file/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ func (t *Test) GetName() string {
return t.Name
}

func (t *Test) GetDescription() string {
return t.Description
}

func (t *Test) GetStatus() string {
return t.Status
}
Expand Down
2 changes: 2 additions & 0 deletions testloader/yaml_file/test_definition.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

type TestDefinition struct {
Name string `json:"name" yaml:"name"`
Description string `json:"description" yaml:"description"`
Status string `json:"status" yaml:"status"`
Variables map[string]string `json:"variables" yaml:"variables"`
VariablesToSet VariablesToSet `json:"variables_to_set" yaml:"variables_to_set"`
Expand Down Expand Up @@ -39,6 +40,7 @@ type CaseData struct {
DbQueryArgs map[string]interface{} `json:"dbQueryArgs" yaml:"dbQueryArgs"`
DbResponseArgs map[string]interface{} `json:"dbResponseArgs" yaml:"dbResponseArgs"`
DbResponse []string `json:"dbResponse" yaml:"dbResponse"`
Description string `json:"description" yaml:"description"`
Variables map[string]interface{} `json:"variables" yaml:"variables"`
}

Expand Down

0 comments on commit 53a1c84

Please sign in to comment.