Releases: ozontech/cute
Releases · ozontech/cute
v0.1.12
So.... Time to change something.
- Update linter
- Update allure-go
- Support new allure labels
func (it *cute) Titlef(format string, args ...interface{}) AllureBuilder
func (it *cute) Descriptionf(format string, args ...interface{}) AllureBuilder
func (it *cute) Stage(stage string) AllureBuilder
func (it *cute) Stagef(format string, args ...interface{}) AllureBuilder
func (it *cute) Layer(value string) AllureBuilder
func (it *cute) TmsLink(tmsLink string) AllureBuilder
func (it *cute) TmsLinks(tmsLinks ...string) AllureBuilder
- Support
provider.StepCtx
func TestInsideStep(t *testing.T) {
runner.Run(t, "Single test with allure-go Runner", func(t provider.T) {
t.WithNewStep("First step", func(sCtx provider.StepCtx) {
sCtx.NewStep("Inside first step")
})
t.WithNewStep("Step name", func(sCtx provider.StepCtx) {
u, _ := url.Parse("https://jsonplaceholder.typicode.com/posts/1/comments")
cute.NewTestBuilder().
Title("Super simple test").
Tags("simple", "suite", "some_local_tag", "json").
Parallel().
Create().
RequestBuilder(
cute.WithHeaders(map[string][]string{
"some_header": []string{"something"},
}),
cute.WithURL(u),
cute.WithMethod(http.MethodPost),
).
ExpectExecuteTimeout(10*time.Second).
ExpectStatus(http.StatusCreated).
ExecuteTest(context.Background(), sCtx) // <---- Execute test with provider.StepCtx
})
})
}
- Remove
EnableHardValidation
- Fix bug with custom
http.Client
- Implement new library for
jsonPath
- New assert. JSON diff
AssertBody(json.Diff("{\"aaa\":\"bb\"}")).
v0.1.11
NEW
Require validation. #37
implements the same assertions as the Assert
, but stops test execution when a test fails.
RequireBody
RequireBodyT
RequireResponse
RequireResponseT
RequireHeaders
RequireHeadersT
Implement query builder
cute.WithQueryKV("socks", "42")
cute.WithQuery(map[string][]string{"hello": {"Denis", "my friend", "MAAA FREEEND"}})
RequestBuilder(
cute.WithURI("https://jsonplaceholder.typicode.com/posts/1/comments"),
cute.WithQueryKV("socks", "42"), <--- NEW METHOD
cute.WithQuery(map[string][]string{"hello": {"Denis", "my friend", "MAAA FREEEND"}}), <--- NEW METHOD
cute.WithMethod(http.MethodGet),
).
v0.1.10
New
- Support
multipart/form-data
#31
func TestUploadfile(t *testing.T) {
cute.NewTestBuilder().
Title("Uploat file").
Create().
RequestBuilder(
cute.WithURI("http://localhost:7000/v1/admin/banner"),
cute.WithMethod("POST"),
cute.WithFormKV("body", []byte("{\"age\": 42}")),
cute.WithFileFormKV("image", &cute.File{
Path: "/vasya/gogogo.png",
}),
).
ExecuteTest(context.Background(), t)
}
- Implement hard validation
#30
func TestUploadfile(t *testing.T) {
cute.NewTestBuilder().
Title("Uploat file").
Create().
RequestBuilder(
cute.WithURI("http://localhost:7000/v1/admin/banner"),
cute.WithMethod("POST"),
cute.WithFormKV("body", []byte("{\"age\": 42}")),
cute.WithFileFormKV("image", &cute.File{
Path: "/vasya/gogogo.png",
}),
).
EnableHardValidation(). <- enable hard validation
ExpectStatus(http.StatusOK).
ExecuteTest(context.Background(), t)
}
- Rename asserts
GreaterThan => LengthGreaterThan
GreaterOrEqualThan => LengthGreaterOrEqualThan
LessThan => LengthLessThan
LessOrEqualThan => LengthLessOrEqualThan
- Implement common after/before test
#32
func TestName(t *testing.T) {
testMaker := cute.NewHTTPTestMaker(
cute.WithMiddlewareAfterT(modules.LogTraceID),
)
}
func LogTraceID(t cute.T, response *http.Response, errors []error) error {
t.Logf("[o3_request_info] Trace_id - %v", response.Header.Get("x-trace-id"))
return nil
}
- Remove deprecated method
CreateWithStep().
StepName("Step name").
you have to replace it by
CreateStep("Step name").
v0.1.9
v0.1.8
v0.1.7
It was hard for me.
Changed interfaces
Old:
// ExecuteTest is a function for execute Test
ExecuteTest(ctx context.Context, t testing.TB) ResultsHTTPBuilder
New:
// ExecuteTest is a function for execute Test
ExecuteTest(ctx context.Context, t testing.TB) []ResultsHTTPBuilder
New asserts
GreaterOrEqualThan
is a function to assert that value is greater or equal than the given lengthLessOrEqualThan
is a function to assert that value is less or equal than the given length
Thank you @shalimski
Curl log
Max length curl log set by 2048
Deprecated
CreateWithStep() StepBuilder
please use CreateStep(string) MiddlewareRequest
Multi-step test
import (
"context"
"fmt"
"net/http"
"testing"
"github.com/ozontech/cute"
)
func Test_TwoSteps(t *testing.T) {
responseCode := 0
// First step.
cute.NewTestBuilder().
Title("Test with two requests and parse body.").
Tag("two_steps").
Create().
RequestBuilder(
cute.WithURI("https://jsonplaceholder.typicode.com/posts/1/comments"),
cute.WithMethod(http.MethodGet),
).
ExpectStatus(http.StatusOK).
NextTest().
// Execute after first step and parse response code
AfterTestExecute(func(response *http.Response, errors []error) error {
responseCode = response.StatusCode
return nil
}).
// Second step
Create().
RequestBuilder(
cute.WithURI("https://jsonplaceholder.typicode.com/posts/2/comments"),
cute.WithMethod(http.MethodDelete),
).
ExecuteTest(context.Background(), t)
fmt.Println("Response code from first request", responseCode)
}
See full example here
Allure:
Table tests
One step to table tests...
You have 2 ways to create table test. These ways have same allure reports.
Builder table tests
import (
"context"
"fmt"
"net/http"
"testing"
"github.com/ozontech/cute"
)
func Test_Table_Array(t *testing.T) {
tests := []*cute.Test{
{
Name: "test_1",
Middleware: nil,
Request: &cute.Request{
Builders: []cute.RequestBuilder{
cute.WithURI("https://jsonplaceholder.typicode.com/posts/1/comments"),
cute.WithMethod(http.MethodPost),
},
},
Expect: &cute.Expect{
Code: 200,
},
},
{
Name: "test_2",
Middleware: nil,
Request: &cute.Request{
Builders: []cute.RequestBuilder{
cute.WithURI("https://jsonplaceholder.typicode.com/posts/1/comments"),
cute.WithMethod(http.MethodGet),
},
},
Expect: &cute.Expect{
Code: 200,
AssertBody: []cute.AssertBody{
json.Equal("$[0].email", "Eliseo@gardner.biz"),
json.Present("$[1].name"),
func(body []byte) error {
return errors.NewAssertError("example error", "example message", nil, nil)
},
},
},
},
}
cute.NewTestBuilder().
Title("Example table test").
Tag("table_test").
Description("Execute array tests").
CreateTableTest().
PutTests(tests...).
ExecuteTest(context.Background(), t)
}
Array tests
func Test_Execute_Array(t *testing.T) {
tests := []*cute.Test{
{
Name: "test_1",
Middleware: nil,
Request: &cute.Request{
Builders: []cute.RequestBuilder{
cute.WithURI("https://jsonplaceholder.typicode.com/posts/1/comments"),
cute.WithMethod(http.MethodPost),
},
},
Expect: &cute.Expect{
Code: 200,
},
},
{
Name: "test_2",
Middleware: nil,
Request: &cute.Request{
Builders: []cute.RequestBuilder{
cute.WithURI("https://jsonplaceholder.typicode.com/posts/1/comments"),
cute.WithMethod(http.MethodGet),
},
},
Expect: &cute.Expect{
Code: 200,
AssertBody: []cute.AssertBody{
json.Equal("$[0].email", "Eliseo@gardner.biz"),
json.Present("$[1].name"),
func(body []byte) error {
return errors.NewAssertError("example error", "example message", nil, nil)
},
},
},
},
}
for _, test := range tests {
test.Execute(context.Background(), t)
}
}
See full example here
Common allure for all table tests:
Report has 2 different tests/suites:
v0.1.5
v0.1.4
v0.1.3
Features:
1. Update to allure v0.1.12 #12
2. Add some logs in console #10
3. Retries for failed tests #9
cute.NewTestBuilder().
Title("AllureRunner").
Description("some_description").
Create().
RequestRepeatDelay(3*time.Second). // delay before new try
RequestRepeat(3). // count attempts
4. Reimplement assert #13
Present
assert will not return error, if value == 0 or value != 0
5. New JSON assert
NotEmpty
assert like Preset
, but value can be 0
or null
6. Change cute error interfaces
Error with allure parameters
Old:
type ExpectedError interface {
GetActual() interface{}
GetExpected() interface{}
}
New:
If function returns error, which implement this interface, parameters will add to allure step
type WithFields interface {
GetFields() map[string]interface{}
PutFields(map[string]interface{})
}
Optional error
Old:
type OptionalError interface {
IsOptional() bool
SetOptional()
}
New:
type OptionalError interface {
IsOptional() bool
SetOptional(bool)
}