Skip to content

Commit

Permalink
CVS output: linter fixes in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
olegbespalov committed Dec 7, 2023
1 parent e09aa8f commit 6d6fb72
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
11 changes: 11 additions & 0 deletions output/csv/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,17 @@ import (
)

func TestNewConfig(t *testing.T) {
t.Parallel()

config := NewConfig()
assert.Equal(t, "file.csv", config.FileName.String)
assert.Equal(t, "1s", config.SaveInterval.String())
assert.Equal(t, "unix", config.TimeFormat.String)
}

func TestApply(t *testing.T) {
t.Parallel()

configs := []Config{
{
FileName: null.StringFrom(""),
Expand Down Expand Up @@ -52,7 +56,10 @@ func TestApply(t *testing.T) {
for i := range configs {
config := configs[i]
expected := expected[i]

t.Run(expected.FileName+"_"+expected.SaveInterval, func(t *testing.T) {
t.Parallel()

baseConfig := NewConfig()
baseConfig = baseConfig.Apply(config)

Expand All @@ -64,6 +71,8 @@ func TestApply(t *testing.T) {
}

func TestParseArg(t *testing.T) {
t.Parallel()

cases := map[string]struct {
config Config
expectedLogEntries []string
Expand Down Expand Up @@ -100,6 +109,8 @@ func TestParseArg(t *testing.T) {
testCase := testCase

t.Run(arg, func(t *testing.T) {
t.Parallel()

config, err := ParseArg(arg)

if testCase.expectedErr {
Expand Down
13 changes: 11 additions & 2 deletions output/csv/output_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import (
)

func TestMakeHeader(t *testing.T) {
t.Parallel()

testdata := map[string][]string{
"One tag": {
"tag1",
Expand All @@ -33,7 +35,10 @@ func TestMakeHeader(t *testing.T) {

for testname, tags := range testdata {
testname, tags := testname, tags

t.Run(testname, func(t *testing.T) {
t.Parallel()

header := MakeHeader(tags)
assert.Equal(t, len(tags)+5, len(header))
assert.Equal(t, "metric_name", header[0])
Expand All @@ -46,6 +51,8 @@ func TestMakeHeader(t *testing.T) {
}

func TestSampleToRow(t *testing.T) {
t.Parallel()

registry := metrics.NewRegistry()
testMetric, err := registry.NewMetric("my_metric", metrics.Gauge)
require.NoError(t, err)
Expand Down Expand Up @@ -306,6 +313,8 @@ func TestSampleToRow(t *testing.T) {
expectedRow := expected[i]

t.Run(testname, func(t *testing.T) {
t.Parallel()

row := SampleToRow(sample, resTags, ignoredTags, make([]string, 3+len(resTags)+2), timeFormat)
for ind, cell := range expectedRow.baseRow {
assert.Equal(t, cell, row[ind])
Expand All @@ -323,7 +332,7 @@ func readUnCompressedFile(fileName string, fs fsext.Fs) string {
return err.Error()
}

return fmt.Sprintf("%s", csvbytes)
return string(csvbytes)
}

func readCompressedFile(fileName string, fs fsext.Fs) string {
Expand All @@ -342,7 +351,7 @@ func readCompressedFile(fileName string, fs fsext.Fs) string {
return err.Error()
}

return fmt.Sprintf("%s", csvbytes)
return string(csvbytes)
}

func TestRun(t *testing.T) {
Expand Down

0 comments on commit 6d6fb72

Please sign in to comment.