Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ISSUE-16] Add methods to hide data #82

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions builder_asserts.go
Original file line number Diff line number Diff line change
Expand Up @@ -367,3 +367,27 @@ func (qt *cute) ExpectJSONSchemaFile(filePath string) ExpectHTTPBuilder {

return qt
}

func (qt *cute) HideBody() ExpectHTTPBuilder {
qt.tests[qt.countTests].HideBody = true

return qt
}

func (qt *cute) HideHeaders() ExpectHTTPBuilder {
qt.tests[qt.countTests].HideHeaders = true

return qt
}

func (qt *cute) HideResponse() ExpectHTTPBuilder {
qt.tests[qt.countTests].HideResponse = true

return qt
}

func (qt *cute) HideResponseHeaders() ExpectHTTPBuilder {
qt.tests[qt.countTests].HideResponseHeaders = true

return qt
}
9 changes: 9 additions & 0 deletions interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,15 @@ type ExpectHTTPBuilder interface {
// Mark in allure as Broken
BrokenAssertResponseT(asserts ...AssertResponseT) ExpectHTTPBuilder

// HideBody is function for hide request body.
HideBody() ExpectHTTPBuilder
// HideHeaders is function for hide request headers.
HideHeaders() ExpectHTTPBuilder
// HideResponse is function for hide response body.
HideResponse() ExpectHTTPBuilder
// HideResponseHeaders is function for hide response headers.
HideResponseHeaders() ExpectHTTPBuilder

After
ControlTest
}
Expand Down
44 changes: 27 additions & 17 deletions roundtripper.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,21 +144,29 @@ func (it *Test) addInformationRequest(t T, req *http.Request) error {
it.Info(t, "[Request] Do request")
}

// Do not change to JSONMarshaler
// In this case we can keep default for keep JSON, independence from JSONMarshaler
headers, err := utils.ToJSON(req.Header)
if err != nil {
return err
t.WithNewParameters(
"method", req.Method,
"host", req.Host,
)

if !it.HideHeaders {
// Do not change to JSONMarshaler
// In this case we can keep default for keep JSON, independence from JSONMarshaler
headers, err := utils.ToJSON(req.Header)
if err != nil {
return err
}

t.WithNewParameters("headers", headers)
}

t.WithParameters(
allure.NewParameters(
"method", req.Method,
"host", req.Host,
"headers", headers,
"curl", curl.String(),
)...,
)
if it.HideBody {
return nil
}

if !it.HideBody && !it.HideHeaders {
t.WithNewParameters("curl", curl.String())
}

if req.Body != nil {
saveBody, req.Body, err = utils.DrainBody(req.Body)
Expand Down Expand Up @@ -200,15 +208,17 @@ func (it *Test) addInformationResponse(t T, response *http.Response) error {
err error
)

headers, _ := utils.ToJSON(response.Header)
if headers != "" {
t.WithNewParameters("response_headers", headers)
if !it.HideResponseHeaders {
headers, _ := utils.ToJSON(response.Header)
if headers != "" {
t.WithNewParameters("response_headers", headers)
}
}

t.WithNewParameters("response_code", fmt.Sprint(response.StatusCode))
it.Info(t, "[Response] Status: "+response.Status)

if response.Body == nil {
if it.HideResponse || response.Body == nil {
return nil
}

Expand Down
7 changes: 5 additions & 2 deletions test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ type Test struct {
Middleware *Middleware
Request *Request
Expect *Expect

HideBody bool
HideHeaders bool
HideResponse bool
HideResponseHeaders bool
}

// Request is struct with HTTP request.
Expand Down Expand Up @@ -200,7 +205,6 @@ func (it *Test) executeInsideAllure(ctx context.Context, allureProvider allurePr
// Execute test inside step
resp, errs = it.startTestWithStep(ctx, allureProvider)
} else {

// Execute Test
resp, errs = it.startTest(ctx, allureProvider)
}
Expand Down Expand Up @@ -470,7 +474,6 @@ func (it *Test) buildRequest(ctx context.Context) (*http.Request, error) {
body := o.body
if o.bodyMarshal != nil {
body, err = it.jsonMarshaler.Marshal(o.bodyMarshal)

if err != nil {
return nil, err
}
Expand Down