Skip to content

Commit

Permalink
[ISSUE-47] remove deprecated fuctional
Browse files Browse the repository at this point in the history
  • Loading branch information
siller174 committed Nov 16, 2023
1 parent 39c9bc7 commit 01b9c30
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 44 deletions.
29 changes: 5 additions & 24 deletions builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ type HTTPTestMaker struct {
httpClient *http.Client
middleware *Middleware

hardValidation bool

// todo add marshaler
}

Expand All @@ -29,8 +27,6 @@ type options struct {
httpRoundTripper http.RoundTripper

middleware *Middleware

hardValidation bool
}

type Option func(*options)
Expand Down Expand Up @@ -84,13 +80,6 @@ func WithMiddlewareBeforeT(beforeT ...BeforeExecuteT) Option {
}
}

// WithHardValidation ...
func WithHardValidation() Option {
return func(o *options) {
o.hardValidation = true
}
}

// NewHTTPTestMaker is function for set options for all cute.
func NewHTTPTestMaker(opts ...Option) *HTTPTestMaker {
var (
Expand Down Expand Up @@ -124,9 +113,8 @@ func NewHTTPTestMaker(opts ...Option) *HTTPTestMaker {
}

m := &HTTPTestMaker{
hardValidation: o.hardValidation,
httpClient: httpClient,
middleware: o.middleware,
httpClient: httpClient,
middleware: o.middleware,
}

return m
Expand Down Expand Up @@ -175,10 +163,9 @@ func createDefaultTest(m *HTTPTestMaker) *Test {
}

return &Test{
HardValidation: m.hardValidation,
httpClient: m.httpClient,
Middleware: middleware,
AllureStep: new(AllureStep),
httpClient: m.httpClient,
Middleware: middleware,
AllureStep: new(AllureStep),
Request: &Request{
Repeat: new(RequestRepeatPolitic),
},
Expand Down Expand Up @@ -660,12 +647,6 @@ func (it *cute) RequireResponseT(asserts ...AssertResponseT) ExpectHTTPBuilder {
return it
}

func (it *cute) EnableHardValidation() ExpectHTTPBuilder {
it.tests[it.countTests].HardValidation = true

return it
}

func (it *cute) CreateTableTest() MiddlewareTable {
it.isTableTest = true

Expand Down
6 changes: 1 addition & 5 deletions builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (

func TestBuilderAfterTest(t *testing.T) {
var (
maker = NewHTTPTestMaker(WithHardValidation())
maker = NewHTTPTestMaker()
)

ht := maker.NewTestBuilder().
Expand Down Expand Up @@ -43,13 +43,11 @@ func TestBuilderAfterTest(t *testing.T) {
res := ht.(*cute)
require.Len(t, res.tests[0].Middleware.After, 2)
require.Len(t, res.tests[0].Middleware.AfterT, 3)
require.True(t, res.tests[0].HardValidation)
}

func TestBuilderAfterTestTwoStep(t *testing.T) {
var (
maker = NewHTTPTestMaker(
WithHardValidation(),
WithMiddlewareBefore(
func(request *http.Request) error {
return nil
Expand Down Expand Up @@ -134,13 +132,11 @@ func TestBuilderAfterTestTwoStep(t *testing.T) {
require.Len(t, res.tests[0].Middleware.Before, 2)
require.Len(t, res.tests[0].Middleware.BeforeT, 1)
require.Len(t, res.tests[0].Middleware.AfterT, 3+3)
require.True(t, res.tests[0].HardValidation)

require.Len(t, res.tests[1].Middleware.After, 2+1)
require.Len(t, res.tests[1].Middleware.AfterT, 1+3)
require.Len(t, res.tests[1].Middleware.Before, 2)
require.Len(t, res.tests[1].Middleware.BeforeT, 1)
require.True(t, res.tests[1].HardValidation)
}

func TestNewTestBuilder(t *testing.T) {
Expand Down
5 changes: 0 additions & 5 deletions interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,11 +248,6 @@ type ExpectHTTPBuilder interface {
// Mark in allure as Skipped
OptionalAssertResponseT(asserts ...AssertResponseT) ExpectHTTPBuilder

// EnableHardValidation is enabled hard validation,
// If one of assert was failed, test will stopped.
// Deprecated. Please use require asserts.
EnableHardValidation() ExpectHTTPBuilder

After
ControlTest
}
Expand Down
12 changes: 2 additions & 10 deletions test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ var (
type Test struct {
httpClient *http.Client

HardValidation bool

Name string

AllureStep *AllureStep
Expand Down Expand Up @@ -202,6 +200,7 @@ func (it *Test) processTestErrors(t internalT, errs []error) bool {
if tErr, ok := err.(cuteErrors.OptionalError); ok {
if tErr.IsOptional() {
t.Logf("[OPTIONAL ERROR] %v", tErr.(error).Error())

continue
}
}
Expand All @@ -221,14 +220,7 @@ func (it *Test) processTestErrors(t internalT, errs []error) bool {
t.Errorf("Test finished with %v errors", countNotOptionalErrors)
}

// If we have not optional errors and hardValidation (assert errors)
// or if we have failed tests (require errors)
// we should fail test
if (it.HardValidation && countNotOptionalErrors != 0) || failTest {
return true
}

return false
return failTest
}

func (it *Test) startTestWithStep(ctx context.Context, t internalT) (*http.Response, []error) {
Expand Down

0 comments on commit 01b9c30

Please sign in to comment.