diff --git a/cmd/browse.go b/cmd/browse.go index 0dd99be..f394f4c 100644 --- a/cmd/browse.go +++ b/cmd/browse.go @@ -3,7 +3,7 @@ package cmd import ( "fmt" "os" - "path" + "path/filepath" "github.com/marwanhawari/stew/constants" stew "github.com/marwanhawari/stew/lib" @@ -57,7 +57,7 @@ func Browse(cliInput string) { assetIndex, _ := stew.Contains(releaseAssets, asset) downloadURL := githubProject.Releases[tagIndex].Assets[assetIndex].DownloadURL - downloadPath := path.Join(stewPkgPath, asset) + downloadPath := filepath.Join(stewPkgPath, asset) downloadPathExists, err := stew.PathExists(downloadPath) stew.CatchAndExit(err) diff --git a/cmd/install.go b/cmd/install.go index a5b309a..7edd4fa 100644 --- a/cmd/install.go +++ b/cmd/install.go @@ -3,7 +3,7 @@ package cmd import ( "fmt" "os" - "path" + "path/filepath" "strings" "github.com/marwanhawari/stew/constants" @@ -102,7 +102,7 @@ func Install(cliInputs []string) { fmt.Println(constants.GreenColor(asset)) } - downloadPath := path.Join(stewPkgPath, asset) + downloadPath := filepath.Join(stewPkgPath, asset) downloadPathExists, err := stew.PathExists(downloadPath) stew.CatchAndExit(err) if downloadPathExists { diff --git a/cmd/upgrade.go b/cmd/upgrade.go index c1ac223..08a85fc 100644 --- a/cmd/upgrade.go +++ b/cmd/upgrade.go @@ -3,7 +3,7 @@ package cmd import ( "fmt" "os" - "path" + "path/filepath" "github.com/marwanhawari/stew/constants" stew "github.com/marwanhawari/stew/lib" @@ -89,7 +89,7 @@ func Upgrade(cliFlag bool, binaryName string) { downloadURL := githubProject.Releases[tagIndex].Assets[assetIndex].DownloadURL - downloadPath := path.Join(stewPkgPath, asset) + downloadPath := filepath.Join(stewPkgPath, asset) downloadPathExists, err := stew.PathExists(downloadPath) stew.CatchAndExit(err) if downloadPathExists { diff --git a/lib/stewfile.go b/lib/stewfile.go index b22bdd6..f8def87 100644 --- a/lib/stewfile.go +++ b/lib/stewfile.go @@ -6,7 +6,7 @@ import ( "fmt" "io/ioutil" "os" - "path" + "path/filepath" "github.com/marwanhawari/stew/constants" ) @@ -131,10 +131,10 @@ type SystemInfo struct { func NewSystemInfo(stewPath string) SystemInfo { var systemInfo SystemInfo systemInfo.StewPath = stewPath - systemInfo.StewBinPath = path.Join(stewPath, "bin") - systemInfo.StewPkgPath = path.Join(stewPath, "pkg") - systemInfo.StewLockFilePath = path.Join(stewPath, "Stewfile.lock.json") - systemInfo.StewTmpPath = path.Join(stewPath, "tmp") + systemInfo.StewBinPath = filepath.Join(stewPath, "bin") + systemInfo.StewPkgPath = filepath.Join(stewPath, "pkg") + systemInfo.StewLockFilePath = filepath.Join(stewPath, "Stewfile.lock.json") + systemInfo.StewTmpPath = filepath.Join(stewPath, "tmp") systemInfo.Os = getOS() systemInfo.Arch = getArch() @@ -143,8 +143,8 @@ func NewSystemInfo(stewPath string) SystemInfo { // DeleteAssetAndBinary will delete the asset from the ~/.stew/pkg path and delete the binary from the ~/.stew/bin path func DeleteAssetAndBinary(stewPkgPath, stewBinPath, asset, binary string) error { - assetPath := path.Join(stewPkgPath, asset) - binPath := path.Join(stewBinPath, binary) + assetPath := filepath.Join(stewPkgPath, asset) + binPath := filepath.Join(stewBinPath, binary) err := os.RemoveAll(assetPath) if err != nil { return err diff --git a/lib/stewfile_test.go b/lib/stewfile_test.go index 3d1c19a..3934af0 100644 --- a/lib/stewfile_test.go +++ b/lib/stewfile_test.go @@ -3,7 +3,7 @@ package stew import ( "io/ioutil" "os" - "path" + "path/filepath" "reflect" "runtime" "testing" @@ -69,7 +69,7 @@ func Test_readLockFileJSON(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { tempDir := t.TempDir() - lockFilePath := path.Join(tempDir, "Stewfile.lock.json") + lockFilePath := filepath.Join(tempDir, "Stewfile.lock.json") WriteLockFileJSON(testLockfile, lockFilePath) got, err := readLockFileJSON(lockFilePath) @@ -97,7 +97,7 @@ func TestWriteLockFileJSON(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { tempDir := t.TempDir() - lockFilePath := path.Join(tempDir, "Stewfile.lock.json") + lockFilePath := filepath.Join(tempDir, "Stewfile.lock.json") if err := WriteLockFileJSON(testLockfile, lockFilePath); (err != nil) != tt.wantErr { t.Errorf("WriteLockFileJSON() error = %v, wantErr %v", err, tt.wantErr) @@ -201,7 +201,7 @@ func TestReadStewfileContents(t *testing.T) { t.Run(tt.name, func(t *testing.T) { tempDir := t.TempDir() - testStewfilePath := path.Join(tempDir, "Stewfile") + testStewfilePath := filepath.Join(tempDir, "Stewfile") ioutil.WriteFile(testStewfilePath, []byte(testStewfileContents), 0644) got, err := ReadStewfileContents(testStewfilePath) @@ -241,7 +241,7 @@ func TestNewLockFile(t *testing.T) { t.Run(tt.name, func(t *testing.T) { tempDir := t.TempDir() - lockFilePath := path.Join(tempDir, "Stewfile.lock.json") + lockFilePath := filepath.Join(tempDir, "Stewfile.lock.json") WriteLockFileJSON(testLockfile, lockFilePath) got, err := NewLockFile(lockFilePath, tt.args.userOS, tt.args.userArch) @@ -279,7 +279,7 @@ func TestNewLockFileDoesntExist(t *testing.T) { t.Run(tt.name, func(t *testing.T) { tempDir := t.TempDir() - lockFilePath := path.Join(tempDir, "Stewfile.lock.json") + lockFilePath := filepath.Join(tempDir, "Stewfile.lock.json") got, err := NewLockFile(lockFilePath, tt.args.userOS, tt.args.userArch) if (err != nil) != tt.wantErr { @@ -309,10 +309,10 @@ func TestNewSystemInfo(t *testing.T) { Os: runtime.GOOS, Arch: runtime.GOARCH, StewPath: tempDir, - StewBinPath: path.Join(tempDir, "bin"), - StewPkgPath: path.Join(tempDir, "pkg"), - StewLockFilePath: path.Join(tempDir, "Stewfile.lock.json"), - StewTmpPath: path.Join(tempDir, "tmp"), + StewBinPath: filepath.Join(tempDir, "bin"), + StewPkgPath: filepath.Join(tempDir, "pkg"), + StewLockFilePath: filepath.Join(tempDir, "Stewfile.lock.json"), + StewTmpPath: filepath.Join(tempDir, "tmp"), } got := NewSystemInfo(tempDir) @@ -336,10 +336,10 @@ func TestDeleteAssetAndBinary(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { tempDir := t.TempDir() - os.MkdirAll(path.Join(tempDir, "pkg"), 0755) - testStewAssetPath := path.Join(tempDir, "pkg", "testAsset.tar.gz") - os.MkdirAll(path.Join(tempDir, "bin"), 0755) - testStewBinaryPath := path.Join(tempDir, "bin", "testBinary") + os.MkdirAll(filepath.Join(tempDir, "pkg"), 0755) + testStewAssetPath := filepath.Join(tempDir, "pkg", "testAsset.tar.gz") + os.MkdirAll(filepath.Join(tempDir, "bin"), 0755) + testStewBinaryPath := filepath.Join(tempDir, "bin", "testBinary") ioutil.WriteFile(testStewAssetPath, []byte("This is a test asset"), 0644) ioutil.WriteFile(testStewBinaryPath, []byte("This is a test binary"), 0644) @@ -351,7 +351,7 @@ func TestDeleteAssetAndBinary(t *testing.T) { t.Errorf("Either the asset or the binary does not exist yet") } - if err := DeleteAssetAndBinary(path.Dir(testStewAssetPath), path.Dir(testStewBinaryPath), path.Base(testStewAssetPath), path.Base(testStewBinaryPath)); (err != nil) != tt.wantErr { + if err := DeleteAssetAndBinary(filepath.Dir(testStewAssetPath), filepath.Dir(testStewBinaryPath), filepath.Base(testStewAssetPath), filepath.Base(testStewBinaryPath)); (err != nil) != tt.wantErr { t.Errorf("DeleteAssetAndBinary() error = %v, wantErr %v", err, tt.wantErr) } diff --git a/lib/util_test.go b/lib/util_test.go index ab2ccc5..9157589 100644 --- a/lib/util_test.go +++ b/lib/util_test.go @@ -3,7 +3,7 @@ package stew import ( "io/ioutil" "os" - "path" + "path/filepath" "reflect" "runtime" "testing" @@ -72,7 +72,7 @@ func Test_isExecutableFile(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { tempDir := t.TempDir() - testExecutableFilePath := path.Join(tempDir, tt.args.filePath) + testExecutableFilePath := filepath.Join(tempDir, tt.args.filePath) if tt.want { ioutil.WriteFile(testExecutableFilePath, []byte("An executable file"), 0755) } else { @@ -121,7 +121,7 @@ func TestPathExists(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { tempDir := t.TempDir() - testFilePath := path.Join(tempDir, tt.args.path) + testFilePath := filepath.Join(tempDir, tt.args.path) if tt.want { ioutil.WriteFile(testFilePath, []byte("A test file"), 0644) } @@ -151,7 +151,7 @@ func TestGetStewPath(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { homeDir, _ := os.UserHomeDir() - testStewPath := path.Join(homeDir, ".stew") + testStewPath := filepath.Join(homeDir, ".stew") stewPathExists, _ := PathExists(testStewPath) if !stewPathExists { os.MkdirAll(testStewPath, 0755) @@ -200,7 +200,7 @@ func TestDownloadFile(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { tempDir := t.TempDir() - testDownloadPath := path.Join(tempDir, path.Base(tt.args.url)) + testDownloadPath := filepath.Join(tempDir, filepath.Base(tt.args.url)) if err := DownloadFile(testDownloadPath, tt.args.url); (err != nil) != tt.wantErr { t.Errorf("DownloadFile() error = %v, wantErr %v", err, tt.wantErr) return @@ -235,8 +235,8 @@ func Test_copyFile(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { tempDir := t.TempDir() - srcFilePath := path.Join(tempDir, tt.args.srcFile) - destFilePath := path.Join(tempDir, tt.args.destFile) + srcFilePath := filepath.Join(tempDir, tt.args.srcFile) + destFilePath := filepath.Join(tempDir, tt.args.destFile) ioutil.WriteFile(srcFilePath, []byte("A test file"), 0644) @@ -280,11 +280,11 @@ func Test_walkDir(t *testing.T) { t.Run(tt.name, func(t *testing.T) { tempDir := t.TempDir() - ioutil.WriteFile(path.Join(tempDir, "testFile.txt"), []byte("A test file"), 0644) - os.MkdirAll(path.Join(tempDir, "bin"), 0755) - ioutil.WriteFile(path.Join(tempDir, "bin", "binDirTestFile.txt"), []byte("Another test file"), 0644) + ioutil.WriteFile(filepath.Join(tempDir, "testFile.txt"), []byte("A test file"), 0644) + os.MkdirAll(filepath.Join(tempDir, "bin"), 0755) + ioutil.WriteFile(filepath.Join(tempDir, "bin", "binDirTestFile.txt"), []byte("Another test file"), 0644) - want := []string{path.Join(tempDir, "bin", "binDirTestFile.txt"), path.Join(tempDir, "testFile.txt")} + want := []string{filepath.Join(tempDir, "bin", "binDirTestFile.txt"), filepath.Join(tempDir, "testFile.txt")} got, err := walkDir(tempDir) if (err != nil) != tt.wantErr { @@ -337,15 +337,15 @@ func Test_getBinary(t *testing.T) { t.Run(tt.name, func(t *testing.T) { tempDir := t.TempDir() - testBinaryFilePath := path.Join(tempDir, tt.binaryName) + testBinaryFilePath := filepath.Join(tempDir, tt.binaryName) ioutil.WriteFile(testBinaryFilePath, []byte("An executable file"), 0755) - testNonBinaryFilePath := path.Join(tempDir, "testNonBinary") + testNonBinaryFilePath := filepath.Join(tempDir, "testNonBinary") ioutil.WriteFile(testNonBinaryFilePath, []byte("Not an executable file"), 0644) testFilePaths := []string{testBinaryFilePath, testNonBinaryFilePath} - wantBinaryFile := path.Join(tempDir, tt.binaryName) - wantBinaryName := path.Base(wantBinaryFile) + wantBinaryFile := filepath.Join(tempDir, tt.binaryName) + wantBinaryName := filepath.Base(wantBinaryFile) got, got1, err := getBinary(testFilePaths, tt.args.repo) if (err != nil) != tt.wantErr { @@ -385,7 +385,7 @@ func Test_getBinaryError(t *testing.T) { t.Run(tt.name, func(t *testing.T) { tempDir := t.TempDir() - testNonBinaryFilePath := path.Join(tempDir, "testNonBinary") + testNonBinaryFilePath := filepath.Join(tempDir, "testNonBinary") ioutil.WriteFile(testNonBinaryFilePath, []byte("Not an executable file"), 0644) testFilePaths := []string{testNonBinaryFilePath} @@ -702,8 +702,8 @@ func Test_extractBinary(t *testing.T) { { name: "test1", args: args{ - downloadedFilePath: path.Join(t.TempDir(), "ppath-v0.0.3-darwin-arm64.tar.gz"), - tmpExtractionPath: path.Join(t.TempDir(), "tmp"), + downloadedFilePath: filepath.Join(t.TempDir(), "ppath-v0.0.3-darwin-arm64.tar.gz"), + tmpExtractionPath: filepath.Join(t.TempDir(), "tmp"), }, url: "https://github.com/marwanhawari/ppath/releases/download/v0.0.3/ppath-v0.0.3-darwin-arm64.tar.gz", wantErr: false, @@ -735,7 +735,7 @@ func TestInstallBinary(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { tempDir := t.TempDir() - stewPath := path.Join(tempDir, ".stew") + stewPath := filepath.Join(tempDir, ".stew") repo := "ppath" systemInfo := NewSystemInfo(stewPath) @@ -759,7 +759,7 @@ func TestInstallBinary(t *testing.T) { }, } - downloadedFilePath := path.Join(systemInfo.StewPkgPath, "ppath-v0.0.3-darwin-arm64.tar.gz") + downloadedFilePath := filepath.Join(systemInfo.StewPkgPath, "ppath-v0.0.3-darwin-arm64.tar.gz") err := DownloadFile(downloadedFilePath, "https://github.com/marwanhawari/ppath/releases/download/v0.0.3/ppath-v0.0.3-darwin-arm64.tar.gz") if err != nil { @@ -794,7 +794,7 @@ func TestInstallBinary_Fail(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { tempDir := t.TempDir() - stewPath := path.Join(tempDir, ".stew") + stewPath := filepath.Join(tempDir, ".stew") repo := "ppath" systemInfo := NewSystemInfo(stewPath) @@ -818,7 +818,7 @@ func TestInstallBinary_Fail(t *testing.T) { }, } - downloadedFilePath := path.Join(systemInfo.StewPkgPath, "ppath-v0.0.3-darwin-arm64.tar.gz") + downloadedFilePath := filepath.Join(systemInfo.StewPkgPath, "ppath-v0.0.3-darwin-arm64.tar.gz") err := DownloadFile(downloadedFilePath, "https://github.com/marwanhawari/ppath/releases/download/v0.0.3/ppath-v0.0.3-darwin-arm64.tar.gz") if err != nil {