-
Notifications
You must be signed in to change notification settings - Fork 33
/
async_suite_test.go
97 lines (83 loc) · 2.51 KB
/
async_suite_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
//go:build async
// +build async
package async
import (
"fmt"
"testing"
"time"
"github.com/ozontech/allure-go/pkg/framework/provider"
"github.com/ozontech/allure-go/pkg/framework/suite"
)
type SuiteAsyncDemo struct {
suite.Suite
}
func (s *SuiteAsyncDemo) BeforeEach(t provider.T) {
t.Epic("Async")
t.Feature("Async Suite")
t.Tags("async", "suite", "steps")
}
func (s *SuiteAsyncDemo) TestAsyncSuiteDemo1(t provider.T) {
t.Title("Async Test 1")
startSign := fmt.Sprintf("%s", time.Now())
t.Parallel()
t.WithNewStep("Sync Step Demo", func(ctx provider.StepCtx) {
ctx.WithNewParameters("Start", startSign)
ctx.Logf("Test 1 Started At: %s", startSign)
time.Sleep(3 * time.Second)
stopSign := fmt.Sprintf("%s", time.Now())
ctx.Logf("Test 1 Stopped At: %s", stopSign)
ctx.WithNewParameters("Stop", stopSign)
})
}
func (s *SuiteAsyncDemo) TestAsyncSuiteDemo2(t provider.T) {
t.Title("Async Test 2")
startSign := fmt.Sprintf("%s", time.Now())
t.Parallel()
t.WithNewStep("Sync Step Demo", func(ctx provider.StepCtx) {
ctx.WithNewParameters("Start", startSign)
ctx.Logf("Test 2 Started At: %s", startSign)
time.Sleep(3 * time.Second)
stopSign := fmt.Sprintf("%s", time.Now())
ctx.Logf("Test 2 Stopped At: %s", stopSign)
ctx.WithNewParameters("Stop", stopSign)
})
}
func (s *SuiteAsyncDemo) TestAsyncSuiteDemo3(t provider.T) {
t.Title("Async Test 3")
t.Description(`
This test should be failed. But all logs a correct.`)
startSign := fmt.Sprintf("%s", time.Now())
t.Parallel()
t.WithNewStep("Sync Step Demo", func(ctx provider.StepCtx) {
ctx.WithNewParameters("Start", startSign)
ctx.Logf("Test 3 Started At: %s", startSign)
time.Sleep(1 * time.Second)
defer func() {
stopSign := fmt.Sprintf("%s", time.Now())
ctx.Logf("Test 3 Stopped At: %s", stopSign)
ctx.WithNewParameters("Stop", stopSign)
}()
ctx.Require().False(true)
})
}
func (s *SuiteAsyncDemo) TestAsyncSuiteDemo4(t provider.T) {
t.Title("Async Test 4")
t.Description(`
This test should be panic. But all logs a correct.`)
startSign := fmt.Sprintf("%s", time.Now())
t.Parallel()
t.WithNewStep("Sync Step Demo", func(ctx provider.StepCtx) {
ctx.WithNewParameters("Start", startSign)
ctx.Logf("Test 4 Started At: %s", startSign)
time.Sleep(2 * time.Second)
defer func() {
stopSign := fmt.Sprintf("%s", time.Now())
ctx.Logf("Test 4 Stopped At: %s", stopSign)
ctx.WithNewParameters("Stop", stopSign)
}()
panic("Whoops")
})
}
func TestSuiteAsyncRunner(t *testing.T) {
suite.RunSuite(t, new(SuiteAsyncDemo))
}