Skip to content

Commit

Permalink
Merge pull request #85 from ozontech/issue-84
Browse files Browse the repository at this point in the history
[ISSUE-84] support helper
  • Loading branch information
koodeex committed Mar 20, 2024
2 parents b670f1c + 7bb626c commit dd7f2ab
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 0 deletions.
12 changes: 12 additions & 0 deletions pkg/framework/core/common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,27 +113,35 @@ func (c *Common) LogfStep(format string, args ...interface{}) {

// Error ...
func (c *Common) Error(args ...interface{}) {
c.TestingT.Helper()

fullMessage := fmt.Sprintf("%s", args...)
c.registerError(fullMessage)
c.TestingT.Error(args...)
}

// Errorf ...
func (c *Common) Errorf(format string, args ...interface{}) {
c.TestingT.Helper()

fullMessage := fmt.Sprintf(format, args...)
c.registerError(fullMessage)
c.TestingT.Errorf(format, args...)
}

// Fatal ...
func (c *Common) Fatal(args ...interface{}) {
c.TestingT.Helper()

fullMessage := fmt.Sprintf("%s", args...)
c.registerError(fullMessage)
c.TestingT.Fatal(args...)
}

// Fatalf ...
func (c *Common) Fatalf(format string, args ...interface{}) {
c.TestingT.Helper()

fullMessage := fmt.Sprintf(format, args...)
c.registerError(fullMessage)
c.TestingT.Fatalf(format, args...)
Expand Down Expand Up @@ -341,6 +349,10 @@ func (c *Common) SetRealT(realT provider.TestingT) {
c.TestingT = realT
}

func (c *Common) GetRealT() provider.TestingT {
return c.TestingT
}

func copyLabels(input, target *allure.Result) *allure.Result {
if input == nil || target == nil {
return target
Expand Down
3 changes: 3 additions & 0 deletions pkg/framework/core/common/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ type commonTMock struct {
parallel bool
run bool
skipped bool
TestingT *testing.T
}

func newCommonTMock() *commonTMock {
Expand Down Expand Up @@ -220,6 +221,8 @@ func (m *commonTMock) Run(testName string, testBody func(t *testing.T)) bool {
return m.run
}

func (m *commonTMock) Helper() {}

func TestCommon_Assert(t *testing.T) {
asserts := helper.NewAssertsHelper(newCommonTMock())
comm := Common{assert: asserts}
Expand Down
13 changes: 13 additions & 0 deletions pkg/framework/core/common/step_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ type StepT interface {
Broken()
BrokenNow()
Name() string
GetRealT() provider.TestingT
}

type InternalStepCtx interface {
Expand Down Expand Up @@ -91,20 +92,28 @@ func (ctx *stepCtx) FailNow() {
}

func (ctx *stepCtx) Error(args ...interface{}) {
ctx.t.GetRealT().Helper()

ctx.Fail()
ctx.t.Error(args...)
}

func (ctx *stepCtx) Errorf(format string, args ...interface{}) {
ctx.t.GetRealT().Helper()

ctx.Fail()
ctx.t.Errorf(format, args...)
}

func (ctx *stepCtx) Log(args ...interface{}) {
ctx.t.GetRealT().Helper()

ctx.t.Log(args...)
}

func (ctx *stepCtx) Logf(format string, args ...interface{}) {
ctx.t.GetRealT().Helper()

ctx.t.Logf(format, args...)
}

Expand Down Expand Up @@ -212,3 +221,7 @@ func (ctx *stepCtx) Breakf(format string, args ...interface{}) {
ctx.Broken()
ctx.t.Breakf(format, args...)
}

func (ctx *stepCtx) GetRealT() provider.TestingT {
return ctx.t.GetRealT()
}
19 changes: 19 additions & 0 deletions pkg/framework/core/common/step_context_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ type providerTMockStep struct {
failNow bool
failed bool
name string

testingT provider.TestingT
}

func (m *providerTMockStep) Break(args ...interface{}) {
Expand Down Expand Up @@ -83,6 +85,14 @@ func (m *providerTMockStep) Name() string {
return m.name
}

func (m *providerTMockStep) GetRealT() provider.TestingT {
return m.testingT
}

func (m *providerTMockStep) SetRealT(realT provider.TestingT) {
m.testingT = realT
}

type providerMockStep struct {
status allure.Status
msg string
Expand All @@ -104,6 +114,9 @@ func (m *providerMockStep) ExecutionContext() provider.ExecutionContext {
return m.executionContext
}

func (m *providerMockStep) Helper() {
}

type executionCtxMock struct {
name string

Expand Down Expand Up @@ -233,6 +246,7 @@ func TestStepCtx_Step(t *testing.T) {

func TestStepCtx_Errorf_withParent(t *testing.T) {
mockT := new(providerTMockStep)
mockT.SetRealT(t)
parentStep := allure.NewSimpleStep("parentStep")
parentCtx := &stepCtx{t: mockT, currentStep: parentStep}
step := allure.NewSimpleStep("testStep")
Expand All @@ -245,6 +259,7 @@ func TestStepCtx_Errorf_withParent(t *testing.T) {

func TestStepCtx_Errorf_noParent(t *testing.T) {
mockT := new(providerTMockStep)
mockT.SetRealT(t)
step := allure.NewSimpleStep("testStep")
ctx := stepCtx{t: mockT, currentStep: step}
ctx.Errorf("test")
Expand All @@ -254,6 +269,8 @@ func TestStepCtx_Errorf_noParent(t *testing.T) {

func TestStepCtx_Error_withParent(t *testing.T) {
mockT := new(providerTMockStep)
mockT.SetRealT(t)

parentStep := allure.NewSimpleStep("parentStep", allure.NewParameters("paramParent1", "v1", "paramParent2", "v2")...)
parentCtx := &stepCtx{t: mockT, currentStep: parentStep}
step := allure.NewSimpleStep("testStep")
Expand All @@ -266,6 +283,8 @@ func TestStepCtx_Error_withParent(t *testing.T) {

func TestStepCtx_Error_noParent(t *testing.T) {
mockT := new(providerTMockStep)
mockT.SetRealT(t)

step := allure.NewSimpleStep("testStep")
ctx := stepCtx{t: mockT, currentStep: step}
ctx.Error("test")
Expand Down

0 comments on commit dd7f2ab

Please sign in to comment.