Skip to content

Commit

Permalink
fixup! k6runner/test: ensure logs are sent to loki when runner report…
Browse files Browse the repository at this point in the history
…s user errors
  • Loading branch information
nadiamoe committed Jun 26, 2024
1 parent 20d19cb commit dda07de
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions internal/k6runner/k6runner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ func TestScriptHTTPRun(t *testing.T) {
var (
registry = prometheus.NewRegistry()
logBuf = bytes.Buffer{}
logger = &testLogger{buf: &logBuf}
logger = recordingLogger{buf: &logBuf}
zlogger = zerolog.Nop()
)

Expand Down Expand Up @@ -417,23 +417,30 @@ func TestK6LogsToLogger(t *testing.T) {
require.NoError(t, err)
}

type testLogger struct {
buf *bytes.Buffer
}
type testLogger struct{}

var _ logger.Logger = &testLogger{}

func (l *testLogger) Log(keyvals ...any) error {
if len(keyvals) == 0 {
return errors.New("empty log message")
}
return nil
}

if len(keyvals)%2 != 0 {
return errors.New("not the same number of keys and vals")
type recordingLogger struct {
buf *bytes.Buffer
}

var _ logger.Logger = &recordingLogger{}

func (l recordingLogger) Log(keyvals ...any) error {
if len(keyvals) == 0 {
return errors.New("empty log message")
}

if l.buf == nil {
return nil
if len(keyvals)%2 != 0 {
return errors.New("not the same number of keys and vals")
}

line := make([]string, 0, len(keyvals)/2)
Expand Down

0 comments on commit dda07de

Please sign in to comment.