Skip to content

Commit

Permalink
Fix hard-coded path concatenation.
Browse files Browse the repository at this point in the history
  • Loading branch information
nao1215 committed Sep 18, 2022
1 parent 17d3677 commit fb3c119
Show file tree
Hide file tree
Showing 6 changed files with 122 additions and 92 deletions.
10 changes: 5 additions & 5 deletions cmd/check_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func Test_check(t *testing.T) {
}{
{
name: "not go install command in $GOBIN",
gobin: "./testdata/check_fail",
gobin: filepath.Join("testdata", "check_fail"),
args: args{},
want: 1,
stdout: []string{},
Expand Down Expand Up @@ -62,7 +62,7 @@ func Test_check(t *testing.T) {
stdout []string
}{
name: "detect old version command",
gobin: "./testdata/check_success",
gobin: filepath.Join("testdata", "check_success"),
args: args{},
want: 0,
stdout: []string{
Expand Down Expand Up @@ -185,7 +185,7 @@ func Test_check_gobin_is_empty(t *testing.T) {
}{
{
name: "gobin is empty",
gobin: "./testdata/empty_dir",
gobin: filepath.Join("testdata", "empty_dir"),
args: args{},
want: 1,
stderr: []string{
Expand Down Expand Up @@ -231,7 +231,7 @@ func Test_check_gobin_is_empty(t *testing.T) {
})
}

if err := os.Mkdir("./testdata/empty_dir", 0755); err != nil {
if err := os.Mkdir(filepath.Join("testdata", "empty_dir"), 0755); err != nil {
t.Fatal(err)
}

Expand Down Expand Up @@ -277,7 +277,7 @@ func Test_check_gobin_is_empty(t *testing.T) {
})
}

err := os.Remove("./testdata/empty_dir")
err := os.Remove(filepath.Join("testdata", "empty_dir"))
if err != nil {
t.Fatal(err)
}
Expand Down
11 changes: 6 additions & 5 deletions cmd/export_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bytes"
"io"
"os"
"path/filepath"
"reflect"
"runtime"
"strings"
Expand Down Expand Up @@ -126,7 +127,7 @@ func Test_export(t *testing.T) {
cmd: &cobra.Command{},
args: []string{},
},
gobin: "testdata/text",
gobin: filepath.Join("testdata", "text"),
want: 1,
stderr: []string{
"gup:WARN : can't get 'dummy.txt'package path information. old go version binary",
Expand All @@ -150,7 +151,7 @@ func Test_export(t *testing.T) {
cmd: &cobra.Command{},
args: []string{},
},
gobin: "testdata/dummy",
gobin: filepath.Join("testdata", "dummy"),
want: 1,
stderr: []string{
"gup:ERROR: can't get binary-paths installed by 'go install': open testdata/dummy: The system cannot find the file specified.",
Expand All @@ -171,7 +172,7 @@ func Test_export(t *testing.T) {
cmd: &cobra.Command{},
args: []string{},
},
gobin: "testdata/dummy",
gobin: filepath.Join("testdata", "dummy"),
want: 1,
stderr: []string{
"gup:ERROR: can't get binary-paths installed by 'go install': open testdata/dummy: no such file or directory",
Expand All @@ -194,7 +195,7 @@ func Test_export(t *testing.T) {

if tt.name == "can not make .config directory" {
oldHome := os.Getenv("HOME")
if err := os.Setenv("HOME", "/root"); err != nil {
if err := os.Setenv("HOME", filepath.Join("/", "root")); err != nil {
t.Fatal(err)
}
defer func() {
Expand Down Expand Up @@ -233,7 +234,7 @@ func Test_export(t *testing.T) {
t.Errorf("value is mismatch (-want +got):\n%s", diff)
}
} else {
if file.IsFile("/.config") {
if file.IsFile(filepath.Join("/", ".config")) {
t.Errorf("permissions are incomplete because '/.config' was created")
}
}
Expand Down
5 changes: 3 additions & 2 deletions cmd/import_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cmd

import (
"os"
"path/filepath"
"testing"

"github.com/spf13/cobra"
Expand Down Expand Up @@ -42,7 +43,7 @@ func Test_runImport(t *testing.T) {
cmd: &cobra.Command{},
args: []string{},
},
home: "./testdata/empty_conf",
home: filepath.Join("testdata", "empty_conf"),
want: 1,
},
{
Expand All @@ -51,7 +52,7 @@ func Test_runImport(t *testing.T) {
cmd: &cobra.Command{},
args: []string{},
},
home: "./testdata/can_not_read_conf",
home: filepath.Join("testdata", "can_not_read_conf"),
want: 1,
},
}
Expand Down
7 changes: 4 additions & 3 deletions cmd/list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bytes"
"io"
"os"
"path/filepath"
"runtime"
"strings"
"testing"
Expand Down Expand Up @@ -77,7 +78,7 @@ func Test_list_gobin_is_empty(t *testing.T) {
}{
{
name: "gobin is empty",
gobin: "./testdata/empty_dir",
gobin: filepath.Join("testdata", "empty_dir"),
args: args{},
want: 1,
stderr: []string{
Expand Down Expand Up @@ -122,7 +123,7 @@ func Test_list_gobin_is_empty(t *testing.T) {
})
}

if err := os.Mkdir("./testdata/empty_dir", 0755); err != nil {
if err := os.Mkdir(filepath.Join("testdata", "empty_dir"), 0755); err != nil {
t.Fatal(err)
}

Expand Down Expand Up @@ -168,7 +169,7 @@ func Test_list_gobin_is_empty(t *testing.T) {
})
}

err := os.Remove("./testdata/empty_dir")
err := os.Remove(filepath.Join("testdata", "empty_dir"))
if err != nil {
t.Fatal(err)
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/remove_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func Test_remove(t *testing.T) {
cmd: &cobra.Command{},
args: []string{},
},
gobin: "no use",
gobin: "no_use",
want: 1,
stderr: []string{
"gup:ERROR: no command name specified",
Expand Down Expand Up @@ -302,7 +302,7 @@ func Test_removeLoop(t *testing.T) {
t.Errorf("removeLoop() = %v, want %v", got, tt.want)
}

if tt.name == "delete cancel" && !file.IsFile("./testdata/delete/posixer") {
if tt.name == "delete cancel" && !file.IsFile("testdata/delete/posixer") {
t.Errorf("input no, however posixer command is deleted")
}
})
Expand Down
Loading

0 comments on commit fb3c119

Please sign in to comment.