Skip to content

Commit 0fcfee0

Browse files
authored
Fix tests for Windows - part 1 (influxdata#8414)
1 parent d64c722 commit 0fcfee0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+416
-253
lines changed

Diff for: .gitattributes

+1
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ README.md merge=union
33
go.sum merge=union
44
plugins/inputs/all/all.go merge=union
55
plugins/outputs/all/all.go merge=union
6+
**/testdata/** test eol=lf

Diff for: Makefile

+1-6
Original file line numberDiff line numberDiff line change
@@ -114,12 +114,7 @@ fmtcheck:
114114

115115
.PHONY: test-windows
116116
test-windows:
117-
go test -short $(race_detector) ./plugins/inputs/ping/...
118-
go test -short $(race_detector) ./plugins/inputs/win_perf_counters/...
119-
go test -short $(race_detector) ./plugins/inputs/win_services/...
120-
go test -short $(race_detector) ./plugins/inputs/procstat/...
121-
go test -short $(race_detector) ./plugins/inputs/ntpq/...
122-
go test -short $(race_detector) ./plugins/processors/port_name/...
117+
go test -short ./...
123118

124119
.PHONY: vet
125120
vet:

Diff for: appveyor.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ clone_folder: C:\gopath\src\github.com\influxdata\telegraf
1212
environment:
1313
GOPATH: C:\gopath
1414

15-
stack: go 1.14
15+
stack: go 1.15
1616

1717
platform: x64
1818

Diff for: config/config_test.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package config
22

33
import (
44
"os"
5+
"strings"
56
"testing"
67
"time"
78

@@ -201,7 +202,7 @@ func TestConfig_LoadSpecialTypes(t *testing.T) {
201202
// Tests telegraf size parsing.
202203
assert.Equal(t, internal.Size{Size: 1024 * 1024}, inputHTTPListener.MaxBodySize)
203204
// Tests toml multiline basic strings.
204-
assert.Equal(t, "/path/to/my/cert\n", inputHTTPListener.TLSCert)
205+
assert.Equal(t, "/path/to/my/cert", strings.TrimRight(inputHTTPListener.TLSCert, "\r\n"))
205206
}
206207

207208
func TestConfig_FieldNotDefined(t *testing.T) {

Diff for: config/testdata/telegraf-agent.toml

-8
Original file line numberDiff line numberDiff line change
@@ -176,14 +176,6 @@
176176
# If no servers are specified, then 127.0.0.1 is used as the host and 4020 as the port.
177177
servers = ["127.0.0.1:4021"]
178178

179-
# Read metrics from local Lustre service on OST, MDS
180-
[[inputs.lustre2]]
181-
# An array of /proc globs to search for Lustre stats
182-
# If not specified, the default will work on Lustre 2.5.x
183-
#
184-
# ost_procfiles = ["/proc/fs/lustre/obdfilter/*/stats", "/proc/fs/lustre/osd-ldiskfs/*/stats"]
185-
# mds_procfiles = ["/proc/fs/lustre/mdt/*/md_stats"]
186-
187179
# Read metrics about memory usage
188180
[[inputs.mem]]
189181
# no configuration

Diff for: internal/globpath/globpath_test.go

+35-19
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,38 @@
1+
// +build !windows
2+
3+
// TODO: Windows - should be enabled for Windows when super asterisk is fixed on Windows
4+
// https://github.com/influxdata/telegraf/issues/6248
5+
16
package globpath
27

38
import (
9+
"os"
10+
"path/filepath"
411
"runtime"
5-
"strings"
612
"testing"
713

814
"github.com/stretchr/testify/require"
915
)
1016

17+
var (
18+
testdataDir = getTestdataDir()
19+
)
20+
1121
func TestCompileAndMatch(t *testing.T) {
12-
dir := getTestdataDir()
1322
// test super asterisk
14-
g1, err := Compile(dir + "/**")
23+
g1, err := Compile(filepath.Join(testdataDir, "**"))
1524
require.NoError(t, err)
1625
// test single asterisk
17-
g2, err := Compile(dir + "/*.log")
26+
g2, err := Compile(filepath.Join(testdataDir, "*.log"))
1827
require.NoError(t, err)
1928
// test no meta characters (file exists)
20-
g3, err := Compile(dir + "/log1.log")
29+
g3, err := Compile(filepath.Join(testdataDir, "log1.log"))
2130
require.NoError(t, err)
2231
// test file that doesn't exist
23-
g4, err := Compile(dir + "/i_dont_exist.log")
32+
g4, err := Compile(filepath.Join(testdataDir, "i_dont_exist.log"))
2433
require.NoError(t, err)
2534
// test super asterisk that doesn't exist
26-
g5, err := Compile(dir + "/dir_doesnt_exist/**")
35+
g5, err := Compile(filepath.Join(testdataDir, "dir_doesnt_exist", "**"))
2736
require.NoError(t, err)
2837

2938
matches := g1.Match()
@@ -39,15 +48,14 @@ func TestCompileAndMatch(t *testing.T) {
3948
}
4049

4150
func TestRootGlob(t *testing.T) {
42-
dir := getTestdataDir()
4351
tests := []struct {
4452
input string
4553
output string
4654
}{
47-
{dir + "/**", dir + "/*"},
48-
{dir + "/nested?/**", dir + "/nested?/*"},
49-
{dir + "/ne**/nest*", dir + "/ne*"},
50-
{dir + "/nested?/*", ""},
55+
{filepath.Join(testdataDir, "**"), filepath.Join(testdataDir, "*")},
56+
{filepath.Join(testdataDir, "nested?", "**"), filepath.Join(testdataDir, "nested?", "*")},
57+
{filepath.Join(testdataDir, "ne**", "nest*"), filepath.Join(testdataDir, "ne*")},
58+
{filepath.Join(testdataDir, "nested?", "*"), ""},
5159
}
5260

5361
for _, test := range tests {
@@ -57,21 +65,19 @@ func TestRootGlob(t *testing.T) {
5765
}
5866

5967
func TestFindNestedTextFile(t *testing.T) {
60-
dir := getTestdataDir()
6168
// test super asterisk
62-
g1, err := Compile(dir + "/**.txt")
69+
g1, err := Compile(filepath.Join(testdataDir, "**.txt"))
6370
require.NoError(t, err)
6471

6572
matches := g1.Match()
6673
require.Len(t, matches, 1)
6774
}
6875

69-
func getTestdataDir() string {
70-
_, filename, _, _ := runtime.Caller(1)
71-
return strings.Replace(filename, "globpath_test.go", "testdata", 1)
72-
}
73-
7476
func TestMatch_ErrPermission(t *testing.T) {
77+
if runtime.GOOS == "windows" {
78+
t.Skip("Skipping Unix only test")
79+
}
80+
7581
tests := []struct {
7682
input string
7783
expected []string
@@ -98,3 +104,13 @@ func TestWindowsSeparator(t *testing.T) {
98104
ok := glob.MatchString("testdata\\nested1")
99105
require.True(t, ok)
100106
}
107+
108+
func getTestdataDir() string {
109+
dir, err := os.Getwd()
110+
if err != nil {
111+
// if we cannot even establish the test directory, further progress is meaningless
112+
panic(err)
113+
}
114+
115+
return filepath.Join(dir, "testdata")
116+
}

Diff for: plugins/inputs/bcache/README.md

+9-9
Original file line numberDiff line numberDiff line change
@@ -56,15 +56,15 @@ cache_readaheads
5656
Using this configuration:
5757

5858
```toml
59-
[bcache]
60-
# Bcache sets path
61-
# If not specified, then default is:
62-
# bcachePath = "/sys/fs/bcache"
63-
#
64-
# By default, telegraf gather stats for all bcache devices
65-
# Setting devices will restrict the stats to the specified
66-
# bcache devices.
67-
# bcacheDevs = ["bcache0", ...]
59+
[[inputs.bcache]]
60+
## Bcache sets path
61+
## If not specified, then default is:
62+
bcachePath = "/sys/fs/bcache"
63+
64+
## By default, Telegraf gather stats for all bcache devices
65+
## Setting devices will restrict the stats to the specified
66+
## bcache devices.
67+
bcacheDevs = ["bcache0"]
6868
```
6969

7070
When run with:

Diff for: plugins/inputs/bcache/bcache.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
// +build !windows
2+
3+
// bcache doesn't aim for Windows
4+
15
package bcache
26

37
import (
@@ -22,7 +26,7 @@ var sampleConfig = `
2226
## If not specified, then default is:
2327
bcachePath = "/sys/fs/bcache"
2428
25-
## By default, telegraf gather stats for all bcache devices
29+
## By default, Telegraf gather stats for all bcache devices
2630
## Setting devices will restrict the stats to the specified
2731
## bcache devices.
2832
bcacheDevs = ["bcache0"]

Diff for: plugins/inputs/bcache/bcache_test.go

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// +build !windows
2+
13
package bcache
24

35
import (

Diff for: plugins/inputs/bcache/bcache_windows.go

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// +build windows
2+
3+
package bcache

Diff for: plugins/inputs/ceph/ceph_test.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import (
44
"fmt"
55
"io/ioutil"
66
"os"
7-
"path"
7+
"path/filepath"
88
"strconv"
99
"strings"
1010
"testing"
@@ -163,7 +163,7 @@ func assertFoundSocket(t *testing.T, dir, sockType string, i int, sockets []*soc
163163
} else {
164164
prefix = monPrefix
165165
}
166-
expected := path.Join(dir, sockFile(prefix, i))
166+
expected := filepath.Join(dir, sockFile(prefix, i))
167167
found := false
168168
for _, s := range sockets {
169169
fmt.Printf("Checking %s\n", s.socket)
@@ -183,7 +183,7 @@ func sockFile(prefix string, i int) string {
183183
func createTestFiles(dir string, st *SockTest) {
184184
writeFile := func(prefix string, i int) {
185185
f := sockFile(prefix, i)
186-
fpath := path.Join(dir, f)
186+
fpath := filepath.Join(dir, f)
187187
ioutil.WriteFile(fpath, []byte(""), 0777)
188188
}
189189
tstFileApply(st, writeFile)
@@ -192,7 +192,7 @@ func createTestFiles(dir string, st *SockTest) {
192192
func cleanupTestFiles(dir string, st *SockTest) {
193193
rmFile := func(prefix string, i int) {
194194
f := sockFile(prefix, i)
195-
fpath := path.Join(dir, f)
195+
fpath := filepath.Join(dir, f)
196196
err := os.Remove(fpath)
197197
if err != nil {
198198
fmt.Printf("Error removing test file %s: %v\n", fpath, err)

Diff for: plugins/inputs/disk/disk_test.go

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package disk
22

33
import (
4+
"fmt"
45
"os"
56
"testing"
67

@@ -74,13 +75,13 @@ func TestDiskUsage(t *testing.T) {
7475
assert.Equal(t, expectedAllDiskMetrics, numDiskMetrics)
7576

7677
tags1 := map[string]string{
77-
"path": "/",
78+
"path": string(os.PathSeparator),
7879
"fstype": "ext4",
7980
"device": "sda",
8081
"mode": "ro",
8182
}
8283
tags2 := map[string]string{
83-
"path": "/home",
84+
"path": fmt.Sprintf("%chome", os.PathSeparator),
8485
"fstype": "ext4",
8586
"device": "sdb",
8687
"mode": "rw",
@@ -144,7 +145,7 @@ func TestDiskUsageHostMountPrefix(t *testing.T) {
144145
},
145146
},
146147
expectedTags: map[string]string{
147-
"path": "/",
148+
"path": string(os.PathSeparator),
148149
"device": "sda",
149150
"fstype": "ext4",
150151
"mode": "ro",
@@ -177,7 +178,7 @@ func TestDiskUsageHostMountPrefix(t *testing.T) {
177178
},
178179
hostMountPrefix: "/hostfs",
179180
expectedTags: map[string]string{
180-
"path": "/var",
181+
"path": fmt.Sprintf("%cvar", os.PathSeparator),
181182
"device": "sda",
182183
"fstype": "ext4",
183184
"mode": "ro",
@@ -210,7 +211,7 @@ func TestDiskUsageHostMountPrefix(t *testing.T) {
210211
},
211212
hostMountPrefix: "/hostfs",
212213
expectedTags: map[string]string{
213-
"path": "/",
214+
"path": string(os.PathSeparator),
214215
"device": "sda",
215216
"fstype": "ext4",
216217
"mode": "ro",

Diff for: plugins/inputs/exec/exec_test.go

+5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
// +build !windows
2+
3+
// TODO: Windows - should be enabled for Windows when super asterisk is fixed on Windows
4+
// https://github.com/influxdata/telegraf/issues/6248
5+
16
package exec
27

38
import (

Diff for: plugins/inputs/execd/execd_test.go

+4-7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
// +build !windows
2-
31
package execd
42

53
import (
@@ -11,17 +9,16 @@ import (
119
"testing"
1210
"time"
1311

12+
"github.com/stretchr/testify/require"
13+
14+
"github.com/influxdata/telegraf"
1415
"github.com/influxdata/telegraf/agent"
1516
"github.com/influxdata/telegraf/config"
1617
"github.com/influxdata/telegraf/metric"
1718
"github.com/influxdata/telegraf/models"
18-
"github.com/influxdata/telegraf/testutil"
19-
"github.com/stretchr/testify/require"
20-
2119
"github.com/influxdata/telegraf/plugins/parsers"
2220
"github.com/influxdata/telegraf/plugins/serializers"
23-
24-
"github.com/influxdata/telegraf"
21+
"github.com/influxdata/telegraf/testutil"
2522
)
2623

2724
func TestSettingConfigWorks(t *testing.T) {

Diff for: plugins/inputs/execd/shim/shim_posix_test.go

-5
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
77
"context"
88
"io"
99
"os"
10-
"runtime"
1110
"syscall"
1211
"testing"
1312
"time"
@@ -16,10 +15,6 @@ import (
1615
)
1716

1817
func TestShimUSR1SignalingWorks(t *testing.T) {
19-
if runtime.GOOS == "windows" {
20-
t.Skip()
21-
return
22-
}
2318
stdinReader, stdinWriter := io.Pipe()
2419
stdoutReader, stdoutWriter := io.Pipe()
2520

Diff for: plugins/inputs/file/file_test.go

+5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
// +build !windows
2+
3+
// TODO: Windows - should be enabled for Windows when super asterisk is fixed on Windows
4+
// https://github.com/influxdata/telegraf/issues/6248
5+
16
package file
27

38
import (

Diff for: plugins/inputs/filecount/filecount_test.go

+5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
// +build !windows
2+
3+
// TODO: Windows - should be enabled for Windows when super asterisk is fixed on Windows
4+
// https://github.com/influxdata/telegraf/issues/6248
5+
16
package filecount
27

38
import (

Diff for: plugins/inputs/filecount/filesystem_helpers_test.go

+5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
// +build !windows
2+
3+
// TODO: Windows - should be enabled for Windows when super asterisk is fixed on Windows
4+
// https://github.com/influxdata/telegraf/issues/6248
5+
16
package filecount
27

38
import (

0 commit comments

Comments
 (0)