Skip to content

Commit

Permalink
fix: Path in .terraform.d should contain normalized version.
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Wentzel committed Jan 11, 2022
1 parent f6c2225 commit 7f31380
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
10 changes: 10 additions & 0 deletions internal/app/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,14 @@ func extractMajorVersionAsNumber(version string) int {
return number
}

func normalizeSemver(version string) string {
if strings.HasPrefix(version, "v") {
return version[1:]
}

return version
}

func createBuildCommand(providerName string, version string) string {
majorVersionNumberAsInt := extractMajorVersionAsNumber(version)

Expand Down Expand Up @@ -200,6 +208,8 @@ func (a *App) buildProvider(dir string, providerName string, version string) {
func (a *App) moveBinaryToCorrectLocation(providerName string, version string, executableName string) {
if len(version) == 0 {
version = "master"
} else {
version = normalizeSemver(version)
}

filePath := a.Config.TerraformPluginDir + "/registry.terraform.io/" + providerName + "/" + version + "/darwin_arm64"
Expand Down
17 changes: 14 additions & 3 deletions internal/app/install_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,27 @@ func TestCreateBuildCommand(t *testing.T) {
buildCommand = createBuildCommand("datadog/datadog", "2.35.9")
expectedBuildCommand = "make build"
if buildCommand != expectedBuildCommand {
t.Fatalf("buildCommand should be equal make build")
t.Fatalf("buildCommand '%s' should be equal '%s'", buildCommand, expectedBuildCommand)
}
buildCommand = createBuildCommand("hashicorp/aws", "v2.71.0")
expectedBuildCommand = "make tools && make fmt && gofmt -s -w ./tools.go && make build"
if buildCommand != expectedBuildCommand {
t.Fatalf("buildCommand2 should be equal make build")
t.Fatalf("buildCommand '%s' should be equal '%s'", buildCommand, expectedBuildCommand)
}
buildCommand = createBuildCommand("hashicorp/aws", "v3.0.0")
expectedBuildCommand = "cd tools && go get -d github.com/pavius/impi/cmd/impi && cd .. && make tools && make build"
if buildCommand != expectedBuildCommand {
t.Fatalf("buildCommand3 should be equal make build")
t.Fatalf("buildCommand '%s' should be equal '%s'", buildCommand, expectedBuildCommand)
}
}

func TestNormalizeSemver(t *testing.T) {
version := normalizeSemver("v2.34.5")
if version != "2.34.5" {
t.Fatalf("version should be equal 2.34.5, not %s", version)
}
version = normalizeSemver("2.34.5")
if version != "2.34.5" {
t.Fatalf("version2 should be equal 2.34.5, not %s", version)
}
}

0 comments on commit 7f31380

Please sign in to comment.