1
1
package f1_test
2
2
3
3
import (
4
+ "bytes"
5
+ "fmt"
4
6
"os"
7
+ "strings"
5
8
"sync/atomic"
6
9
"syscall"
7
10
"testing"
@@ -11,21 +14,21 @@ import (
11
14
"github.com/stretchr/testify/require"
12
15
"go.uber.org/goleak"
13
16
17
+ "github.com/form3tech-oss/f1/v2/internal/log"
14
18
"github.com/form3tech-oss/f1/v2/pkg/f1"
15
19
f1_testing "github.com/form3tech-oss/f1/v2/pkg/f1/testing"
16
20
)
17
21
18
22
type f1Stage struct {
19
- t * testing.T
20
- assert * assert.Assertions
21
- require * require.Assertions
22
-
23
- f1 * f1.F1
24
- errCh chan error
25
- scenario string
26
- runCount atomic.Uint32
27
-
28
23
executeErr error
24
+ t * testing.T
25
+ assert * assert.Assertions
26
+ require * require.Assertions
27
+ f1 * f1.F1
28
+ errCh chan error
29
+ scenario string
30
+ logOutput bytes.Buffer
31
+ runCount atomic.Uint32
29
32
}
30
33
31
34
func newF1Stage (t * testing.T ) (* f1Stage , * f1Stage , * f1Stage ) {
@@ -46,6 +49,13 @@ func (s *f1Stage) and() *f1Stage {
46
49
return s
47
50
}
48
51
52
+ func (s * f1Stage ) a_custom_logger_is_configured_with_attr (key , value string ) * f1Stage {
53
+ logger := log .NewTestLogger (& s .logOutput ).With (key , value )
54
+ s .f1 = f1 .New ().WithLogger (logger )
55
+
56
+ return s
57
+ }
58
+
49
59
func (s * f1Stage ) after_duration_signal_will_be_sent (duration time.Duration , signal syscall.Signal ) * f1Stage {
50
60
go func () {
51
61
time .Sleep (duration )
@@ -74,6 +84,20 @@ func (s *f1Stage) a_scenario_where_each_iteration_takes(duration time.Duration)
74
84
return s
75
85
}
76
86
87
+ func (s * f1Stage ) a_scenario_that_logs () * f1Stage {
88
+ s .scenario = "logging_scenario"
89
+ s .f1 .Add (s .scenario , func (sceanrioT * f1_testing.T ) f1_testing.RunFn {
90
+ sceanrioT .Log ("scenario" )
91
+
92
+ return func (* f1_testing.T ) {
93
+ sceanrioT .Log ("iteration" )
94
+ sceanrioT .Logger ().Info ("iteration" )
95
+ }
96
+ })
97
+
98
+ return s
99
+ }
100
+
77
101
func (s * f1Stage ) the_f1_scenario_is_executed_with_constant_rate_and_args (args ... string ) * f1Stage {
78
102
err := s .f1 .ExecuteWithArgs (append ([]string {
79
103
"run" , "constant" , s .scenario ,
@@ -115,3 +139,17 @@ func (s *f1Stage) expect_no_goroutines_to_run() *f1Stage {
115
139
116
140
return s
117
141
}
142
+
143
+ func (s * f1Stage ) expect_all_log_lines_to_contain_attr (key , value string ) * f1Stage {
144
+ lines := strings .Split (s .logOutput .String (), "\n " )
145
+
146
+ s .require .Len (lines , 7 )
147
+
148
+ for _ , line := range lines {
149
+ if line != "" {
150
+ s .require .Contains (line , fmt .Sprintf (" %s=%s " , key , value ))
151
+ }
152
+ }
153
+
154
+ return s
155
+ }
0 commit comments