Skip to content

Commit 2672d84

Browse files
authored
Merge pull request #45 from nao1215/add-platform-unit-test-workflow
Add platform test workflow
2 parents 9e3fc5e + 0f5ae37 commit 2672d84

File tree

13 files changed

+537
-276
lines changed

13 files changed

+537
-276
lines changed
+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
name: MultiVersionUnitTest
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
branches: [main]
8+
9+
jobs:
10+
unit-test:
11+
runs-on: ubuntu-latest
12+
strategy:
13+
matrix:
14+
go-version: ["1.18", "1.19"]
15+
steps:
16+
- uses: actions/checkout@v3
17+
- name: Setup Go ${{ matrix.go-version }}
18+
uses: actions/setup-go@v3
19+
with:
20+
go-version: ${{ matrix.go-version }}
21+
22+
- name: MultiVersionUnitTest
23+
run: make test

.github/workflows/platform_test.yml

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
name: PlatformTests
2+
3+
on:
4+
workflow_dispatch:
5+
push:
6+
branches: [main]
7+
pull_request:
8+
branches: [main]
9+
10+
jobs:
11+
unit_test:
12+
name: Unit test
13+
14+
strategy:
15+
matrix:
16+
platform: [ubuntu-latest, macos-latest, windows-latest]
17+
18+
runs-on: ${{ matrix.platform }}
19+
20+
steps:
21+
- uses: actions/checkout@v3
22+
23+
- uses: actions/setup-go@v3
24+
with:
25+
go-version: "1"
26+
check-latest: true
27+
28+
- name: Run unit test
29+
run: |
30+
go mod download
31+
go test -race -v ./...

.github/workflows/unit_test.yml

-21
This file was deleted.

cmd/check_test.go

