Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: fixup tests and ensure go vet and staticcheck pass #138

Merged
merged 1 commit into from
May 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions lib/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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)
}
Expand Down
2 changes: 1 addition & 1 deletion lib/revert.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
12 changes: 6 additions & 6 deletions test-dist/testnew.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -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
}
Expand All @@ -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)
}
Expand All @@ -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)
}
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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
Expand Down
7 changes: 4 additions & 3 deletions util/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"io/ioutil"
"os"
"path"

"testing"
)

Expand All @@ -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")

Expand All @@ -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)
}
Expand All @@ -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)
}
Expand Down
1 change: 1 addition & 0 deletions util/utils_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down