Skip to content

Commit a9bc6ef

Browse files
committed
output_test: fix TestOutputStart expectations and lack of logger
1 parent 23330af commit a9bc6ef

File tree

1 file changed

+14
-28
lines changed

1 file changed

+14
-28
lines changed

output_test.go

+14-28
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@ package sm
22

33
import (
44
"bytes"
5+
"io"
56
"strings"
67
"testing"
78

9+
"github.com/sirupsen/logrus"
810
"github.com/spf13/afero"
911
"github.com/stretchr/testify/require"
1012
"go.k6.io/k6/metrics"
@@ -53,14 +55,12 @@ func TestOutputDescription(t *testing.T) {
5355
require.NotEmpty(t, out.Description())
5456
}
5557

56-
func TestOutputStart(t *testing.T) {
57-
t.Skip("Skipping broken test")
58-
58+
func TestOutputStartStop(t *testing.T) {
5959
t.Parallel()
6060

6161
fs := afero.NewMemMapFs()
6262

63-
out, err := New(output.Params{ConfigArgument: "test.out", FS: fs})
63+
out, err := New(output.Params{ConfigArgument: "test.out", FS: fs, Logger: nopLogger()})
6464
require.NoError(t, err)
6565

6666
err = out.Start()
@@ -69,34 +69,13 @@ func TestOutputStart(t *testing.T) {
6969
err = out.Stop()
7070
require.NoError(t, err)
7171

72-
// At this point we should have an empty file.
73-
fi, err := fs.Stat("test.out")
74-
require.NoError(t, err)
75-
require.Equal(t, int64(0), fi.Size())
76-
}
77-
78-
// TestOutputStop tests that the metrics are correctly collected and written to the file.
79-
func TestOutputStop(t *testing.T) {
80-
t.Skip("Skipping broken test")
81-
82-
t.Parallel()
83-
84-
fs := afero.NewMemMapFs()
85-
86-
out, err := New(output.Params{ConfigArgument: "test.out", FS: fs})
87-
require.NoError(t, err)
88-
89-
err = out.Start()
72+
fileOut, err := fs.Open("test.out")
9073
require.NoError(t, err)
9174

92-
// TODO(mem): add samples
93-
94-
err = out.Stop()
75+
output, err := io.ReadAll(fileOut)
9576
require.NoError(t, err)
9677

97-
fi, err := fs.Stat("test.out")
98-
require.NoError(t, err)
99-
require.Equal(t, int64(0), fi.Size())
78+
require.Contains(t, string(output), "probe_script_duration_seconds")
10079
}
10180

10281
func makeSample(name string, value float64) metrics.Sample {
@@ -660,3 +639,10 @@ func TestTargetMetricsCollectionWriteMany(t *testing.T) {
660639

661640
require.Equal(t, expected, buf.String())
662641
}
642+
643+
func nopLogger() *logrus.Logger {
644+
l := logrus.New()
645+
l.SetOutput(io.Discard)
646+
647+
return l
648+
}

0 commit comments

Comments
 (0)