Skip to content

Commit

Permalink
Merge pull request #44 from ozontech/release/issue-43
Browse files Browse the repository at this point in the history
[ISSUE-43] add status "broken" control methods
  • Loading branch information
koodeex authored Jan 10, 2023
2 parents ff31572 + 5d715a8 commit 27e94e3
Show file tree
Hide file tree
Showing 9 changed files with 238 additions and 34 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ jobs:
name: lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- uses: actions/setup-go@v3
with:
go-version: '1.17.8'
- name: allure-golangci-lint
run: cd ./pkg/allure && make lint
- name: provider-golangci-lint
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ Check out [our example](./examples/suite_demo/setup_test.go) for more informatio
:information_source: Yes, it works with t.Parallel, but HIGHLY recommended to run t.Parallel AFTER TestSetup.<br>
:information_source: Yes, it works with TableTest.<br>



**Release v0.6.16**

#### :zap: Parametrized tests
Expand Down
104 changes: 104 additions & 0 deletions examples/suite_demo/fails_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,110 @@ func (s *FailsDemoSuite) TestPanicInnerSteps(t provider.T) {
})
}

func (s *FailsDemoSuite) TestBrokenStatusNoMessage(t provider.T) {
t.Title("This test fails with broken status")
t.Description(`
This Test will Failed as Fail().
Test status will be "Broken" in allure.
No any message expected there`)

t.Tags("fail", "broken")

t.NewStep("This step will be reached before failing")
t.Broken()
t.NewStep("This step will be reached after failing")
}

func (s *FailsDemoSuite) TestBrokenNowStatusNoMessage(t provider.T) {
t.Title("This test fails immediately with broken status")
t.Description(`
This Test will Failed as Fail().
Test status will be "Broken" in allure.
No any message expected there`)

t.Tags("fail", "broken")

t.NewStep("This step will be reached before failing")
t.BrokenNow()
t.NewStep("This step will never be reached after failing")
}

func (s *FailsDemoSuite) TestBrokenNowStatusMessage(t provider.T) {
t.Title("This test fails immediately with broken status and message")
t.Description(`
This Test will Failed as FailNow().
Test status will be "Broken" in allure.
No any message expected there`)

t.Tags("fail", "broken")

t.NewStep("This step will be reached before failing")
t.Breakf("Test fails as FailNow()")
t.NewStep("This step will never be reached after failing")
}

func (s *FailsDemoSuite) TestBrokenStatusNoMessageStep(t provider.T) {
t.Title("This test fails with broken status inside step")
t.Description(`
This Test will Failed as Fail().
Test status will be "Broken" in allure.
No any message expected there`)

t.Tags("fail", "broken")

t.WithNewStep("This step will be broken", func(sCtx provider.StepCtx) {
sCtx.Broken()
})
t.NewStep("This step will be reached after failing")
}

func (s *FailsDemoSuite) TestBrokenNowStatusNoMessageStep(t provider.T) {
t.Title("This test fails immediately with broken status inside step")
t.Description(`
This Test will Failed as Fail().
Test status will be "Broken" in allure.
No any message expected there`)

t.Tags("fail", "broken")

t.WithNewStep("This step will be broken", func(sCtx provider.StepCtx) {
sCtx.BrokenNow()
})
t.NewStep("This step will never be reached after failing")
}

func (s *FailsDemoSuite) TestBrokenNowStatusMessageStep(t provider.T) {
t.Title("This test fails immediately with broken status and message inside step")
t.Description(`
This Test will Failed as FailNow().
Test status will be "Broken" in allure.
No any message expected there`)

t.Tags("fail", "broken")

t.WithNewStep("This step will be broken", func(sCtx provider.StepCtx) {
sCtx.Breakf("Test fails as FailNow()")
})
t.NewStep("This step will never be reached after failing")
}

func (s *FailsDemoSuite) TestBrokenNowStatusMessageInnerStep(t provider.T) {
t.Title("This test fails immediately with broken status and message inside inner step")
t.Description(`
This Test will Failed as FailNow().
Test status will be "Broken" in allure.
No any message expected there`)

t.Tags("fail", "broken", "inner")

t.WithNewStep("This step will be broken", func(sCtx provider.StepCtx) {
sCtx.WithNewStep("Inner step", func(sCtx provider.StepCtx) {
sCtx.Breakf("Test fails as FailNow()")
})
})
t.NewStep("This step will never be reached after failing")
}

