Skip to content

Releases: ozontech/cute

v0.1.12

20 Nov 11:43
8b574b1
Compare
Choose a tag to compare

So.... Time to change something.

  1. Update linter
  2. Update allure-go
  3. 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
  1. 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
		})
	})

}
  1. Remove EnableHardValidation
  2. Fix bug with custom http.Client
  3. Implement new library for jsonPath
  4. New assert. JSON diff
		AssertBody(json.Diff("{\"aaa\":\"bb\"}")).

v0.1.11

13 Feb 12:15
a91de3b
Compare
Choose a tag to compare

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

09 Jan 09:33
d329f99
Compare
Choose a tag to compare

New

  1. 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)
}
  1. 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)
}
  1. Rename asserts
 GreaterThan => LengthGreaterThan
 GreaterOrEqualThan  => LengthGreaterOrEqualThan
 LessThan => LengthLessThan
 LessOrEqualThan => LengthLessOrEqualThan
  1. 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
}
  1. Remove deprecated method
		CreateWithStep().
		StepName("Step name").

you have to replace it by

		CreateStep("Step name").

v0.1.9

06 Oct 13:19
4c9afd0
Compare
Choose a tag to compare

Fixed:

  1. #28

New:

  1. Added After and AfterT in main builder interface
    Example: https://github.com/ozontech/cute/blob/master/examples/single_test.go#L54

v0.1.8

19 Sep 08:28
ea8745a
Compare
Choose a tag to compare

hotfix #27

v0.1.7

15 Sep 13:16
303e905
Compare
Choose a tag to compare

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 length
  • LessOrEqualThan 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:

multistep_test.png

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:

table_tests_execute_array.png

v0.1.5

02 Sep 11:15
337b6fc
Compare
Choose a tag to compare

Update allure-go to

github.com/ozontech/allure-go/pkg/allure v0.6.4
github.com/ozontech/allure-go/pkg/framework v0.6.18
github.com/ozontech/allure-go v0.6.18

v0.1.4

30 Aug 19:24
c7f2aef
Compare
Choose a tag to compare

Update allure

    github.com/ozontech/allure-go/pkg/allure v0.6.3
    github.com/ozontech/allure-go/pkg/framework v0.6.17

v0.1.3

24 Jul 07:47
dbbed9e
Compare
Choose a tag to compare

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

Allure:
image

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)
}

v0.1.2

27 Jun 09:11
4d7c1f6
Compare
Choose a tag to compare

Problem:
If create some option asserts and one will be failed, test will be failed also

Fix
#8