From ab41438fb5d5e02f532bcd6198c7ec3e8f59c35d Mon Sep 17 00:00:00 2001 From: Sergey Makarov Date: Sat, 16 Mar 2024 22:46:50 +0100 Subject: [PATCH 1/6] [ISSUE-84] support helper --- pkg/framework/core/common/common.go | 13 +++++++++++++ pkg/framework/core/common/step_context.go | 13 +++++++++++++ pkg/framework/core/common/step_context_test.go | 6 ++++++ pkg/framework/provider/test.go | 1 + 4 files changed, 33 insertions(+) diff --git a/pkg/framework/core/common/common.go b/pkg/framework/core/common/common.go index df94a21..13964fc 100644 --- a/pkg/framework/core/common/common.go +++ b/pkg/framework/core/common/common.go @@ -99,6 +99,11 @@ func (c *Common) SkipOnPrint() { c.GetResult().SkipOnPrint() } +// Helper ... +func (c *Common) Helper() { + c.TestingT.Helper() +} + // LogStep ... func (c *Common) LogStep(args ...interface{}) { c.Provider.Step(allure.NewSimpleStep(fmt.Sprintln(args...))) @@ -113,6 +118,8 @@ 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...) @@ -120,6 +127,8 @@ func (c *Common) Error(args ...interface{}) { // 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...) @@ -127,6 +136,8 @@ func (c *Common) Errorf(format string, args ...interface{}) { // Fatal ... func (c *Common) Fatal(args ...interface{}) { + c.TestingT.Helper() + fullMessage := fmt.Sprintf("%s", args...) c.registerError(fullMessage) c.TestingT.Fatal(args...) @@ -134,6 +145,8 @@ func (c *Common) Fatal(args ...interface{}) { // 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...) diff --git a/pkg/framework/core/common/step_context.go b/pkg/framework/core/common/step_context.go index a256821..5254fc7 100644 --- a/pkg/framework/core/common/step_context.go +++ b/pkg/framework/core/common/step_context.go @@ -27,6 +27,7 @@ type StepT interface { Broken() BrokenNow() Name() string + Helper() } type InternalStepCtx interface { @@ -90,21 +91,33 @@ func (ctx *stepCtx) FailNow() { ctx.t.FailNow() } +func (ctx *stepCtx) Helper() { + ctx.t.Helper() +} + func (ctx *stepCtx) Error(args ...interface{}) { + ctx.t.Helper() + ctx.Fail() ctx.t.Error(args...) } func (ctx *stepCtx) Errorf(format string, args ...interface{}) { + ctx.t.Helper() + ctx.Fail() ctx.t.Errorf(format, args...) } func (ctx *stepCtx) Log(args ...interface{}) { + ctx.t.Helper() + ctx.t.Log(args...) } func (ctx *stepCtx) Logf(format string, args ...interface{}) { + ctx.t.Helper() + ctx.t.Logf(format, args...) } diff --git a/pkg/framework/core/common/step_context_test.go b/pkg/framework/core/common/step_context_test.go index 836a079..a09c956 100644 --- a/pkg/framework/core/common/step_context_test.go +++ b/pkg/framework/core/common/step_context_test.go @@ -83,6 +83,9 @@ func (m *providerTMockStep) Name() string { return m.name } +func (m *providerTMockStep) Helper() { +} + type providerMockStep struct { status allure.Status msg string @@ -104,6 +107,9 @@ func (m *providerMockStep) ExecutionContext() provider.ExecutionContext { return m.executionContext } +func (m *providerMockStep) Helper() { +} + type executionCtxMock struct { name string diff --git a/pkg/framework/provider/test.go b/pkg/framework/provider/test.go index e9f7b89..5eca42b 100644 --- a/pkg/framework/provider/test.go +++ b/pkg/framework/provider/test.go @@ -70,6 +70,7 @@ type StepCtx interface { Break(args ...interface{}) Breakf(format string, args ...interface{}) Name() string + Helper() } // Asserts ... From b4cba36b31047a3802ffa8dc57942af3d4d8f003 Mon Sep 17 00:00:00 2001 From: Sergey Makarov Date: Sat, 16 Mar 2024 23:04:02 +0100 Subject: [PATCH 2/6] [ISSUE-84] fix test --- pkg/framework/core/common/common_test.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pkg/framework/core/common/common_test.go b/pkg/framework/core/common/common_test.go index d55df50..d013ec3 100644 --- a/pkg/framework/core/common/common_test.go +++ b/pkg/framework/core/common/common_test.go @@ -220,6 +220,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} From 5ee8265e6aa3cf0ad811837f38f98de619af192d Mon Sep 17 00:00:00 2001 From: Sergey Makarov Date: Sun, 17 Mar 2024 13:01:13 +0100 Subject: [PATCH 3/6] [ISSUE-35] add getRealT --- pkg/framework/core/common/common.go | 4 ++++ pkg/framework/core/common/step_context.go | 11 ++++++----- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/pkg/framework/core/common/common.go b/pkg/framework/core/common/common.go index 13964fc..89bfe95 100644 --- a/pkg/framework/core/common/common.go +++ b/pkg/framework/core/common/common.go @@ -354,6 +354,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 diff --git a/pkg/framework/core/common/step_context.go b/pkg/framework/core/common/step_context.go index 5254fc7..0eff902 100644 --- a/pkg/framework/core/common/step_context.go +++ b/pkg/framework/core/common/step_context.go @@ -28,6 +28,7 @@ type StepT interface { BrokenNow() Name() string Helper() + GetRealT() provider.TestingT } type InternalStepCtx interface { @@ -92,31 +93,31 @@ func (ctx *stepCtx) FailNow() { } func (ctx *stepCtx) Helper() { - ctx.t.Helper() + ctx.t.GetRealT().Helper() } func (ctx *stepCtx) Error(args ...interface{}) { - ctx.t.Helper() + ctx.t.GetRealT().Helper() ctx.Fail() ctx.t.Error(args...) } func (ctx *stepCtx) Errorf(format string, args ...interface{}) { - ctx.t.Helper() + ctx.t.GetRealT().Helper() ctx.Fail() ctx.t.Errorf(format, args...) } func (ctx *stepCtx) Log(args ...interface{}) { - ctx.t.Helper() + ctx.t.GetRealT().Helper() ctx.t.Log(args...) } func (ctx *stepCtx) Logf(format string, args ...interface{}) { - ctx.t.Helper() + ctx.t.GetRealT().Helper() ctx.t.Logf(format, args...) } From 0c7c5f62dfed192c06ccae950b0031a1f2a1f2c9 Mon Sep 17 00:00:00 2001 From: Sergey Makarov Date: Sun, 17 Mar 2024 13:04:47 +0100 Subject: [PATCH 4/6] [ISSUE-35] add getRealT --- pkg/framework/core/common/step_context_test.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pkg/framework/core/common/step_context_test.go b/pkg/framework/core/common/step_context_test.go index a09c956..eedb11a 100644 --- a/pkg/framework/core/common/step_context_test.go +++ b/pkg/framework/core/common/step_context_test.go @@ -86,6 +86,10 @@ func (m *providerTMockStep) Name() string { func (m *providerTMockStep) Helper() { } +func (m *providerTMockStep) GetRealT() provider.TestingT { + return nil +} + type providerMockStep struct { status allure.Status msg string From 592bb00fcb61997d88474bb0b95d32292ac386f9 Mon Sep 17 00:00:00 2001 From: Sergey Makarov Date: Sun, 17 Mar 2024 13:09:12 +0100 Subject: [PATCH 5/6] [ISSUE-35] add getRealT --- pkg/framework/core/common/step_context_test.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/pkg/framework/core/common/step_context_test.go b/pkg/framework/core/common/step_context_test.go index eedb11a..4dc3cd6 100644 --- a/pkg/framework/core/common/step_context_test.go +++ b/pkg/framework/core/common/step_context_test.go @@ -22,6 +22,8 @@ type providerTMockStep struct { failNow bool failed bool name string + + testingT provider.TestingT } func (m *providerTMockStep) Break(args ...interface{}) { @@ -87,7 +89,11 @@ func (m *providerTMockStep) Helper() { } func (m *providerTMockStep) GetRealT() provider.TestingT { - return nil + return m.testingT +} + +func (m *providerTMockStep) SetRealT(realT provider.TestingT) { + m.testingT = realT } type providerMockStep struct { @@ -243,6 +249,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") From 7bb626c4c7bd84bbdbaf7432cdd7d73b749fca67 Mon Sep 17 00:00:00 2001 From: Sergey Makarov Date: Sun, 17 Mar 2024 21:33:55 +0100 Subject: [PATCH 6/6] [ISSUE-84] add getRealT --- pkg/framework/core/common/common.go | 5 ----- pkg/framework/core/common/common_test.go | 1 + pkg/framework/core/common/step_context.go | 9 ++++----- pkg/framework/core/common/step_context_test.go | 8 +++++--- pkg/framework/provider/test.go | 1 - 5 files changed, 10 insertions(+), 14 deletions(-) diff --git a/pkg/framework/core/common/common.go b/pkg/framework/core/common/common.go index 89bfe95..12e61e0 100644 --- a/pkg/framework/core/common/common.go +++ b/pkg/framework/core/common/common.go @@ -99,11 +99,6 @@ func (c *Common) SkipOnPrint() { c.GetResult().SkipOnPrint() } -// Helper ... -func (c *Common) Helper() { - c.TestingT.Helper() -} - // LogStep ... func (c *Common) LogStep(args ...interface{}) { c.Provider.Step(allure.NewSimpleStep(fmt.Sprintln(args...))) diff --git a/pkg/framework/core/common/common_test.go b/pkg/framework/core/common/common_test.go index d013ec3..a579e30 100644 --- a/pkg/framework/core/common/common_test.go +++ b/pkg/framework/core/common/common_test.go @@ -184,6 +184,7 @@ type commonTMock struct { parallel bool run bool skipped bool + TestingT *testing.T } func newCommonTMock() *commonTMock { diff --git a/pkg/framework/core/common/step_context.go b/pkg/framework/core/common/step_context.go index 0eff902..56066c8 100644 --- a/pkg/framework/core/common/step_context.go +++ b/pkg/framework/core/common/step_context.go @@ -27,7 +27,6 @@ type StepT interface { Broken() BrokenNow() Name() string - Helper() GetRealT() provider.TestingT } @@ -92,10 +91,6 @@ func (ctx *stepCtx) FailNow() { ctx.t.FailNow() } -func (ctx *stepCtx) Helper() { - ctx.t.GetRealT().Helper() -} - func (ctx *stepCtx) Error(args ...interface{}) { ctx.t.GetRealT().Helper() @@ -226,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() +} diff --git a/pkg/framework/core/common/step_context_test.go b/pkg/framework/core/common/step_context_test.go index 4dc3cd6..398b954 100644 --- a/pkg/framework/core/common/step_context_test.go +++ b/pkg/framework/core/common/step_context_test.go @@ -85,9 +85,6 @@ func (m *providerTMockStep) Name() string { return m.name } -func (m *providerTMockStep) Helper() { -} - func (m *providerTMockStep) GetRealT() provider.TestingT { return m.testingT } @@ -262,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") @@ -271,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") @@ -283,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") diff --git a/pkg/framework/provider/test.go b/pkg/framework/provider/test.go index 5eca42b..e9f7b89 100644 --- a/pkg/framework/provider/test.go +++ b/pkg/framework/provider/test.go @@ -70,7 +70,6 @@ type StepCtx interface { Break(args ...interface{}) Breakf(format string, args ...interface{}) Name() string - Helper() } // Asserts ...