11package f1_test
22
33import (
4+ "bytes"
5+ "fmt"
46 "os"
7+ "strings"
58 "sync/atomic"
69 "syscall"
710 "testing"
@@ -11,21 +14,21 @@ import (
1114 "github.com/stretchr/testify/require"
1215 "go.uber.org/goleak"
1316
17+ "github.com/form3tech-oss/f1/v2/internal/log"
1418 "github.com/form3tech-oss/f1/v2/pkg/f1"
1519 f1_testing "github.com/form3tech-oss/f1/v2/pkg/f1/testing"
1620)
1721
1822type 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-
2823 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
2932}
3033
3134func newF1Stage (t * testing.T ) (* f1Stage , * f1Stage , * f1Stage ) {
@@ -46,6 +49,13 @@ func (s *f1Stage) and() *f1Stage {
4649 return s
4750}
4851
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+
4959func (s * f1Stage ) after_duration_signal_will_be_sent (duration time.Duration , signal syscall.Signal ) * f1Stage {
5060 go func () {
5161 time .Sleep (duration )
@@ -74,6 +84,20 @@ func (s *f1Stage) a_scenario_where_each_iteration_takes(duration time.Duration)
7484 return s
7585}
7686
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+
77101func (s * f1Stage ) the_f1_scenario_is_executed_with_constant_rate_and_args (args ... string ) * f1Stage {
78102 err := s .f1 .ExecuteWithArgs (append ([]string {
79103 "run" , "constant" , s .scenario ,
@@ -115,3 +139,17 @@ func (s *f1Stage) expect_no_goroutines_to_run() *f1Stage {
115139
116140 return s
117141}
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