diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 90949f3..93b3aa9 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -15,7 +15,7 @@ jobs: - name: Set up Go uses: actions/setup-go@v2 with: - go-version: 1.17 + go-version: 1.21 - name: Build run: go build -v ./... diff --git a/allure.go b/allure.go index 90432ae..75ff88c 100644 --- a/allure.go +++ b/allure.go @@ -11,15 +11,19 @@ func (qt *cute) setLinksAllure(t linksAllureProvider) { if qt.allureLinks.issue != "" { t.SetIssue(qt.allureLinks.issue) } + if qt.allureLinks.testCase != "" { t.SetTestCase(qt.allureLinks.testCase) } + if qt.allureLinks.link != nil { t.Link(qt.allureLinks.link) } + if qt.allureLinks.tmsLink != "" { t.TmsLink(qt.allureLinks.tmsLink) } + if len(qt.allureLinks.tmsLinks) > 0 { t.TmsLinks(qt.allureLinks.tmsLinks...) } @@ -29,48 +33,63 @@ func (qt *cute) setLabelsAllure(t labelsAllureProvider) { if qt.allureLabels.id != "" { t.ID(qt.allureLabels.id) } + if qt.allureLabels.suiteLabel != "" { t.AddSuiteLabel(qt.allureLabels.suiteLabel) } + if qt.allureLabels.subSuite != "" { t.AddSubSuite(qt.allureLabels.subSuite) } + if qt.allureLabels.parentSuite != "" { t.AddParentSuite(qt.allureLabels.parentSuite) } + if qt.allureLabels.story != "" { t.Story(qt.allureLabels.story) } + if qt.allureLabels.tag != "" { t.Tag(qt.allureLabels.tag) } + if qt.allureLabels.allureID != "" { t.AllureID(qt.allureLabels.allureID) } + if qt.allureLabels.severity != "" { t.Severity(qt.allureLabels.severity) } + if qt.allureLabels.owner != "" { t.Owner(qt.allureLabels.owner) } + if qt.allureLabels.lead != "" { t.Lead(qt.allureLabels.lead) } + if qt.allureLabels.label != nil { t.Label(qt.allureLabels.label) } + if len(qt.allureLabels.labels) != 0 { t.Labels(qt.allureLabels.labels...) } + if qt.allureLabels.feature != "" { t.Feature(qt.allureLabels.feature) } + if qt.allureLabels.epic != "" { t.Epic(qt.allureLabels.epic) } + if len(qt.allureLabels.tags) != 0 { t.Tags(qt.allureLabels.tags...) } + if qt.allureLabels.layer != "" { t.Layer(qt.allureLabels.layer) } @@ -80,9 +99,11 @@ func (qt *cute) setInfoAllure(t infoAllureProvider) { if qt.allureInfo.title != "" { t.Title(qt.allureInfo.title) } + if qt.allureInfo.description != "" { t.Description(qt.allureInfo.description) } + if qt.allureInfo.stage != "" { t.Stage(qt.allureInfo.stage) } diff --git a/asserts/json/util.go b/asserts/json/util.go index ed2c8d1..8e834dc 100644 --- a/asserts/json/util.go +++ b/asserts/json/util.go @@ -273,7 +273,9 @@ func isEmpty(object interface{}) bool { if objValue.IsNil() { return true } + deref := objValue.Elem().Interface() + return isEmpty(deref) case reflect.Array, reflect.Chan, reflect.Map, reflect.Slice: return objValue.Len() == 0 diff --git a/builder.go b/builder.go index ac51118..a27cb7d 100644 --- a/builder.go +++ b/builder.go @@ -30,6 +30,7 @@ type options struct { middleware *Middleware } +// Option ... type Option func(*options) // WithHTTPClient is a function for set custom http client diff --git a/builder_test.go b/builder_test.go index 455843d..eb57af7 100644 --- a/builder_test.go +++ b/builder_test.go @@ -179,7 +179,7 @@ func TestHTTPTestMaker(t *testing.T) { allureID = "AllureID" owner = "Owner" lead = "Lead" - label = &allure.Label{"kek", "lol"} + label = &allure.Label{Name: "kek", Value: "lol"} setIssue = "SetIssue" setTestCase = "SetTestCase" repeatCount = 10 @@ -354,10 +354,10 @@ func TestCreateDefaultTest(t *testing.T) { Name: "", AllureStep: new(AllureStep), Middleware: &Middleware{ - After: make([]AfterExecute, 0, 0), - AfterT: make([]AfterExecuteT, 0, 0), - Before: make([]BeforeExecute, 0, 0), - BeforeT: make([]BeforeExecuteT, 0, 0), + After: make([]AfterExecute, 0), + AfterT: make([]AfterExecuteT, 0), + Before: make([]BeforeExecute, 0), + BeforeT: make([]BeforeExecuteT, 0), }, Request: &Request{ Repeat: new(RequestRepeatPolitic), diff --git a/cute.go b/cute.go index 3a55fa1..31f6723 100644 --- a/cute.go +++ b/cute.go @@ -104,6 +104,7 @@ func createAllureT(t *testing.T) *common.Common { WithRunner(callers[0]) newProvider = manager.NewProvider(providerCfg) ) + newProvider.NewTest(t.Name(), "package") newT.SetProvider(newProvider) diff --git a/go.mod b/go.mod index 5747fa3..e14badb 100644 --- a/go.mod +++ b/go.mod @@ -1,13 +1,13 @@ module github.com/ozontech/cute -go 1.19 +go 1.21 require ( - github.com/josephburnett/jd v1.5.1 - github.com/ohler55/ojg v1.19.4 - github.com/ozontech/allure-go/pkg/allure v0.6.11 - github.com/ozontech/allure-go/pkg/framework v0.6.28 - github.com/stretchr/testify v1.7.1 + github.com/josephburnett/jd v1.7.1 + github.com/ohler55/ojg v1.21.1 + github.com/ozontech/allure-go/pkg/allure v0.6.12 + github.com/ozontech/allure-go/pkg/framework v0.6.29 + github.com/stretchr/testify v1.8.4 github.com/xeipuuv/gojsonschema v1.2.0 moul.io/http2curl/v2 v2.3.0 ) @@ -15,13 +15,14 @@ require ( require ( github.com/davecgh/go-spew v1.1.1 // indirect github.com/go-openapi/jsonpointer v0.19.5 // indirect - github.com/go-openapi/swag v0.19.5 // indirect + github.com/go-openapi/swag v0.21.1 // indirect github.com/google/uuid v1.3.0 // indirect - github.com/mailru/easyjson v0.0.0-20190626092158-b2ccc519800e // indirect + github.com/josharian/intern v1.0.0 // indirect + github.com/mailru/easyjson v0.7.7 // indirect github.com/pkg/errors v0.9.1 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect github.com/xeipuuv/gojsonpointer v0.0.0-20180127040702-4e3ac2762d5f // indirect github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 // indirect gopkg.in/yaml.v2 v2.4.0 // indirect - gopkg.in/yaml.v3 v3.0.0 // indirect + gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/go.sum b/go.sum index 6aa66cd..3444c6d 100644 --- a/go.sum +++ b/go.sum @@ -1,28 +1,36 @@ +github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/go-openapi/jsonpointer v0.19.5 h1:gZr+CIYByUqjcgeLXnQu2gHYQC9o73G2XUeOFYEICuY= github.com/go-openapi/jsonpointer v0.19.5/go.mod h1:Pl9vOtqEWErmShwVjC8pYs9cog34VGT37dQOVbmoatg= -github.com/go-openapi/swag v0.19.5 h1:lTz6Ys4CmqqCQmZPBlbQENR1/GucA2bzYTE12Pw4tFY= github.com/go-openapi/swag v0.19.5/go.mod h1:POnQmlKehdgb5mhVOsnJFsivZCEZ/vjK9gh66Z9tfKk= +github.com/go-openapi/swag v0.21.1 h1:wm0rhTb5z7qpJRHBdPOMuY4QjVUMbF6/kwoYeRAOrKU= +github.com/go-openapi/swag v0.21.1/go.mod h1:QYRuS/SOXUCsnplDa677K7+DxSOj6IPNl/eQntq43wQ= github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I= github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= -github.com/josephburnett/jd v1.5.1 h1:6V6C5rMl1RCea2EuufPuGS+rSfJetRXl//R5XJz19AA= -github.com/josephburnett/jd v1.5.1/go.mod h1:2pSZGHitQCumXDDTxmJehndlsltrTeVAhrzP8WfFeuc= -github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI= +github.com/josephburnett/jd v1.7.1 h1:oXBPMS+SNnILTMGj1fWLK9pexpeJUXtbVFfRku/PjBU= +github.com/josephburnett/jd v1.7.1/go.mod h1:R8ZnZnLt2D4rhW4NvBc/USTo6mzyNT6fYNIIWOJA9GY= +github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY= +github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= -github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= +github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= +github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= github.com/mailru/easyjson v0.0.0-20190614124828-94de47d64c63/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc= -github.com/mailru/easyjson v0.0.0-20190626092158-b2ccc519800e h1:hB2xlXdHp/pmPZq0y3QnmWAArdw9PqbmotexnWx/FU8= github.com/mailru/easyjson v0.0.0-20190626092158-b2ccc519800e/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc= -github.com/ohler55/ojg v1.19.4 h1:ZIgfyHI83aLx+fi1VoKn4I80HqWo45usWKnnxw94Mro= -github.com/ohler55/ojg v1.19.4/go.mod h1:uHcD1ErbErC27Zhb5Df2jUjbseLLcmOCo6oxSr3jZxo= -github.com/ozontech/allure-go/pkg/allure v0.6.11 h1:1g8jCTLSI7hcAQBXwMx8HoKaVwErRPcWqSrjVGgv+Nk= -github.com/ozontech/allure-go/pkg/allure v0.6.11/go.mod h1:4oEG2yq+DGOzJS/ZjPc87C/mx3tAnlYpYonk77Ru/vQ= -github.com/ozontech/allure-go/pkg/framework v0.6.28 h1:ZYPPtGDANRkbneo0lMvlM17xix1YO2jHgZu8iuIL9Q8= -github.com/ozontech/allure-go/pkg/framework v0.6.28/go.mod h1:aFyaKnv9vtiX5ZNaOJxwVA46glCsLNeueZDtmu3eGW0= +github.com/mailru/easyjson v0.7.6/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc= +github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0= +github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc= +github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e h1:fD57ERR4JtEqsWbfPhv4DMiApHyliiK5xCTNVSPiaAs= +github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno= +github.com/ohler55/ojg v1.21.1 h1:b2RLUaDcy9gvn46dmhTjezu/TDauoR0/kgKTqkwIxto= +github.com/ohler55/ojg v1.21.1/go.mod h1:gQhDVpQLqrmnd2eqGAvJtn+NfKoYJbe/A4Sj3/Vro4o= +github.com/ozontech/allure-go/pkg/allure v0.6.12 h1:O9VTf7fW9q/c9qKidQ3CGRCXBC4c8MR7NZW+oVm7Uz4= +github.com/ozontech/allure-go/pkg/allure v0.6.12/go.mod h1:4oEG2yq+DGOzJS/ZjPc87C/mx3tAnlYpYonk77Ru/vQ= +github.com/ozontech/allure-go/pkg/framework v0.6.29 h1:RzOXLMEg/O1K8+mqbKtorqqmlmEYtq94H4XH7aSvn14= +github.com/ozontech/allure-go/pkg/framework v0.6.29/go.mod h1:ZNUnhean4TKmDwHPX2Jwr3y/o0WTeyuXB9aKKRcyHBg= github.com/pkg/diff v0.0.0-20200914180035-5b29258ca4f7/go.mod h1:zO8QMzTeZd5cpnIkz/Gn6iK0jDfGicM1nynOkkPIl28= github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= @@ -32,8 +40,9 @@ github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAm github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= -github.com/stretchr/testify v1.7.1 h1:5TQK59W5E3v0r2duFAb7P95B6hEeOyEnHRa8MjYSMTY= -github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= +github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= github.com/tailscale/depaware v0.0.0-20210622194025-720c4b409502/go.mod h1:p9lPsd+cx33L3H9nNoecRRxPssFKUwwI50I3pZ0yT+8= github.com/xeipuuv/gojsonpointer v0.0.0-20180127040702-4e3ac2762d5f h1:J9EGpcZtP0E/raorCMxlFGSTBrsSlaDGf3jU/qvAE2c= github.com/xeipuuv/gojsonpointer v0.0.0-20180127040702-4e3ac2762d5f/go.mod h1:N2zxlSyiKSe5eX1tZViRH5QA0qijqEDrYZiPEAiq3wU= @@ -64,13 +73,15 @@ golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8T golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f h1:BLraFXnmrev5lT+xlilqcH8XK9/i0At2xKjWk4p6zsU= +gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= -gopkg.in/yaml.v3 v3.0.0 h1:hjy8E9ON/egN1tAYqKb61G10WtihqetD4sz2H+8nIeA= -gopkg.in/yaml.v3 v3.0.0/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gopkg.in/yaml.v3 v3.0.0-20200615113413-eeeca48fe776/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= moul.io/http2curl/v2 v2.3.0 h1:9r3JfDzWPcbIklMOs2TnIFzDYvfAZvjeavG6EzP7jYs= moul.io/http2curl/v2 v2.3.0/go.mod h1:RW4hyBjTWSYDOxapodpNEtX0g5Eb16sxklBqmd2RHcE= diff --git a/init.go b/init.go index ade1982..1f2410f 100644 --- a/init.go +++ b/init.go @@ -6,6 +6,8 @@ func init() { commonBuilder = NewHTTPTestMaker() } +// NewTestBuilder is function for create base test builder, +// For create custom test builder use NewHTTPTestMaker() func NewTestBuilder() AllureBuilder { return commonBuilder.NewTestBuilder() } diff --git a/interface.go b/interface.go index 0067b9a..bafe34b 100644 --- a/interface.go +++ b/interface.go @@ -21,6 +21,7 @@ type AllureBuilder interface { Parallel() AllureBuilder } +// AllureInfoBuilder ... type AllureInfoBuilder interface { // Title is a function for set title in allure information Title(title string) AllureBuilder @@ -32,6 +33,7 @@ type AllureInfoBuilder interface { Stagef(format string, args ...interface{}) AllureBuilder } +// AllureLinksBuilder ... type AllureLinksBuilder interface { SetIssue(issue string) AllureBuilder SetTestCase(testCase string) AllureBuilder @@ -40,6 +42,7 @@ type AllureLinksBuilder interface { TmsLinks(tmsLinks ...string) AllureBuilder } +// AllureLabelsBuilder ... type AllureLabelsBuilder interface { Feature(feature string) AllureBuilder Epic(epic string) AllureBuilder @@ -166,6 +169,7 @@ type RequestHTTPBuilder interface { RequestParams } +// RequestParams is a scope of methods for configurate http request type RequestParams interface { // RequestRepeat is a count of repeat request, if request was failed. RequestRepeat(count int) RequestHTTPBuilder diff --git a/internal/utils/body.go b/internal/utils/body.go index edaad71..8bcc2a5 100644 --- a/internal/utils/body.go +++ b/internal/utils/body.go @@ -6,6 +6,7 @@ import ( "net/http" ) +// GetBody get body from IO func GetBody(body io.ReadCloser) ([]byte, error) { var ( err error @@ -20,6 +21,7 @@ func GetBody(body io.ReadCloser) ([]byte, error) { return buf.Bytes(), nil } +// DrainBody ... func DrainBody(body io.ReadCloser) (r1, r2 io.ReadCloser, err error) { if body == nil || body == http.NoBody { // No copying needed. Preserve the magic sentinel meaning of NoBody. @@ -27,9 +29,11 @@ func DrainBody(body io.ReadCloser) (r1, r2 io.ReadCloser, err error) { } var buf bytes.Buffer + if _, err = buf.ReadFrom(body); err != nil { return nil, body, err } + if err = body.Close(); err != nil { return nil, body, err } diff --git a/internal/utils/json.go b/internal/utils/json.go index 18fadf9..a82b6f8 100644 --- a/internal/utils/json.go +++ b/internal/utils/json.go @@ -8,12 +8,15 @@ import ( // ToJSON returns string Json representation of any object that can be marshaled. func ToJSON(v interface{}) (string, error) { j, err := json.Marshal(v) + return string(j), err } // PrettyJSON make indent to json byte array. Returns prettified json as []byte or error if is it impossible func PrettyJSON(b []byte) ([]byte, error) { var out bytes.Buffer + err := json.Indent(&out, b, "", " ") + return out.Bytes(), err } diff --git a/jsonschema.go b/jsonschema.go index 7eac1ad..bc9f004 100644 --- a/jsonschema.go +++ b/jsonschema.go @@ -32,6 +32,7 @@ func (it *Test) validateJSONSchema(t internalT, body []byte) []error { func checkJSONSchema(expect gojsonschema.JSONLoader, data []byte) []error { scope := make([]error, 0) + validateResult, err := gojsonschema.Validate(expect, gojsonschema.NewBytesLoader(data)) if err != nil { return []error{err} diff --git a/provider.go b/provider.go index 8bcb9a1..a901290 100644 --- a/provider.go +++ b/provider.go @@ -5,6 +5,7 @@ import ( "github.com/ozontech/allure-go/pkg/framework/provider" ) +// T is internal testing.T provider type T interface { tProvider logProvider diff --git a/request.go b/request.go index 57eb395..e2821d4 100644 --- a/request.go +++ b/request.go @@ -4,6 +4,7 @@ import ( "net/url" ) +// RequestBuilder ... type RequestBuilder func(o *requestOptions) // File is struct for upload file in form field diff --git a/roundtripper.go b/roundtripper.go index 5966887..490fd0e 100644 --- a/roundtripper.go +++ b/roundtripper.go @@ -47,6 +47,7 @@ func (it *Test) makeRequest(t internalT, req *http.Request) (*http.Response, []e } scope = append(scope, err) + if i != countRepeat { time.Sleep(delay) } @@ -84,7 +85,7 @@ func (it *Test) doRequest(t T, baseReq *http.Request) (*http.Response, error) { // Add information (code, body, headers) about response to Allure step addInformationResponse(t, resp) - if validErr := it.validateResponseCode(t, resp); validErr != nil { + if validErr := it.validateResponseCode(resp); validErr != nil { return nil, validErr } } @@ -92,7 +93,7 @@ func (it *Test) doRequest(t T, baseReq *http.Request) (*http.Response, error) { return resp, nil } -func (it *Test) validateResponseCode(t T, resp *http.Response) error { +func (it *Test) validateResponseCode(resp *http.Response) error { if it.Expect.Code != 0 && it.Expect.Code != resp.StatusCode { return cuteErrors.NewAssertError( "Assert response code", @@ -194,6 +195,7 @@ func addInformationResponse(t T, response *http.Response) { if err != nil { return } + body, err := utils.GetBody(saveBody) // if could not get body from response, no add to allure if err != nil { @@ -206,6 +208,7 @@ func addInformationResponse(t T, response *http.Response) { } responseType := allure.Text + if _, ok := response.Header["Content-Type"]; ok { if len(response.Header["Content-Type"]) > 0 { if strings.Contains(response.Header["Content-Type"][0], "application/json") { @@ -215,6 +218,7 @@ func addInformationResponse(t T, response *http.Response) { } } } + if responseType == allure.JSON { body, _ = utils.PrettyJSON(body) } diff --git a/test_test.go b/test_test.go index 32e89fc..f10fd86 100644 --- a/test_test.go +++ b/test_test.go @@ -4,7 +4,7 @@ import ( "bytes" "context" "errors" - "io/ioutil" + "io" "net/http" "net/url" "testing" @@ -39,7 +39,7 @@ func TestCreateRequestBuilder(t *testing.T) { url = "http://go.com" ) - req, err := http.NewRequest(http.MethodGet, url, ioutil.NopCloser(bytes.NewReader(body))) + req, err := http.NewRequest(http.MethodGet, url, io.NopCloser(bytes.NewReader(body))) require.NoError(t, err) req.Header = headers @@ -135,7 +135,7 @@ func TestValidateResponseWithErrors(t *testing.T) { }, AssertResponse: []AssertResponse{ func(response *http.Response) error { - if response.StatusCode != http.StatusOK || len(response.Header["auth"]) == 0 { + if response.StatusCode != http.StatusOK || len(response.Header["auth"]) == 0 { //nolint return errors.New("bad response") } return nil @@ -152,7 +152,7 @@ func TestValidateResponseWithErrors(t *testing.T) { "key": []string{"value"}, "auth": []string{"sometoken"}, }, - Body: ioutil.NopCloser(reader), + Body: io.NopCloser(reader), } )