diff --git a/README.md b/README.md index 88e6cf5..ae7edf8 100644 --- a/README.md +++ b/README.md @@ -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 @@ -349,6 +350,7 @@ Example: ```yaml - method: "{{ $method }}" + description: "{{ $description }}" path: "/some/path/{{ $pathPart }}" query: "{{ $query }}" headers: diff --git a/models/test.go b/models/test.go index ff6b108..a81a715 100644 --- a/models/test.go +++ b/models/test.go @@ -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 diff --git a/output/allure_report/allure_report.go b/output/allure_report/allure_report.go index a0c52d8..bb15b0e 100644 --- a/output/allure_report/allure_report.go +++ b/output/allure_report/allure_report.go @@ -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)), diff --git a/output/allure_report/beans/test.go b/output/allure_report/beans/test.go index 1b1fe89..0729176 100644 --- a/output/allure_report/beans/test.go +++ b/output/allure_report/beans/test.go @@ -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, diff --git a/output/console_colored/console_colored.go b/output/console_colored/console_colored.go index 798b4d6..a23c669 100644 --- a/output/console_colored/console_colored.go +++ b/output/console_colored/console_colored.go @@ -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: diff --git a/output/testing/testing.go b/output/testing/testing.go index 7379f51..e345baf 100644 --- a/output/testing/testing.go +++ b/output/testing/testing.go @@ -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: diff --git a/testloader/yaml_file/parser.go b/testloader/yaml_file/parser.go index e73adc6..6f3bf50 100644 --- a/testloader/yaml_file/parser.go +++ b/testloader/yaml_file/parser.go @@ -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 @@ -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) diff --git a/testloader/yaml_file/test.go b/testloader/yaml_file/test.go index 3707ec2..06784de 100644 --- a/testloader/yaml_file/test.go +++ b/testloader/yaml_file/test.go @@ -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 } diff --git a/testloader/yaml_file/test_definition.go b/testloader/yaml_file/test_definition.go index 9f57697..06a1601 100644 --- a/testloader/yaml_file/test_definition.go +++ b/testloader/yaml_file/test_definition.go @@ -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"` @@ -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"` }