Skip to content

Commit

Permalink
Merge branch 'master' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
warrensbox committed Jul 2, 2021
2 parents f75fa6c + 7a3e96a commit 573ed84
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 5 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,6 @@ tfswitch*

build-script.sh

.idea

/vendor
1 change: 1 addition & 0 deletions lib/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ func removeFiles(src string) {
if err != nil {
panic(err)
}

for _, f := range files {
if err := os.Remove(f); err != nil {
panic(err)
Expand Down
6 changes: 3 additions & 3 deletions lib/download_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,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
Expand Down Expand Up @@ -92,7 +92,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
Expand Down Expand Up @@ -166,7 +166,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"

Expand Down
25 changes: 24 additions & 1 deletion lib/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const (
hashiURL = "https://releases.hashicorp.com/terraform/"
installFile = "terraform"
installVersion = "terraform_"
installPath = "/.terraform.versions/"
installPath = ".terraform.versions"
recentFile = "RECENT"
)

Expand Down Expand Up @@ -50,6 +50,29 @@ func initialize() {

}

// get install path variable value (windows os runtime support)
func getInstallPath() string {
return string(os.PathSeparator) + installPath + string(os.PathSeparator)
}

// get versioned install filename (windows os runtime support)
func getVersionedInstallFileName(tfversion string) string {
if runtime.GOOS == "windows" {
return filepath.Join(getInstallLocation(), installVersion + tfversion + ".exe")
}

return getInstallLocation() + installVersion + tfversion
}

// get install filename (windows os runtime support)
func getInstallFileName() string {
if runtime.GOOS == "windows" {
return filepath.Join(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 {
Expand Down
14 changes: 14 additions & 0 deletions lib/install_test.go
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down

0 comments on commit 573ed84

Please sign in to comment.