Skip to content

Commit 95fb8d2

Browse files
authored
Merge pull request mackerelio#678 from mackerelio/lint-os
combine lint, lint-windows, fix test on windows.
2 parents 60d9e28 + f998867 commit 95fb8d2

22 files changed

+65
-60
lines changed

.github/workflows/test.yml

Lines changed: 16 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -14,29 +14,20 @@ jobs:
1414
lint:
1515
strategy:
1616
matrix:
17-
os: [ubuntu-latest, macos-latest]
18-
runs-on: ${{ matrix.os }}
19-
steps:
20-
- uses: actions/checkout@v3
21-
- uses: golangci/golangci-lint-action@v3
22-
lint-windows:
23-
strategy:
24-
matrix:
25-
os: [windows-latest]
17+
os: [ubuntu-latest, macos-latest, windows-latest]
2618
runs-on: ${{ matrix.os }}
2719
steps:
2820
- uses: actions/checkout@v3
2921
- uses: golangci/golangci-lint-action@v3
3022
with:
31-
args: --timeout 2m ./check-log/... ./check-procs/... ./check-ntservice/... ./check-windows-eventlog/...
23+
args: --timeout 5m
3224
test:
3325
strategy:
3426
matrix:
3527
go: ["1.19.x", "1.18.x"]
36-
os: [ubuntu-latest]
28+
os: [ubuntu-latest, windows-latest]
3729
runs-on: ${{ matrix.os }}
3830
steps:
39-
- run: sudo apt-get install memcached
4031
- uses: actions/setup-go@v2
4132
with:
4233
go-version: ${{ matrix.go }}
@@ -49,8 +40,20 @@ jobs:
4940
${{ runner.os }}-go-
5041
- run: |
5142
go test -race -covermode=atomic -coverprofile=prof.out ./...
43+
shell: bash
44+
- if: matrix.os == 'ubuntu-latest'
45+
run: |
5246
./test.bash
5347
make testconvention
48+
- if: matrix.os == 'windows-latest'
49+
run: |
50+
go build -o check-log/check-log.exe ./check-log
51+
go build -o check-procs/check-procs.exe ./check-procs
52+
go build -o check-windows-eventlog/check-windows-evenglog.exe ./check-windows-eventlog
53+
go build -o check-ntservice/check-ntservice.exe ./check-ntservice
54+
go build -o check-disk/check-disk.exe ./check-disk
55+
go build -o check-uptime/check-uptime.exe ./check-uptime
56+
go build -o check-tcp/check-tcp.exe ./check-tcp
5457
- uses: shogo82148/actions-goveralls@v1
5558
with:
5659
github-token: ${{ secrets.GITHUB_TOKEN }}
@@ -65,29 +68,8 @@ jobs:
6568
with:
6669
github-token: ${{ secrets.GITHUB_TOKEN }}
6770
parallel-finished: true
68-
test-windows:
69-
strategy:
70-
matrix:
71-
go: ["1.19.x", "1.18.x"]
72-
runs-on: windows-latest
73-
steps:
74-
- uses: actions/setup-go@v2
75-
with:
76-
go-version: ${{ matrix.go }}
77-
- uses: actions/checkout@v2
78-
- uses: actions/cache@v2
79-
with:
80-
path: ~/go/pkg/mod
81-
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
82-
restore-keys: |
83-
${{ runner.os }}-go-
84-
- run: |
85-
go build -o check-log/check-log.exe ./check-log
86-
go build -o check-procs/check-procs.exe ./check-procs
87-
go build -o check-windows-eventlog/check-windows-evenglog.exe ./check-windows-eventlog
88-
go test ./check-log/... ./check-procs/... ./check-ntservice/... ./check-windows-eventlog/...
8971
build:
90-
needs: [test, test-windows]
72+
needs: test
9173
runs-on: ubuntu-latest
9274
if: github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/tags/v')
9375
steps:

check-aws-cloudwatch-logs/lib/check-aws-cloudwatch-logs_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//go:build !windows
2+
13
package checkawscloudwatchlogs
24

35
import (

check-file-size/lib/check_file_size.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,8 @@ func listFiles(base string, depth int) ([]string, error) {
7272
}
7373

7474
rel, _ := filepath.Rel(base, path)
75-
if len(strings.Split(rel, "/")) > depth {
75+
s := string(filepath.Separator)
76+
if len(strings.Split(rel, s)) > depth {
7677
return nil
7778
}
7879
files = append(files, path)

check-file-size/lib/check_file_size_test.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package checkfilesize
22

33
import (
44
"fmt"
5+
"path/filepath"
56
"reflect"
67
"sort"
78
"testing"
@@ -53,12 +54,13 @@ func TestSizeValueWithInvalidInput(t *testing.T) {
5354
}
5455

5556
func TestListFiles(t *testing.T) {
57+
s := string(filepath.Separator)
5658
// map[depth] = expected files
5759
var testData = map[int][]string{
58-
1: []string{"test_dir/file1"},
59-
2: []string{"test_dir/file1", "test_dir/depth1/file2"},
60-
3: []string{"test_dir/file1", "test_dir/depth1/file2", "test_dir/depth1/depth2/file3"},
61-
4: []string{"test_dir/file1", "test_dir/depth1/file2", "test_dir/depth1/depth2/file3"},
60+
1: {"test_dir" + s + "file1"},
61+
2: {"test_dir" + s + "file1", "test_dir" + s + "depth1" + s + "file2"},
62+
3: {"test_dir" + s + "file1", "test_dir" + s + "depth1" + s + "file2", "test_dir" + s + "depth1" + s + "depth2" + s + "file3"},
63+
4: {"test_dir" + s + "file1", "test_dir" + s + "depth1" + s + "file2", "test_dir" + s + "depth1" + s + "depth2" + s + "file3"},
6264
}
6365
for depth, expects := range testData {
6466
files, err := listFiles("test_dir", depth)

check-ldap/lib/check_ldap_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// +build docker
1+
//go:build docker
22

33
package checkldap
44

check-load/lib/check_load.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//go:build !windows
2+
13
package checkload
24

35
import (
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
package checkload
22

33
import (
4-
"github.com/mackerelio/go-osstat/loadavg"
4+
"github.com/mackerelio/go-osstat/loadavg"
55
)
66

77
func getloadavg() (loadavgs [3]float64, err error) {
8-
output, err := loadavg.Get()
9-
loadavgs = [3]float64{output.Loadavg1,output.Loadavg5,output.Loadavg15}
8+
output, err := loadavg.Get()
9+
loadavgs = [3]float64{output.Loadavg1, output.Loadavg5, output.Loadavg15}
1010

11-
return loadavgs, nil
11+
return loadavgs, nil
1212
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
//go:build windows
2+
3+
package checkload
4+
5+
// Do the plugin
6+
func Do() {
7+
panic("The check-load does not work on Windows environment.")
8+
}

check-log/lib/check-log_unix.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// +build !windows
1+
//go:build !windows
22

33
package checklog
44

check-log/lib/check-log_unix_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// +build !windows
1+
//go:build !windows
22

33
package checklog
44

0 commit comments

Comments
 (0)