func TestFails(t *testing.T) {
t.Parallel()
suite.RunSuite(t, new(FailsDemoSuite))
Expand Down
40 changes: 38 additions & 2 deletions pkg/framework/core/common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ func (c *Common) registerError(fullMessage string) {
c.Skip(fullMessage)
}
result.Status = allure.Failed
result.StatusDetails.Message = extractErrorMessages(fullMessage)
result.StatusDetails.Trace = fmt.Sprintf("%s\n%s", result.StatusDetails.Trace, fullMessage)
}
result.StatusDetails.Message = extractErrorMessages(fullMessage)
result.StatusDetails.Trace = fmt.Sprintf("%s\n%s", result.StatusDetails.Trace, fullMessage)
}

func (c *Common) safely(f func(result *allure.Result)) {
Expand Down Expand Up @@ -137,6 +137,26 @@ func (c *Common) Fatalf(format string, args ...interface{}) {
c.TestingT.Fatalf(format, args...)
}

// Break ...
func (c *Common) Break(args ...interface{}) {
c.safely(func(result *allure.Result) {
result.Status = allure.Broken
})
fullMessage := fmt.Sprintf("%s", args...)
c.registerError(fullMessage)
c.FailNow()
}

// Breakf ...
func (c *Common) Breakf(format string, args ...interface{}) {
c.safely(func(result *allure.Result) {
result.Status = allure.Broken
})
fullMessage := fmt.Sprintf(format, args...)
c.registerError(fullMessage)
c.FailNow()
}

// Name ...
func (c *Common) Name() string {
if c.GetProvider() != nil && c.GetProvider().GetResult() != nil {
Expand All @@ -161,6 +181,22 @@ func (c *Common) FailNow() {
c.TestingT.FailNow()
}

// Broken ...
func (c *Common) Broken() {
c.safely(func(result *allure.Result) {
result.Status = allure.Broken
})
c.TestingT.Fail()
}

// BrokenNow ...
func (c *Common) BrokenNow() {
c.safely(func(result *allure.Result) {
result.Status = allure.Broken
})
c.TestingT.FailNow()
}

// Skip ...
func (c *Common) Skip(args ...interface{}) {
c.safely(func(result *allure.Result) {
Expand Down
24 changes: 10 additions & 14 deletions pkg/framework/core/common/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,14 @@ type providerMockCommon struct {
executionMock *executionContextCommMock
}

func newProviderMockCommon(name, fullName string) *providerMockCommon {
return &providerMockCommon{
testMetaMock: &testMetaMockCommon{result: allure.NewResult(name, fullName)},
suiteMetaMock: nil,
executionMock: nil,
}
}

func (m *providerMockCommon) GetResult() *allure.Result {
return m.testMetaMock.GetResult()
}
Expand Down Expand Up @@ -228,26 +236,14 @@ func TestCommon_Require(t *testing.T) {

func TestCommon_Error(t *testing.T) {
mock := newCommonTMock()
cfg := manager.NewProviderConfig().
WithRunner("WithRunner").
WithPackageName("WithPackageName").
WithSuiteName("WithSuiteName").
WithFullName("WithFullName")

comm := Common{TestingT: mock, Provider: manager.NewProvider(cfg)}
comm := Common{TestingT: mock, Provider: newProviderMockCommon("name", "fullName")}
comm.Error("test")
require.True(t, mock.errorfFlag)
}

func TestCommon_Errorf(t *testing.T) {
mock := newCommonTMock()
cfg := manager.NewProviderConfig().
WithRunner("WithRunner").
WithPackageName("WithPackageName").
WithSuiteName("WithSuiteName").
WithFullName("WithFullName")

comm := Common{TestingT: mock, Provider: manager.NewProvider(cfg)}
comm := Common{TestingT: mock, Provider: newProviderMockCommon("name", "fullName")}
comm.Errorf("test")
require.True(t, mock.errorfFlag)
}
Expand Down
23 changes: 23 additions & 0 deletions pkg/framework/core/common/step_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ type StepT interface {
Errorf(format string, args ...interface{})
Log(args ...interface{})
Logf(format string, args ...interface{})
Break(args ...interface{})
Breakf(format string, args ...interface{})
Broken()
BrokenNow()
Name() string
}

Expand Down Expand Up @@ -188,4 +192,23 @@ func (ctx *stepCtx) Broken() {
if ctx.parentStep != nil {
ctx.parentStep.Broken()
}
ctx.t.Broken()
}

func (ctx *stepCtx) BrokenNow() {
ctx.currentStep.Broken()
if ctx.parentStep != nil {
ctx.parentStep.Broken()
}
ctx.t.BrokenNow()
}

func (ctx *stepCtx) Break(args ...interface{}) {
ctx.Broken()
ctx.t.Break(args...)
}

func (ctx *stepCtx) Breakf(format string, args ...interface{}) {
ctx.Broken()
ctx.t.Breakf(format, args...)
}
Loading

0 comments on commit 27e94e3

Please sign in to comment.