From 620ecff44c3b8ffcc970031f2ad2c73299f71f86 Mon Sep 17 00:00:00 2001 From: Ian Davis Date: Fri, 7 May 2021 16:46:34 +0100 Subject: [PATCH] chore: fixup tests and ensure go vet and staticcheck pass --- lib/install.go | 8 ++++---- lib/revert.go | 2 +- main.go | 2 +- test-dist/testnew.go | 12 ++++++------ util/utils_test.go | 7 ++++--- util/utils_windows.go | 1 + 6 files changed, 17 insertions(+), 15 deletions(-) diff --git a/lib/install.go b/lib/install.go index 5b3cc56..9fef24f 100644 --- a/lib/install.go +++ b/lib/install.go @@ -24,7 +24,7 @@ func (i *Install) getTmpPath() (string, error) { return "", err } - err = os.MkdirAll(tmpd, 0777) + err = os.MkdirAll(tmpd, 0o777) if err != nil { return "", err } @@ -184,7 +184,7 @@ func InstallBinaryTo(nbin, nloc string) error { return fmt.Errorf("error moving new binary into place: %s", err) } - err = os.Chmod(nloc, 0755) + err = os.Chmod(nloc, 0o755) if err != nil { return fmt.Errorf("error setting permissions on new binary: %s", err) } @@ -213,13 +213,13 @@ func StashOldBinary(tag string, keep bool) (string, error) { npath := filepath.Join(olddir, "ipfs-"+tag) pathpath := filepath.Join(olddir, "path-old") - err = os.MkdirAll(olddir, 0700) + err = os.MkdirAll(olddir, 0o700) if err != nil { return "", fmt.Errorf("could not create dir to backup old binary: %s", err) } // write the old path of the binary to the backup dir - err = ioutil.WriteFile(pathpath, []byte(loc), 0644) + err = ioutil.WriteFile(pathpath, []byte(loc), 0o644) if err != nil { return "", fmt.Errorf("could not stash path: %s", err) } diff --git a/lib/revert.go b/lib/revert.go index 4d879dd..c2d3001 100644 --- a/lib/revert.go +++ b/lib/revert.go @@ -43,7 +43,7 @@ func SelectRevertBin() (string, error) { oldbinpath := filepath.Join(ipfsDir, "old-bin") _, err = os.Stat(oldbinpath) if os.IsNotExist(err) { - return "", fmt.Errorf("No prior binary found at: %s", oldbinpath) + return "", fmt.Errorf("no prior binary found at: %s", oldbinpath) } entries, err := ioutil.ReadDir(oldbinpath) diff --git a/main.go b/main.go index 25c2aca..2c06bac 100644 --- a/main.go +++ b/main.go @@ -276,7 +276,7 @@ var cmdFetch = &cli.Command{ stump.Log("fetching go-ipfs version", vers) - output, err = migrations.FetchBinary(c.Context, fetcher, "go-ipfs", vers, "ipfs", output) + _, err = migrations.FetchBinary(c.Context, fetcher, "go-ipfs", vers, "ipfs", output) if err != nil { stump.Fatal("failed to fetch binary:", err) } diff --git a/test-dist/testnew.go b/test-dist/testnew.go index 0efa735..67e11c1 100644 --- a/test-dist/testnew.go +++ b/test-dist/testnew.go @@ -93,7 +93,7 @@ func tweakConfig(ipfspath string) error { return err } - err = ioutil.WriteFile(cfgpath, out, 0644) + err = ioutil.WriteFile(cfgpath, out, 0o644) if err != nil { return fmt.Errorf("error writing tweaked config: %s", err) } @@ -188,7 +188,7 @@ func TestBinary(bin, version string) error { } // make sure binary is executable - err = os.Chmod(bin, 0755) + err = os.Chmod(bin, 0o755) if err != nil { return err } @@ -198,7 +198,7 @@ func TestBinary(bin, version string) error { return fmt.Errorf("cannot find ipfs directory: %s", err) } staging := filepath.Join(ipfsDir, "update-staging") - err = os.MkdirAll(staging, 0755) + err = os.MkdirAll(staging, 0o755) if err != nil { return fmt.Errorf("error creating test staging directory: %s", err) } @@ -208,7 +208,7 @@ func TestBinary(bin, version string) error { return err } - err = os.MkdirAll(tdir, 0755) + err = os.MkdirAll(tdir, 0o755) if err != nil { return fmt.Errorf("error creating test staging directory: %s", err) } @@ -292,7 +292,7 @@ func testFileAdd(tdir, bin string) error { stump.VLog(" - checking that we can add and cat a file") text := []byte("hello world! This node should work") testFile := filepath.Join(tdir, "/test.txt") - err := ioutil.WriteFile(testFile, text, 0644) + err := ioutil.WriteFile(testFile, text, 0o644) if err != nil { stump.Error("testfileadd could not create test file: %s", err) } @@ -346,7 +346,7 @@ func testRefsList(tdir, bin string) error { } } if !found { - return fmt.Errorf("expected to see %s in the local refs!", exp) + return fmt.Errorf("expected to see %s in the local refs", exp) } return nil diff --git a/util/utils_test.go b/util/utils_test.go index 4637ec8..28b8426 100644 --- a/util/utils_test.go +++ b/util/utils_test.go @@ -4,7 +4,6 @@ import ( "io/ioutil" "os" "path" - "testing" ) @@ -15,7 +14,9 @@ func TestApiEndpoint(t *testing.T) { } defer os.RemoveAll(fakeHome) defer os.Unsetenv("HOME") + defer os.Unsetenv("IPFS_PATH") + os.Setenv("IPFS_PATH", "") os.Setenv("HOME", fakeHome) fakeIpfs := path.Join(fakeHome, ".ipfs") @@ -30,7 +31,7 @@ func TestApiEndpoint(t *testing.T) { } apiPath := path.Join(fakeIpfs, apiFile) - err = ioutil.WriteFile(apiPath, []byte("bad-data"), 0644) + err = ioutil.WriteFile(apiPath, []byte("bad-data"), 0o644) if err != nil { panic(err) } @@ -40,7 +41,7 @@ func TestApiEndpoint(t *testing.T) { t.Fatal("expected error when bad data") } - err = ioutil.WriteFile(apiPath, []byte("/ip4/127.0.0.1/tcp/5001"), 0644) + err = ioutil.WriteFile(apiPath, []byte("/ip4/127.0.0.1/tcp/5001"), 0o644) if err != nil { panic(err) } diff --git a/util/utils_windows.go b/util/utils_windows.go index 15a757d..4e082fb 100644 --- a/util/utils_windows.go +++ b/util/utils_windows.go @@ -26,6 +26,7 @@ func winForceRemove(filePath string) error { } return nil } + func winInsideGUI() bool { conhostInfo := &windows.ConsoleScreenBufferInfo{} if err := windows.GetConsoleScreenBufferInfo(windows.Stdout, conhostInfo); err != nil {