+47-30
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import (
44
"bytes"
55
"io"
66
"os"
7+
"path/filepath"
8+
"runtime"
79
"strings"
810
"testing"
911

@@ -19,28 +21,16 @@ func Test_check(t *testing.T) {
1921
args []string
2022
}
2123
tests := []struct {
22-
name string
23-
gobin string
24-
args args
25-
want int
26-
stdout []string
24+
name string
25+
gobin string
26+
args args
27+
want int
2728
}{
2829
{
29-
name: "detect old version command",
30-
gobin: "./testdata/check_success",
30+
name: "not go install command in $GOBIN",
31+
gobin: filepath.Join("testdata", "check_fail"),
3132
args: args{},
32-
want: 0,
33-
stdout: []string{
34-
" $ gup update subaru gal posixer ",
35-
"",
36-
},
37-
},
38-
{
39-
name: "not go install command in $GOBIN",
40-
gobin: "./testdata/check_fail",
41-
args: args{},
42-
want: 1,
43-
stdout: []string{},
33+
want: 1,
4434
},
4535
}
4636
for _, tt := range tests {
@@ -83,9 +73,6 @@ func Test_check(t *testing.T) {
8373
defer pr.Close()
8474
got := strings.Split(buf.String(), "\n")
8575

86-
if !strings.Contains(got[len(got)-2], "subaru") {
87-
t.Errorf("subaru package is not included in the update target: %s", got[len(got)-2])
88-
}
8976
if !strings.Contains(got[len(got)-2], "posixer") {
9077
t.Errorf("posixer package is not included in the update target: %s", got[len(got)-2])
9178
}
@@ -132,9 +119,13 @@ func Test_check_not_use_go_cmd(t *testing.T) {
132119
defer pr.Close()
133120
got := strings.Split(buf.String(), "\n")
134121

135-
want := []string{
136-
`gup:ERROR: you didn't install golang: exec: "go": executable file not found in $PATH`,
137-
"",
122+
want := []string{}
123+
if runtime.GOOS == "windows" {
124+
want = append(want, `gup:ERROR: you didn't install golang: exec: "go": executable file not found in %PATH%`)
125+
want = append(want, "")
126+
} else {
127+
want = append(want, `gup:ERROR: you didn't install golang: exec: "go": executable file not found in $PATH`)
128+
want = append(want, "")
138129
}
139130
if diff := cmp.Diff(want, got); diff != "" {
140131
t.Errorf("value is mismatch (-want +got):\n%s", diff)
@@ -156,15 +147,41 @@ func Test_check_gobin_is_empty(t *testing.T) {
156147
}{
157148
{
158149
name: "gobin is empty",
159-
gobin: "./testdata/empty_dir",
150+
gobin: filepath.Join("testdata", "empty_dir"),
160151
args: args{},
161152
want: 1,
162153
stderr: []string{
163154
"gup:ERROR: unable to check package: no package information",
164155
"",
165156
},
166157
},
167-
{
158+
}
159+
160+
if runtime.GOOS == "windows" {
161+
tests = append(tests, struct {
162+
name string
163+
gobin string
164+
args args
165+
want int
166+
stderr []string
167+
}{
168+
name: "$GOBIN is empty",
169+
gobin: "no_exist_dir",
170+
args: args{},
171+
want: 1,
172+
stderr: []string{
173+
"gup:ERROR: can't get binary-paths installed by 'go install': open no_exist_dir: The system cannot find the file specified.",
174+
"",
175+
},
176+
})
177+
} else {
178+
tests = append(tests, struct {
179+
name string
180+
gobin string
181+
args args
182+
want int
183+
stderr []string
184+
}{
168185
name: "$GOBIN is empty",
169186
gobin: "no_exist_dir",
170187
args: args{},
@@ -173,10 +190,10 @@ func Test_check_gobin_is_empty(t *testing.T) {
173190
"gup:ERROR: can't get binary-paths installed by 'go install': open no_exist_dir: no such file or directory",
174191
"",
175192
},
176-
},
193+
})
177194
}
178195

179-
if err := os.Mkdir("./testdata/empty_dir", 0755); err != nil {
196+
if err := os.Mkdir(filepath.Join("testdata", "empty_dir"), 0755); err != nil {
180197
t.Fatal(err)
181198
}
182199

@@ -222,7 +239,7 @@ func Test_check_gobin_is_empty(t *testing.T) {
222239
})
223240
}
224241

225-
err := os.Remove("./testdata/empty_dir")
242+
err := os.Remove(filepath.Join("testdata", "empty_dir"))
226243
if err != nil {
227244
t.Fatal(err)
228245
}

cmd/export_test.go

+53-14
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ import (
44
"bytes"
55
"io"
66
"os"
7+
"path/filepath"
78
"reflect"
9+
"runtime"
810
"strings"
911
"testing"
1012

@@ -82,10 +84,15 @@ func Test_export_not_use_go_cmd(t *testing.T) {
8284
defer pr.Close()
8385
got := strings.Split(buf.String(), "\n")
8486

85-
want := []string{
86-
`gup:ERROR: you didn't install golang: exec: "go": executable file not found in $PATH`,
87-
"",
87+
want := []string{}
88+
if runtime.GOOS == "windows" {
89+
want = append(want, `gup:ERROR: you didn't install golang: exec: "go": executable file not found in %PATH%`)
90+
want = append(want, "")
91+
} else {
92+
want = append(want, `gup:ERROR: you didn't install golang: exec: "go": executable file not found in $PATH`)
93+
want = append(want, "")
8894
}
95+
8996
if diff := cmp.Diff(want, got); diff != "" {
9097
t.Errorf("value is mismatch (-want +got):\n%s", diff)
9198
}
@@ -115,33 +122,65 @@ func Test_export(t *testing.T) {
115122
stderr: []string{},
116123
},
117124
{
118-
name: "not exist gobin directory",
125+
name: "no package information",
119126
args: args{
120127
cmd: &cobra.Command{},
121128
args: []string{},
122129
},
123-
gobin: "testdata/dummy",
130+
gobin: filepath.Join("testdata", "text"),
124131
want: 1,
125132
stderr: []string{
126-
"gup:ERROR: can't get binary-paths installed by 'go install': open testdata/dummy: no such file or directory",
133+
"gup:WARN : can't get 'dummy.txt'package path information. old go version binary",
134+
"gup:ERROR: no package information",
127135
"",
128136
},
129137
},
130-
{
131-
name: "no package information",
138+
}
139+
140+
if runtime.GOOS == "windows" {
141+
tests = append(tests, struct {
142+
name string
143+
args args
144+
gobin string
145+
want int
146+
stderr []string
147+
}{
148+
149+
name: "not exist gobin directory",
132150
args: args{
133151
cmd: &cobra.Command{},
134152
args: []string{},
135153
},
136-
gobin: "testdata/text",
154+
gobin: filepath.Join("testdata", "dummy"),
137155
want: 1,
138156
stderr: []string{
139-
"gup:WARN : can't get 'dummy.txt'package path information. old go version binary",
140-
"gup:ERROR: no package information",
157+
"gup:ERROR: can't get binary-paths installed by 'go install': open " + filepath.Join("testdata", "dummy") + ": The system cannot find the file specified.",
141158
"",
142159
},
143-
},
160+
})
161+
} else {
162+
tests = append(tests, struct {
163+
name string
164+
args args
165+
gobin string
166+
want int
167+
stderr []string
168+
}{
169+
170+
name: "not exist gobin directory",
171+
args: args{
172+
cmd: &cobra.Command{},
173+
args: []string{},
174+
},
175+
gobin: filepath.Join("testdata", "dummy"),
176+
want: 1,
177+
stderr: []string{
178+
"gup:ERROR: can't get binary-paths installed by 'go install': open " + filepath.Join("testdata", "dummy") + ": no such file or directory",
179+
"",
180+
},
181+
})
144182
}
183+
145184
for _, tt := range tests {
146185
t.Run(tt.name, func(t *testing.T) {
147186
oldGoBin := os.Getenv("GOBIN")
@@ -156,7 +195,7 @@ func Test_export(t *testing.T) {
156195

157196
if tt.name == "can not make .config directory" {
158197
oldHome := os.Getenv("HOME")
159-
if err := os.Setenv("HOME", "/root"); err != nil {
198+
if err := os.Setenv("HOME", filepath.Join("/", "root")); err != nil {
160199
t.Fatal(err)
161200
}
162201
defer func() {
@@ -195,7 +234,7 @@ func Test_export(t *testing.T) {
195234
t.Errorf("value is mismatch (-want +got):\n%s", diff)
196235
}
197236
} else {
198-
if file.IsFile("/.config") {
237+
if file.IsFile(filepath.Join("/", ".config")) {
199238
t.Errorf("permissions are incomplete because '/.config' was created")
200239
}
201240
}

cmd/import_test.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package cmd
22

33
import (
44
"os"
5+
"path/filepath"
56
"testing"
67

78
"github.com/spf13/cobra"
@@ -42,7 +43,7 @@ func Test_runImport(t *testing.T) {
4243
cmd: &cobra.Command{},
4344
args: []string{},
4445
},
45-
home: "./testdata/empty_conf",
46+
home: filepath.Join("testdata", "empty_conf"),
4647
want: 1,
4748
},
4849
{
@@ -51,7 +52,7 @@ func Test_runImport(t *testing.T) {
5152
cmd: &cobra.Command{},
5253
args: []string{},
5354
},
54-
home: "./testdata/can_not_read_conf",
55+
home: filepath.Join("testdata", "can_not_read_conf"),
5556
want: 1,
5657
},
5758
}

0 commit comments

Comments
 (0)