Skip to content
This repository has been archived by the owner on Apr 23, 2024. It is now read-only.

Commit

Permalink
fix unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kamsz committed Jan 2, 2019
1 parent fbbd885 commit 379bab6
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 16 deletions.
11 changes: 7 additions & 4 deletions plugins/inputs/varnish/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,14 @@ This plugin gathers stats from [Varnish HTTP Cache](https://varnish-cache.org/)
## Optional name for the varnish instance (or working directory) to query
## Usually appened after -n in varnish cli
# instance_name = instanceName

## Timeout for varnishstat command
# timeout = "1s"
```

### Measurements & Fields:

This is the full list of stats provided by varnish. Stats will be grouped by their capitalized prefix (eg MAIN,
This is the full list of stats provided by varnish. Stats will be grouped by their capitalized prefix (eg MAIN,
MEMPOOL, etc). In the output, the prefix will be used as a tag, and removed from field names.

- varnish
Expand Down Expand Up @@ -326,7 +329,7 @@ MEMPOOL, etc). In the output, the prefix will be used as a tag, and removed from

### Tags:

As indicated above, the prefix of a varnish stat will be used as it's 'section' tag. So section tag may have one of
As indicated above, the prefix of a varnish stat will be used as it's 'section' tag. So section tag may have one of
the following values:
- section:
- MAIN
Expand All @@ -335,8 +338,8 @@ the following values:
- SMA
- VBE
- LCK



### Permissions:

Expand Down
12 changes: 6 additions & 6 deletions plugins/inputs/varnish/varnish_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,16 @@ import (
"github.com/stretchr/testify/assert"
)

func fakeVarnishStat(output string, useSudo bool, InstanceName string) func(string, bool, string) (*bytes.Buffer, error) {
return func(string, bool, string) (*bytes.Buffer, error) {
func fakeVarnishStat(output string, useSudo bool, InstanceName string, Timeout string) func(string, bool, string, string) (*bytes.Buffer, error) {
return func(string, bool, string, string) (*bytes.Buffer, error) {
return bytes.NewBuffer([]byte(output)), nil
}
}

func TestGather(t *testing.T) {
acc := &testutil.Accumulator{}
v := &Varnish{
run: fakeVarnishStat(smOutput, false, ""),
run: fakeVarnishStat(smOutput, false, "", "5s"),
Stats: []string{"*"},
}
v.Gather(acc)
Expand All @@ -37,7 +37,7 @@ func TestGather(t *testing.T) {
func TestParseFullOutput(t *testing.T) {
acc := &testutil.Accumulator{}
v := &Varnish{
run: fakeVarnishStat(fullOutput, true, ""),
run: fakeVarnishStat(fullOutput, true, "", "5s"),
Stats: []string{"*"},
}
err := v.Gather(acc)
Expand All @@ -52,7 +52,7 @@ func TestParseFullOutput(t *testing.T) {
func TestFilterSomeStats(t *testing.T) {
acc := &testutil.Accumulator{}
v := &Varnish{
run: fakeVarnishStat(fullOutput, false, ""),
run: fakeVarnishStat(fullOutput, false, "", "5s"),
Stats: []string{"MGT.*", "VBE.*"},
}
err := v.Gather(acc)
Expand All @@ -75,7 +75,7 @@ func TestFieldConfig(t *testing.T) {
for fieldCfg, expected := range expect {
acc := &testutil.Accumulator{}
v := &Varnish{
run: fakeVarnishStat(fullOutput, true, ""),
run: fakeVarnishStat(fullOutput, true, "", "5s"),
Stats: strings.Split(fieldCfg, ","),
}
err := v.Gather(acc)
Expand Down
12 changes: 6 additions & 6 deletions plugins/parsers/grok/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -915,17 +915,17 @@ func TestSyslogTimestamp(t *testing.T) {
{
name: "two digit day of month",
line: "Sep 25 09:01:55 value=42",
expected: time.Date(2018, time.September, 25, 9, 1, 55, 0, time.UTC),
expected: time.Date(2019, time.September, 25, 9, 1, 55, 0, time.UTC),
},
{
name: "one digit day of month single space",
line: "Sep 2 09:01:55 value=42",
expected: time.Date(2018, time.September, 2, 9, 1, 55, 0, time.UTC),
expected: time.Date(2019, time.September, 2, 9, 1, 55, 0, time.UTC),
},
{
name: "one digit day of month double space",
line: "Sep 2 09:01:55 value=42",
expected: time.Date(2018, time.September, 2, 9, 1, 55, 0, time.UTC),
expected: time.Date(2019, time.September, 2, 9, 1, 55, 0, time.UTC),
},
}
for _, tt := range tests {
Expand All @@ -950,11 +950,11 @@ func TestReplaceTimestampComma(t *testing.T) {
}

require.NoError(t, p.Compile())
m, err := p.ParseLine("2018-02-21 13:10:34,555 successfulMatches=1")
m, err := p.ParseLine("2019-02-21 13:10:34,555 successfulMatches=1")
require.NoError(t, err)
require.NotNil(t, m)

require.Equal(t, 2018, m.Time().Year())
require.Equal(t, 2019, m.Time().Year())
require.Equal(t, 13, m.Time().Hour())
require.Equal(t, 34, m.Time().Second())
// Convert nanosecond to millisecond for compare
Expand Down Expand Up @@ -1023,5 +1023,5 @@ func TestEmptyYearInTimestamp(t *testing.T) {
m, err := p.ParseLine("Nov 6 13:57:03 generic iTunes[6504]: objc[6504]: Object descriptor was null.")
require.NoError(t, err)
require.NotNil(t, m)
require.Equal(t, 2018, m.Time().Year())
require.Equal(t, 2019, m.Time().Year())
}

0 comments on commit 379bab6

Please sign in to comment.