Skip to content

Commit

Permalink
Add test over csv output deprecation log warning
Browse files Browse the repository at this point in the history
  • Loading branch information
josephwoodward committed Oct 5, 2021
1 parent ac736b0 commit 199248a
Showing 1 changed file with 25 additions and 9 deletions.
34 changes: 25 additions & 9 deletions output/csv/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,12 @@ import (
"testing"
"time"

"go.k6.io/k6/lib/testutils"

"gopkg.in/guregu/null.v3"

"github.com/sirupsen/logrus"
"github.com/sirupsen/logrus/hooks/test"
"github.com/stretchr/testify/assert"

"go.k6.io/k6/lib/testutils"
"go.k6.io/k6/lib/types"
)

Expand Down Expand Up @@ -80,8 +79,9 @@ func TestApply(t *testing.T) {

func TestParseArg(t *testing.T) {
cases := map[string]struct {
config Config
expectedErr bool
config Config
expectedLogEntries []string
expectedErr bool
}{
"test_file.csv": {
config: Config{
Expand All @@ -93,6 +93,9 @@ func TestParseArg(t *testing.T) {
config: Config{
SaveInterval: types.NullDurationFrom(5 * time.Second),
},
expectedLogEntries: []string{
"CSV output argument 'save_interval' is deprecated, please use 'saveInterval' instead.",
},
},
"saveInterval=5s": {
config: Config{
Expand All @@ -104,27 +107,34 @@ func TestParseArg(t *testing.T) {
FileName: null.StringFrom("test.csv"),
SaveInterval: types.NullDurationFrom(5 * time.Second),
},
expectedLogEntries: []string{
"CSV output argument 'file_name' is deprecated, please use 'fileName' instead.",
"CSV output argument 'save_interval' is deprecated, please use 'saveInterval' instead.",
},
},
"fileName=test.csv,save_interval=5s": {
config: Config{
FileName: null.StringFrom("test.csv"),
SaveInterval: types.NullDurationFrom(5 * time.Second),
},
expectedLogEntries: []string{
"CSV output argument 'save_interval' is deprecated, please use 'saveInterval' instead.",
},
},
"filename=test.csv,save_interval=5s": {
expectedErr: true,
},
}

testLog := logrus.New()
testLog.SetOutput(testutils.NewTestOutput(t))

for arg, testCase := range cases {
arg := arg
testCase := testCase

testLogger, hook := test.NewNullLogger()
testLogger.SetOutput(testutils.NewTestOutput(t))

t.Run(arg, func(t *testing.T) {
config, err := ParseArg(arg, testLog)
config, err := ParseArg(arg, testLogger)

if testCase.expectedErr {
assert.Error(t, err)
Expand All @@ -133,6 +143,12 @@ func TestParseArg(t *testing.T) {
}
assert.Equal(t, testCase.config.FileName.String, config.FileName.String)
assert.Equal(t, testCase.config.SaveInterval.String(), config.SaveInterval.String())

var entries []string
for _, v := range hook.AllEntries() {
entries = append(entries, v.Message)
}
assert.ElementsMatch(t, entries, testCase.expectedLogEntries)
})
}
}

0 comments on commit 199248a

Please sign in to comment.