From ab7aaba5f4ba2cde480d4ff596d837668b00e5c3 Mon Sep 17 00:00:00 2001 From: Roman Date: Tue, 18 May 2021 17:35:14 +0300 Subject: [PATCH 1/8] fix installation directories and files paths for windows based hosts --- .gitignore | 3 +++ go.mod | 2 +- lib/install.go | 39 +++++++++++++++++++++++++++++++++------ 3 files changed, 37 insertions(+), 7 deletions(-) diff --git a/.gitignore b/.gitignore index 50898570..53d69fef 100644 --- a/.gitignore +++ b/.gitignore @@ -33,3 +33,6 @@ tfswitch* build-script.sh +.idea + +/vendor diff --git a/go.mod b/go.mod index 4f92aa29..694a67df 100644 --- a/go.mod +++ b/go.mod @@ -8,7 +8,7 @@ require ( github.com/chzyer/readline v0.0.0-20171208011716-f6d7a1f6fbf3 // indirect github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1 // indirect github.com/hashicorp/hcl/v2 v2.10.0 // indirect - github.com/hashicorp/hcl2 v0.0.0-20191002203319-fb75b3253c80 // indirect + github.com/hashicorp/hcl2 v0.0.0-20191002203319-fb75b3253c80 github.com/juju/ansiterm v0.0.0-20180109212912-720a0952cc2a // indirect github.com/kiranjthomas/terraform-config-inspect v0.0.0-20191120205521-a1d709eb2824 github.com/lunixbochs/vtclean v0.0.0-20170504063817-d14193dfc626 // indirect diff --git a/lib/install.go b/lib/install.go index dde1e5b3..c9bf556e 100644 --- a/lib/install.go +++ b/lib/install.go @@ -12,7 +12,7 @@ const ( hashiURL = "https://releases.hashicorp.com/terraform/" installFile = "terraform" installVersion = "terraform_" - installPath = "/.terraform.versions/" + installPath = ".terraform.versions" recentFile = "RECENT" ) @@ -49,6 +49,33 @@ func initialize() { } +// get install path variable value (windows os runtime support) +func getInstallPath() string { + if runtime.GOOS == "windows" { + return "\\" + installPath + "\\" + } + + return "/" + installPath + "/" +} + +// get versioned install filename (windows os runtime support) +func getVersionedInstallFileName(tfversion string) string { + if runtime.GOOS == "windows" { + return getInstallLocation() + installVersion + tfversion + ".exe" + } + + return getInstallLocation() + installVersion + tfversion +} + +// get install filename (windows os runtime support) +func getInstallFileName() string { + if runtime.GOOS == "windows" { + return getInstallLocation() + installFile + ".exe" + } + + return installLocation + installFile +} + // getInstallLocation : get location where the terraform binary will be installed, // will create a directory in the home location if it does not exist func getInstallLocation() string { @@ -59,7 +86,7 @@ func getInstallLocation() string { } /* set installation location */ - installLocation = usr.HomeDir + installPath + installLocation = usr.HomeDir + getInstallPath() /* Create local installation directory if it does not exist */ CreateDirIfNotExist(installLocation) @@ -97,7 +124,7 @@ func Install(tfversion string, binPath string) { } /* check if selected version already downloaded */ - fileExist := CheckFileExist(installLocation + installVersion + tfversion) + fileExist := CheckFileExist(getVersionedInstallFileName(tfversion)) /* if selected version already exist, */ if fileExist { @@ -110,7 +137,7 @@ func Install(tfversion string, binPath string) { } /* set symlink to desired version */ - CreateSymlink(installLocation+installVersion+tfversion, binPath) + CreateSymlink(getVersionedInstallFileName(tfversion), binPath) fmt.Printf("Switched terraform to version %q \n", tfversion) AddRecent(tfversion) //add to recent file for faster lookup os.Exit(0) @@ -136,7 +163,7 @@ func Install(tfversion string, binPath string) { } /* rename unzipped file to terraform version name - terraform_x.x.x */ - RenameFile(installLocation+installFile, installLocation+installVersion+tfversion) + RenameFile(getInstallFileName(), getVersionedInstallFileName(tfversion)) /* remove zipped file to clear clutter */ RemoveFiles(installLocation + installVersion + tfversion + "_" + goos + "_" + goarch + ".zip") @@ -149,7 +176,7 @@ func Install(tfversion string, binPath string) { } /* set symlink to desired version */ - CreateSymlink(installLocation+installVersion+tfversion, binPath) + CreateSymlink(getVersionedInstallFileName(tfversion), binPath) fmt.Printf("Switched terraform to version %q \n", tfversion) AddRecent(tfversion) //add to recent file for faster lookup os.Exit(0) From d7f02593a5a450efcb133aca0f8bce9c871753c3 Mon Sep 17 00:00:00 2001 From: Roman Date: Tue, 18 May 2021 18:03:30 +0300 Subject: [PATCH 2/8] add space trimming for tfswitch content --- main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.go b/main.go index 65c15cfa..f41dba86 100644 --- a/main.go +++ b/main.go @@ -278,7 +278,7 @@ func retrieveFileContents(file string) string { fmt.Printf("Error: %s\n", err) os.Exit(1) } - tfversion := strings.TrimSuffix(string(fileContents), "\n") + tfversion := strings.TrimSpace(string(fileContents)) return tfversion } From 1e90680b17a46acaf44dcdcf20ba6e8f6f4741a3 Mon Sep 17 00:00:00 2001 From: Roman Date: Tue, 18 May 2021 22:17:40 +0300 Subject: [PATCH 3/8] update testing files --- lib/common_test.go | 2 +- lib/download_test.go | 8 +++--- lib/files_test.go | 58 +++++++++++++++++++++++++------------------- lib/install.go | 6 +---- lib/install_test.go | 14 +++++++++++ 5 files changed, 53 insertions(+), 35 deletions(-) diff --git a/lib/common_test.go b/lib/common_test.go index 08606b34..12e3d3d2 100644 --- a/lib/common_test.go +++ b/lib/common_test.go @@ -51,9 +51,9 @@ func cleanUp(path string) { func removeFiles(src string) { files, err := filepath.Glob(src) if err != nil { - panic(err) } + for _, f := range files { if err := os.Remove(f); err != nil { panic(err) diff --git a/lib/download_test.go b/lib/download_test.go index f4785ae7..2907bef3 100644 --- a/lib/download_test.go +++ b/lib/download_test.go @@ -16,7 +16,7 @@ func TestDownloadFromURL_FileNameMatch(t *testing.T) { hashiURL := "https://releases.hashicorp.com/terraform/" installVersion := "terraform_" - installPath := "/.terraform.versions_test/" + installPath := getInstallLocation(".terraform.versions_test") macOS := "_darwin_amd64.zip" // get current user @@ -91,7 +91,7 @@ func TestDownloadFromURL_FileExist(t *testing.T) { hashiURL := "https://releases.hashicorp.com/terraform/" installFile := "terraform" installVersion := "terraform_" - installPath := "/.terraform.versions_test/" + installPath := getInstallLocation(".terraform.versions_test") macOS := "_darwin_amd64.zip" // get current user @@ -165,7 +165,7 @@ func TestInvalidURL(t *testing.T) { hashiURL := "https://releases.hashicorp.com/terraform/" installVersion := "terraform_" - installPath := "/.terraform.versions_test/" + installPath := getInstallLocation(".terraform.versions_test") macOS := "_darwin_amd64.zip" invalidVersion := "0.11.7-nonexistent" @@ -189,7 +189,7 @@ func TestInvalidURL(t *testing.T) { } url := hashiURL + invalidVersion + "/" + installVersion + invalidVersion + macOS - //expectedFile := usr.HomeDir + installPath + installVersion + invalidVersion + macOS + //expectedFile := usr.HomeDir + globalInstallPath + installVersion + invalidVersion + macOS _, errDownload := lib.DownloadFromURL(installLocation, url) if errDownload != nil { diff --git a/lib/files_test.go b/lib/files_test.go index fe9cd632..5d31a1bb 100644 --- a/lib/files_test.go +++ b/lib/files_test.go @@ -22,9 +22,9 @@ import ( // rename file, check new filename exit func TestRenameFile(t *testing.T) { - installFile := "terraform" + installFile := getInstallFile("terraform") installVersion := "terraform_" - installPath := "/.terraform.versions_test/" + installPath := getInstallLocation(".terraform.versions_test") version := "0.0.7" usr, errCurr := user.Current() @@ -68,7 +68,7 @@ func TestRenameFile(t *testing.T) { func TestRemoveFiles(t *testing.T) { installFile := "terraform" - installPath := "/.terraform.versions_test/" + installPath := getInstallLocation(".terraform.versions_test") usr, errCurr := user.Current() if errCurr != nil { @@ -103,7 +103,7 @@ func TestRemoveFiles(t *testing.T) { // remove file, check file does not exist func TestUnzip(t *testing.T) { - installPath := "/.terraform.versions_test/" + installPath := getInstallLocation(".terraform.versions_test") absPath, _ := filepath.Abs("../test-data/test-data.zip") fmt.Println(absPath) @@ -139,7 +139,7 @@ func TestUnzip(t *testing.T) { // TestCreateDirIfNotExist : Create a directory, check directory exist func TestCreateDirIfNotExist(t *testing.T) { - installPath := "/.terraform.versions_test/" + installPath := getInstallLocation(".terraform.versions_test") usr, errCurr := user.Current() if errCurr != nil { @@ -172,7 +172,7 @@ func TestCreateDirIfNotExist(t *testing.T) { //TestWriteLines : write to file, check readline to verify func TestWriteLines(t *testing.T) { - installPath := "/.terraform.versions_test/" + installPath := getInstallLocation(".terraform.versions_test") recentFile := "RECENT" semverRegex := regexp.MustCompile(`\A\d+(\.\d+){2}(-\w+\d*)?\z`) //semverRegex := regexp.MustCompile(`\A\d+(\.\d+){2}\z`) @@ -181,13 +181,15 @@ func TestWriteLines(t *testing.T) { if errCurr != nil { log.Fatal(errCurr) } + installLocation := usr.HomeDir + installPath + recentFile = installLocation + recentFile createDirIfNotExist(installLocation) - test_array := []string{"0.1.1", "0.0.2", "0.0.3", "0.12.0-rc1", "0.12.0-beta1"} + versionsList := []string{"0.1.1", "0.0.2", "0.0.3", "0.12.0-rc1", "0.12.0-beta1"} - errWrite := lib.WriteLines(test_array, installLocation+recentFile) + errWrite := lib.WriteLines(versionsList, recentFile) if errWrite != nil { t.Logf("Write should work %v (unexpected)", errWrite) @@ -201,13 +203,16 @@ func TestWriteLines(t *testing.T) { errOpen, errRead error lines []string ) - if file, errOpen = os.Open(installLocation + recentFile); errOpen != nil { + + if file, errOpen = os.Open(recentFile); errOpen != nil { log.Fatal(errOpen) } + defer file.Close() reader := bufio.NewReader(file) buffer := bytes.NewBuffer(make([]byte, 0)) + for { if part, prefix, errRead = reader.ReadLine(); errRead != nil { break @@ -242,7 +247,7 @@ func TestWriteLines(t *testing.T) { // TestReadLines : read from file, check write to verify func TestReadLines(t *testing.T) { - installPath := "/.terraform.versions_test/" + installPath := getInstallLocation(".terraform.versions_test") recentFile := "RECENT" semverRegex := regexp.MustCompile(`\A\d+(\.\d+){2}(-\w+\d*)?\z`) @@ -250,23 +255,26 @@ func TestReadLines(t *testing.T) { if errCurr != nil { log.Fatal(errCurr) } + installLocation := usr.HomeDir + installPath + recentFileLocation := installLocation + recentFile createDirIfNotExist(installLocation) - test_array := []string{"0.0.1", "0.0.2", "0.0.3", "0.12.0-rc1", "0.12.0-beta1"} + versionsList := []string{"0.0.1", "0.0.2", "0.0.3", "0.12.0-rc1", "0.12.0-beta1"} var ( file *os.File errCreate error ) - if file, errCreate = os.Create(installLocation + recentFile); errCreate != nil { + if file, errCreate = os.Create(recentFileLocation); errCreate != nil { log.Fatalf("Error: %s\n", errCreate) } + defer file.Close() - for _, item := range test_array { + for _, item := range versionsList { _, err := file.WriteString(strings.TrimSpace(item) + "\n") if err != nil { log.Fatalf("Error: %s\n", err) @@ -274,7 +282,7 @@ func TestReadLines(t *testing.T) { } } - lines, errRead := lib.ReadLines(installLocation + recentFile) + lines, errRead := lib.ReadLines(recentFileLocation) if errRead != nil { log.Fatalf("Error: %s\n", errRead) @@ -298,7 +306,7 @@ func TestIsDirEmpty(t *testing.T) { current := time.Now() - installPath := "/.terraform.versions_test/" + installPath := getInstallLocation(".terraform.versions_test") usr, errCurr := user.Current() if errCurr != nil { @@ -306,16 +314,16 @@ func TestIsDirEmpty(t *testing.T) { } installLocation := usr.HomeDir + installPath - test_dir := current.Format("2006-01-02") - t.Logf("Create test dir: %v \n", test_dir) + testDir := current.Format("2006-01-02") + t.Logf("Create test dir: %v \n", testDir) createDirIfNotExist(installLocation) - createDirIfNotExist(installLocation + "/" + test_dir) + createDirIfNotExist(installLocation + "/" + testDir) - empty := lib.IsDirEmpty(installLocation + "/" + test_dir) + empty := lib.IsDirEmpty(installLocation + "/" + testDir) - t.Logf("Expected directory to be empty %v [expected]", installLocation+"/"+test_dir) + t.Logf("Expected directory to be empty %v [expected]", installLocation+"/"+testDir) if empty == true { t.Logf("Directory empty") @@ -323,7 +331,7 @@ func TestIsDirEmpty(t *testing.T) { t.Error("Directory not empty") } - cleanUp(installLocation + "/" + test_dir) + cleanUp(installLocation + "/" + testDir) cleanUp(installLocation) @@ -334,7 +342,7 @@ func TestCheckDirHasTFBin(t *testing.T) { goarch := runtime.GOARCH goos := runtime.GOOS - installPath := "/.terraform.versions_test/" + installPath := getInstallLocation(".terraform.versions_test") installFile := "terraform" usr, errCurr := user.Current() @@ -363,7 +371,7 @@ func TestCheckDirHasTFBin(t *testing.T) { // TestPath : create file in directory, check if path exist func TestPath(t *testing.T) { - installPath := "/.terraform.versions_test" + installPath := getInstallLocation(".terraform.versions_test") installFile := "terraform" usr, errCurr := user.Current() @@ -374,9 +382,9 @@ func TestPath(t *testing.T) { createDirIfNotExist(installLocation) - createFile(installLocation + "/" + installFile) + createFile(installLocation + string(os.PathSeparator) + installFile) - path := lib.Path(installLocation + "/" + installFile) + path := lib.Path(installLocation + string(os.PathSeparator) + installFile) t.Logf("Path created %s\n", installLocation+installFile) t.Logf("Path expected %s\n", installLocation) diff --git a/lib/install.go b/lib/install.go index c9bf556e..537295b4 100644 --- a/lib/install.go +++ b/lib/install.go @@ -51,11 +51,7 @@ func initialize() { // get install path variable value (windows os runtime support) func getInstallPath() string { - if runtime.GOOS == "windows" { - return "\\" + installPath + "\\" - } - - return "/" + installPath + "/" + return string(os.PathSeparator) + installPath + string(os.PathSeparator) } // get versioned install filename (windows os runtime support) diff --git a/lib/install_test.go b/lib/install_test.go index b8ec1817..89ec7c74 100644 --- a/lib/install_test.go +++ b/lib/install_test.go @@ -1,12 +1,26 @@ package lib_test import ( + "os" "os/user" + "runtime" "testing" ) // TestAddRecent : Create a file, check filename exist, // rename file, check new filename exit +func getInstallLocation(installPath string) string { + return string(os.PathSeparator) + installPath + string(os.PathSeparator) +} + +func getInstallFile(installFile string) string { + if runtime.GOOS == "windows" { + return installFile + ".exe" + } + + return installFile +} + func TestInstall(t *testing.T) { t.Run("User should exist", From a109de65a5835bc526c2945349e857f9764ff641 Mon Sep 17 00:00:00 2001 From: Roman Date: Tue, 18 May 2021 22:26:40 +0300 Subject: [PATCH 4/8] remove separators --- lib/files_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/files_test.go b/lib/files_test.go index 5d31a1bb..f1795f54 100644 --- a/lib/files_test.go +++ b/lib/files_test.go @@ -382,9 +382,9 @@ func TestPath(t *testing.T) { createDirIfNotExist(installLocation) - createFile(installLocation + string(os.PathSeparator) + installFile) + createFile(installLocation + installFile) - path := lib.Path(installLocation + string(os.PathSeparator) + installFile) + path := lib.Path(installLocation + installFile) t.Logf("Path created %s\n", installLocation+installFile) t.Logf("Path expected %s\n", installLocation) From 396f926fbb95ddc3951d3e80a9a6c7fd5ce9600a Mon Sep 17 00:00:00 2001 From: Roman Date: Tue, 18 May 2021 22:33:57 +0300 Subject: [PATCH 5/8] restore tests --- lib/files_test.go | 58 ++++++++++++++++++++--------------------------- 1 file changed, 25 insertions(+), 33 deletions(-) diff --git a/lib/files_test.go b/lib/files_test.go index f1795f54..fe9cd632 100644 --- a/lib/files_test.go +++ b/lib/files_test.go @@ -22,9 +22,9 @@ import ( // rename file, check new filename exit func TestRenameFile(t *testing.T) { - installFile := getInstallFile("terraform") + installFile := "terraform" installVersion := "terraform_" - installPath := getInstallLocation(".terraform.versions_test") + installPath := "/.terraform.versions_test/" version := "0.0.7" usr, errCurr := user.Current() @@ -68,7 +68,7 @@ func TestRenameFile(t *testing.T) { func TestRemoveFiles(t *testing.T) { installFile := "terraform" - installPath := getInstallLocation(".terraform.versions_test") + installPath := "/.terraform.versions_test/" usr, errCurr := user.Current() if errCurr != nil { @@ -103,7 +103,7 @@ func TestRemoveFiles(t *testing.T) { // remove file, check file does not exist func TestUnzip(t *testing.T) { - installPath := getInstallLocation(".terraform.versions_test") + installPath := "/.terraform.versions_test/" absPath, _ := filepath.Abs("../test-data/test-data.zip") fmt.Println(absPath) @@ -139,7 +139,7 @@ func TestUnzip(t *testing.T) { // TestCreateDirIfNotExist : Create a directory, check directory exist func TestCreateDirIfNotExist(t *testing.T) { - installPath := getInstallLocation(".terraform.versions_test") + installPath := "/.terraform.versions_test/" usr, errCurr := user.Current() if errCurr != nil { @@ -172,7 +172,7 @@ func TestCreateDirIfNotExist(t *testing.T) { //TestWriteLines : write to file, check readline to verify func TestWriteLines(t *testing.T) { - installPath := getInstallLocation(".terraform.versions_test") + installPath := "/.terraform.versions_test/" recentFile := "RECENT" semverRegex := regexp.MustCompile(`\A\d+(\.\d+){2}(-\w+\d*)?\z`) //semverRegex := regexp.MustCompile(`\A\d+(\.\d+){2}\z`) @@ -181,15 +181,13 @@ func TestWriteLines(t *testing.T) { if errCurr != nil { log.Fatal(errCurr) } - installLocation := usr.HomeDir + installPath - recentFile = installLocation + recentFile createDirIfNotExist(installLocation) - versionsList := []string{"0.1.1", "0.0.2", "0.0.3", "0.12.0-rc1", "0.12.0-beta1"} + test_array := []string{"0.1.1", "0.0.2", "0.0.3", "0.12.0-rc1", "0.12.0-beta1"} - errWrite := lib.WriteLines(versionsList, recentFile) + errWrite := lib.WriteLines(test_array, installLocation+recentFile) if errWrite != nil { t.Logf("Write should work %v (unexpected)", errWrite) @@ -203,16 +201,13 @@ func TestWriteLines(t *testing.T) { errOpen, errRead error lines []string ) - - if file, errOpen = os.Open(recentFile); errOpen != nil { + if file, errOpen = os.Open(installLocation + recentFile); errOpen != nil { log.Fatal(errOpen) } - defer file.Close() reader := bufio.NewReader(file) buffer := bytes.NewBuffer(make([]byte, 0)) - for { if part, prefix, errRead = reader.ReadLine(); errRead != nil { break @@ -247,7 +242,7 @@ func TestWriteLines(t *testing.T) { // TestReadLines : read from file, check write to verify func TestReadLines(t *testing.T) { - installPath := getInstallLocation(".terraform.versions_test") + installPath := "/.terraform.versions_test/" recentFile := "RECENT" semverRegex := regexp.MustCompile(`\A\d+(\.\d+){2}(-\w+\d*)?\z`) @@ -255,26 +250,23 @@ func TestReadLines(t *testing.T) { if errCurr != nil { log.Fatal(errCurr) } - installLocation := usr.HomeDir + installPath - recentFileLocation := installLocation + recentFile createDirIfNotExist(installLocation) - versionsList := []string{"0.0.1", "0.0.2", "0.0.3", "0.12.0-rc1", "0.12.0-beta1"} + test_array := []string{"0.0.1", "0.0.2", "0.0.3", "0.12.0-rc1", "0.12.0-beta1"} var ( file *os.File errCreate error ) - if file, errCreate = os.Create(recentFileLocation); errCreate != nil { + if file, errCreate = os.Create(installLocation + recentFile); errCreate != nil { log.Fatalf("Error: %s\n", errCreate) } - defer file.Close() - for _, item := range versionsList { + for _, item := range test_array { _, err := file.WriteString(strings.TrimSpace(item) + "\n") if err != nil { log.Fatalf("Error: %s\n", err) @@ -282,7 +274,7 @@ func TestReadLines(t *testing.T) { } } - lines, errRead := lib.ReadLines(recentFileLocation) + lines, errRead := lib.ReadLines(installLocation + recentFile) if errRead != nil { log.Fatalf("Error: %s\n", errRead) @@ -306,7 +298,7 @@ func TestIsDirEmpty(t *testing.T) { current := time.Now() - installPath := getInstallLocation(".terraform.versions_test") + installPath := "/.terraform.versions_test/" usr, errCurr := user.Current() if errCurr != nil { @@ -314,16 +306,16 @@ func TestIsDirEmpty(t *testing.T) { } installLocation := usr.HomeDir + installPath - testDir := current.Format("2006-01-02") - t.Logf("Create test dir: %v \n", testDir) + test_dir := current.Format("2006-01-02") + t.Logf("Create test dir: %v \n", test_dir) createDirIfNotExist(installLocation) - createDirIfNotExist(installLocation + "/" + testDir) + createDirIfNotExist(installLocation + "/" + test_dir) - empty := lib.IsDirEmpty(installLocation + "/" + testDir) + empty := lib.IsDirEmpty(installLocation + "/" + test_dir) - t.Logf("Expected directory to be empty %v [expected]", installLocation+"/"+testDir) + t.Logf("Expected directory to be empty %v [expected]", installLocation+"/"+test_dir) if empty == true { t.Logf("Directory empty") @@ -331,7 +323,7 @@ func TestIsDirEmpty(t *testing.T) { t.Error("Directory not empty") } - cleanUp(installLocation + "/" + testDir) + cleanUp(installLocation + "/" + test_dir) cleanUp(installLocation) @@ -342,7 +334,7 @@ func TestCheckDirHasTFBin(t *testing.T) { goarch := runtime.GOARCH goos := runtime.GOOS - installPath := getInstallLocation(".terraform.versions_test") + installPath := "/.terraform.versions_test/" installFile := "terraform" usr, errCurr := user.Current() @@ -371,7 +363,7 @@ func TestCheckDirHasTFBin(t *testing.T) { // TestPath : create file in directory, check if path exist func TestPath(t *testing.T) { - installPath := getInstallLocation(".terraform.versions_test") + installPath := "/.terraform.versions_test" installFile := "terraform" usr, errCurr := user.Current() @@ -382,9 +374,9 @@ func TestPath(t *testing.T) { createDirIfNotExist(installLocation) - createFile(installLocation + installFile) + createFile(installLocation + "/" + installFile) - path := lib.Path(installLocation + installFile) + path := lib.Path(installLocation + "/" + installFile) t.Logf("Path created %s\n", installLocation+installFile) t.Logf("Path expected %s\n", installLocation) From c903ee7bd2c16ca875e8d4b1540cae9076857a39 Mon Sep 17 00:00:00 2001 From: Roman Date: Tue, 18 May 2021 22:37:50 +0300 Subject: [PATCH 6/8] restore comment file name --- lib/download_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/download_test.go b/lib/download_test.go index 2907bef3..4f70bf1a 100644 --- a/lib/download_test.go +++ b/lib/download_test.go @@ -189,7 +189,7 @@ func TestInvalidURL(t *testing.T) { } url := hashiURL + invalidVersion + "/" + installVersion + invalidVersion + macOS - //expectedFile := usr.HomeDir + globalInstallPath + installVersion + invalidVersion + macOS + //expectedFile := usr.HomeDir + installPath + installVersion + invalidVersion + macOS _, errDownload := lib.DownloadFromURL(installLocation, url) if errDownload != nil { From 28a14514fb0434b55da97d6c7b0533f2b80bbf84 Mon Sep 17 00:00:00 2001 From: Warren Veerasingam <38867521+warrensbox@users.noreply.github.com> Date: Fri, 2 Jul 2021 13:21:56 -0500 Subject: [PATCH 7/8] Update lib/install.go MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: 老叶 --- lib/install.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/install.go b/lib/install.go index 537295b4..6163dcd7 100644 --- a/lib/install.go +++ b/lib/install.go @@ -57,7 +57,7 @@ func getInstallPath() string { // get versioned install filename (windows os runtime support) func getVersionedInstallFileName(tfversion string) string { if runtime.GOOS == "windows" { - return getInstallLocation() + installVersion + tfversion + ".exe" + return filepath.Join(getInstallLocation(), installVersion + tfversion + ".exe") } return getInstallLocation() + installVersion + tfversion From c4e9616a507420a9576f2b974c906635264220b0 Mon Sep 17 00:00:00 2001 From: Warren Veerasingam <38867521+warrensbox@users.noreply.github.com> Date: Fri, 2 Jul 2021 13:22:10 -0500 Subject: [PATCH 8/8] Update lib/install.go MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: 老叶 --- lib/install.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/install.go b/lib/install.go index 6163dcd7..8cee5a61 100644 --- a/lib/install.go +++ b/lib/install.go @@ -66,7 +66,7 @@ func getVersionedInstallFileName(tfversion string) string { // get install filename (windows os runtime support) func getInstallFileName() string { if runtime.GOOS == "windows" { - return getInstallLocation() + installFile + ".exe" + return filepath.Join(getInstallLocation(), installFile + ".exe") } return installLocation + installFile