Compare commits
No commits in common. "master" and "1.2.0" have entirely different histories.
6
Makefile
6
Makefile
@ -7,12 +7,12 @@ build:
|
||||
# Clean
|
||||
####################################################
|
||||
clean:
|
||||
rm -f $(shell go env GOPATH)/bin/versionedTerraform
|
||||
rm -f ~/.local/bin/versionedTerraform
|
||||
####################################################
|
||||
# Install
|
||||
####################################################
|
||||
install:
|
||||
mv versionedTerraform $(shell go env GOPATH)/bin/
|
||||
mv versionedTerraform ~/.local/bin/
|
||||
####################################################
|
||||
# help feature
|
||||
####################################################
|
||||
@ -22,6 +22,6 @@ help:
|
||||
@echo 'Targets:'
|
||||
@echo ' build go build -o versionedTerraform ./cmd'
|
||||
@echo ' clean removes installed versionedTerraform file'
|
||||
@echo ' install installs versionedTerraform to bin folder in GOPATH'
|
||||
@echo ' install installs versionedTerraform to local user bin folder'
|
||||
@echo ' all Nothing to do.'
|
||||
@echo ''
|
@ -5,7 +5,7 @@ A wrapper for terraform to detect the expected version of terraform,
|
||||
download, and execute that version
|
||||
|
||||
## Requirements
|
||||
- go
|
||||
- go compiler (only tested on go1.17)
|
||||
|
||||
## Install
|
||||
`make build install` for installation to local user<br>
|
||||
|
@ -86,50 +86,3 @@ func (s *SemVersion) VersionInSlice(sSem []SemVersion) bool {
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (s *SemVersion) IsEqualTo(s2 SemVersion) bool {
|
||||
if s.majorVersion == s2.majorVersion && s.minorVersion == s2.minorVersion && s.patchVersion == s2.patchVersion {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (s *SemVersion) IsLessThan(s2 SemVersion) bool {
|
||||
if s2.majorVersion > s.majorVersion {
|
||||
return true
|
||||
}
|
||||
if s2.minorVersion > s.minorVersion && s2.majorVersion == s.majorVersion {
|
||||
return true
|
||||
}
|
||||
if s2.patchVersion > s.patchVersion && s2.majorVersion == s.majorVersion && s2.minorVersion == s.minorVersion {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (s *SemVersion) IsGreaterThan(s2 SemVersion) bool {
|
||||
if s2.majorVersion < s.majorVersion {
|
||||
return true
|
||||
}
|
||||
if s2.minorVersion < s.minorVersion && s2.majorVersion == s.majorVersion {
|
||||
return true
|
||||
}
|
||||
if s2.patchVersion < s.patchVersion && s2.majorVersion == s.majorVersion && s2.minorVersion == s.minorVersion {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (s *SemVersion) IsLessOrEqual(s2 SemVersion) bool {
|
||||
if s.IsLessThan(s2) || s.IsEqualTo(s2) {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (s *SemVersion) IsGreaterOrEqual(s2 SemVersion) bool {
|
||||
if s.IsGreaterThan(s2) || s.IsEqualTo(s2) {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
@ -86,688 +86,3 @@ func TestSemVersion_VersionInSlice_fail(t *testing.T) {
|
||||
t.Errorf("Expected Sem Version to not be found in semArray")
|
||||
}
|
||||
}
|
||||
|
||||
func TestSemVersion_IsLessThan(t *testing.T) {
|
||||
cases := []struct {
|
||||
name string
|
||||
want bool
|
||||
s1, s2 SemVersion
|
||||
}{
|
||||
{"IsEqualTo",
|
||||
false,
|
||||
SemVersion{
|
||||
version: "1.2.3",
|
||||
isStable: false,
|
||||
majorVersion: 1,
|
||||
minorVersion: 2,
|
||||
patchVersion: 3,
|
||||
},
|
||||
SemVersion{
|
||||
version: "1.2.3",
|
||||
isStable: false,
|
||||
majorVersion: 1,
|
||||
minorVersion: 2,
|
||||
patchVersion: 3,
|
||||
},
|
||||
},
|
||||
{"MajorVersionLess",
|
||||
true,
|
||||
SemVersion{
|
||||
version: "1.2.3",
|
||||
isStable: false,
|
||||
majorVersion: 1,
|
||||
minorVersion: 2,
|
||||
patchVersion: 3,
|
||||
},
|
||||
SemVersion{
|
||||
version: "2.2.3",
|
||||
isStable: false,
|
||||
majorVersion: 2,
|
||||
minorVersion: 2,
|
||||
patchVersion: 3,
|
||||
},
|
||||
},
|
||||
{"MinorVersionLess",
|
||||
true,
|
||||
SemVersion{
|
||||
version: "1.2.3",
|
||||
isStable: false,
|
||||
majorVersion: 1,
|
||||
minorVersion: 2,
|
||||
patchVersion: 3,
|
||||
},
|
||||
SemVersion{
|
||||
version: "1.3.3",
|
||||
isStable: false,
|
||||
majorVersion: 1,
|
||||
minorVersion: 3,
|
||||
patchVersion: 3,
|
||||
},
|
||||
},
|
||||
{"PatchVersionLess",
|
||||
true,
|
||||
SemVersion{
|
||||
version: "1.2.3",
|
||||
isStable: false,
|
||||
majorVersion: 1,
|
||||
minorVersion: 2,
|
||||
patchVersion: 3,
|
||||
},
|
||||
SemVersion{
|
||||
version: "1.2.3",
|
||||
isStable: false,
|
||||
majorVersion: 2,
|
||||
minorVersion: 2,
|
||||
patchVersion: 3,
|
||||
},
|
||||
},
|
||||
{"MajorVersionGreater",
|
||||
false,
|
||||
SemVersion{
|
||||
version: "2.2.3",
|
||||
isStable: false,
|
||||
majorVersion: 2,
|
||||
minorVersion: 2,
|
||||
patchVersion: 3,
|
||||
},
|
||||
SemVersion{
|
||||
version: "1.2.4",
|
||||
isStable: false,
|
||||
majorVersion: 1,
|
||||
minorVersion: 2,
|
||||
patchVersion: 4,
|
||||
},
|
||||
},
|
||||
{"MinorVersionGreater",
|
||||
false,
|
||||
SemVersion{
|
||||
version: "1.3.3",
|
||||
isStable: false,
|
||||
majorVersion: 1,
|
||||
minorVersion: 3,
|
||||
patchVersion: 3,
|
||||
},
|
||||
SemVersion{
|
||||
version: "1.2.3",
|
||||
isStable: false,
|
||||
majorVersion: 1,
|
||||
minorVersion: 2,
|
||||
patchVersion: 3,
|
||||
},
|
||||
},
|
||||
{"PatchVersionGreater",
|
||||
false,
|
||||
SemVersion{
|
||||
version: "1.2.4",
|
||||
isStable: false,
|
||||
majorVersion: 1,
|
||||
minorVersion: 2,
|
||||
patchVersion: 4,
|
||||
},
|
||||
SemVersion{
|
||||
version: "1.2.3",
|
||||
isStable: false,
|
||||
majorVersion: 1,
|
||||
minorVersion: 2,
|
||||
patchVersion: 3,
|
||||
},
|
||||
},
|
||||
}
|
||||
for _, c := range cases {
|
||||
t.Run("Test: "+c.name, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
got := c.s1.IsLessThan(c.s2)
|
||||
if c.want != got {
|
||||
t.Errorf("Expected %+v got %+v", c.want, got)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestSemVersion_IsGreaterThan(t *testing.T) {
|
||||
cases := []struct {
|
||||
name string
|
||||
want bool
|
||||
s1, s2 SemVersion
|
||||
}{
|
||||
{"IsEqualTo",
|
||||
false,
|
||||
SemVersion{
|
||||
version: "1.2.3",
|
||||
isStable: false,
|
||||
majorVersion: 1,
|
||||
minorVersion: 2,
|
||||
patchVersion: 3,
|
||||
},
|
||||
SemVersion{
|
||||
version: "1.2.3",
|
||||
isStable: false,
|
||||
majorVersion: 1,
|
||||
minorVersion: 2,
|
||||
patchVersion: 3,
|
||||
},
|
||||
},
|
||||
{"MajorVersionLess",
|
||||
false,
|
||||
SemVersion{
|
||||
version: "1.2.3",
|
||||
isStable: false,
|
||||
majorVersion: 1,
|
||||
minorVersion: 2,
|
||||
patchVersion: 3,
|
||||
},
|
||||
SemVersion{
|
||||
version: "2.2.3",
|
||||
isStable: false,
|
||||
majorVersion: 2,
|
||||
minorVersion: 2,
|
||||
patchVersion: 3,
|
||||
},
|
||||
},
|
||||
{"MinorVersionLess",
|
||||
false,
|
||||
SemVersion{
|
||||
version: "1.2.3",
|
||||
isStable: false,
|
||||
majorVersion: 1,
|
||||
minorVersion: 2,
|
||||
patchVersion: 3,
|
||||
},
|
||||
SemVersion{
|
||||
version: "1.3.3",
|
||||
isStable: false,
|
||||
majorVersion: 1,
|
||||
minorVersion: 3,
|
||||
patchVersion: 3,
|
||||
},
|
||||
},
|
||||
{"PatchVersionLess",
|
||||
false,
|
||||
SemVersion{
|
||||
version: "1.2.3",
|
||||
isStable: false,
|
||||
majorVersion: 1,
|
||||
minorVersion: 2,
|
||||
patchVersion: 3,
|
||||
},
|
||||
SemVersion{
|
||||
version: "1.2.3",
|
||||
isStable: false,
|
||||
majorVersion: 2,
|
||||
minorVersion: 2,
|
||||
patchVersion: 3,
|
||||
},
|
||||
},
|
||||
{"MajorVersionGreater",
|
||||
true,
|
||||
SemVersion{
|
||||
version: "2.2.3",
|
||||
isStable: false,
|
||||
majorVersion: 2,
|
||||
minorVersion: 2,
|
||||
patchVersion: 3,
|
||||
},
|
||||
SemVersion{
|
||||
version: "1.2.4",
|
||||
isStable: false,
|
||||
majorVersion: 1,
|
||||
minorVersion: 2,
|
||||
patchVersion: 4,
|
||||
},
|
||||
},
|
||||
{"MinorVersionGreater",
|
||||
true,
|
||||
SemVersion{
|
||||
version: "1.3.3",
|
||||
isStable: false,
|
||||
majorVersion: 1,
|
||||
minorVersion: 3,
|
||||
patchVersion: 3,
|
||||
},
|
||||
SemVersion{
|
||||
version: "1.2.3",
|
||||
isStable: false,
|
||||
majorVersion: 1,
|
||||
minorVersion: 2,
|
||||
patchVersion: 3,
|
||||
},
|
||||
},
|
||||
{"PatchVersionGreater",
|
||||
true,
|
||||
SemVersion{
|
||||
version: "1.2.4",
|
||||
isStable: false,
|
||||
majorVersion: 1,
|
||||
minorVersion: 2,
|
||||
patchVersion: 4,
|
||||
},
|
||||
SemVersion{
|
||||
version: "1.2.3",
|
||||
isStable: false,
|
||||
majorVersion: 1,
|
||||
minorVersion: 2,
|
||||
patchVersion: 3,
|
||||
},
|
||||
},
|
||||
}
|
||||
for _, c := range cases {
|
||||
t.Run("Test: "+c.name, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
got := c.s1.IsGreaterThan(c.s2)
|
||||
if c.want != got {
|
||||
t.Errorf("Expected %+v got %+v", c.want, got)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestSemVersion_IsEqualTo(t *testing.T) {
|
||||
cases := []struct {
|
||||
name string
|
||||
want bool
|
||||
s1, s2 SemVersion
|
||||
}{
|
||||
{"IsEqualTo",
|
||||
true,
|
||||
SemVersion{
|
||||
version: "1.2.3",
|
||||
isStable: false,
|
||||
majorVersion: 1,
|
||||
minorVersion: 2,
|
||||
patchVersion: 3,
|
||||
},
|
||||
SemVersion{
|
||||
version: "1.2.3",
|
||||
isStable: false,
|
||||
majorVersion: 1,
|
||||
minorVersion: 2,
|
||||
patchVersion: 3,
|
||||
},
|
||||
},
|
||||
{"MajorVersionLess",
|
||||
false,
|
||||
SemVersion{
|
||||
version: "1.2.3",
|
||||
isStable: false,
|
||||
majorVersion: 1,
|
||||
minorVersion: 2,
|
||||
patchVersion: 3,
|
||||
},
|
||||
SemVersion{
|
||||
version: "2.2.3",
|
||||
isStable: false,
|
||||
majorVersion: 2,
|
||||
minorVersion: 2,
|
||||
patchVersion: 3,
|
||||
},
|
||||
},
|
||||
{"MinorVersionLess",
|
||||
false,
|
||||
SemVersion{
|
||||
version: "1.2.3",
|
||||
isStable: false,
|
||||
majorVersion: 1,
|
||||
minorVersion: 2,
|
||||
patchVersion: 3,
|
||||
},
|
||||
SemVersion{
|
||||
version: "1.3.3",
|
||||
isStable: false,
|
||||
majorVersion: 1,
|
||||
minorVersion: 3,
|
||||
patchVersion: 3,
|
||||
},
|
||||
},
|
||||
{"PatchVersionLess",
|
||||
false,
|
||||
SemVersion{
|
||||
version: "1.2.3",
|
||||
isStable: false,
|
||||
majorVersion: 1,
|
||||
minorVersion: 2,
|
||||
patchVersion: 3,
|
||||
},
|
||||
SemVersion{
|
||||
version: "1.2.3",
|
||||
isStable: false,
|
||||
majorVersion: 2,
|
||||
minorVersion: 2,
|
||||
patchVersion: 3,
|
||||
},
|
||||
},
|
||||
{"MajorVersionGreater",
|
||||
false,
|
||||
SemVersion{
|
||||
version: "2.2.3",
|
||||
isStable: false,
|
||||
majorVersion: 2,
|
||||
minorVersion: 2,
|
||||
patchVersion: 3,
|
||||
},
|
||||
SemVersion{
|
||||
version: "1.2.4",
|
||||
isStable: false,
|
||||
majorVersion: 1,
|
||||
minorVersion: 2,
|
||||
patchVersion: 4,
|
||||
},
|
||||
},
|
||||
{"MinorVersionGreater",
|
||||
false,
|
||||
SemVersion{
|
||||
version: "1.3.3",
|
||||
isStable: false,
|
||||
majorVersion: 1,
|
||||
minorVersion: 3,
|
||||
patchVersion: 3,
|
||||
},
|
||||
SemVersion{
|
||||
version: "1.2.3",
|
||||
isStable: false,
|
||||
majorVersion: 1,
|
||||
minorVersion: 2,
|
||||
patchVersion: 3,
|
||||
},
|
||||
},
|
||||
{"PatchVersionGreater",
|
||||
false,
|
||||
SemVersion{
|
||||
version: "1.2.4",
|
||||
isStable: false,
|
||||
majorVersion: 1,
|
||||
minorVersion: 2,
|
||||
patchVersion: 4,
|
||||
},
|
||||
SemVersion{
|
||||
version: "1.2.3",
|
||||
isStable: false,
|
||||
majorVersion: 1,
|
||||
minorVersion: 2,
|
||||
patchVersion: 3,
|
||||
},
|
||||
},
|
||||
}
|
||||
for _, c := range cases {
|
||||
t.Run("Test: "+c.name, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
got := c.s1.IsEqualTo(c.s2)
|
||||
if c.want != got {
|
||||
t.Errorf("Expected %+v got %+v", c.want, got)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestSemVersion_IsLessOrEqual(t *testing.T) {
|
||||
cases := []struct {
|
||||
name string
|
||||
want bool
|
||||
s1, s2 SemVersion
|
||||
}{
|
||||
{"IsEqualTo",
|
||||
true,
|
||||
SemVersion{
|
||||
version: "1.2.3",
|
||||
isStable: false,
|
||||
majorVersion: 1,
|
||||
minorVersion: 2,
|
||||
patchVersion: 3,
|
||||
},
|
||||
SemVersion{
|
||||
version: "1.2.3",
|
||||
isStable: false,
|
||||
majorVersion: 1,
|
||||
minorVersion: 2,
|
||||
patchVersion: 3,
|
||||
},
|
||||
},
|
||||
{"MajorVersionLess",
|
||||
true,
|
||||
SemVersion{
|
||||
version: "1.2.3",
|
||||
isStable: false,
|
||||
majorVersion: 1,
|
||||
minorVersion: 2,
|
||||
patchVersion: 3,
|
||||
},
|
||||
SemVersion{
|
||||
version: "2.2.3",
|
||||
isStable: false,
|
||||
majorVersion: 2,
|
||||
minorVersion: 2,
|
||||
patchVersion: 3,
|
||||
},
|
||||
},
|
||||
{"MinorVersionLess",
|
||||
true,
|
||||
SemVersion{
|
||||
version: "1.2.3",
|
||||
isStable: false,
|
||||
majorVersion: 1,
|
||||
minorVersion: 2,
|
||||
patchVersion: 3,
|
||||
},
|
||||
SemVersion{
|
||||
version: "1.3.3",
|
||||
isStable: false,
|
||||
majorVersion: 1,
|
||||
minorVersion: 3,
|
||||
patchVersion: 3,
|
||||
},
|
||||
},
|
||||
{"PatchVersionLess",
|
||||
true,
|
||||
SemVersion{
|
||||
version: "1.2.3",
|
||||
isStable: false,
|
||||
majorVersion: 1,
|
||||
minorVersion: 2,
|
||||
patchVersion: 3,
|
||||
},
|
||||
SemVersion{
|
||||
version: "1.2.3",
|
||||
isStable: false,
|
||||
majorVersion: 2,
|
||||
minorVersion: 2,
|
||||
patchVersion: 3,
|
||||
},
|
||||
},
|
||||
{"MajorVersionGreater",
|
||||
false,
|
||||
SemVersion{
|
||||
version: "2.2.3",
|
||||
isStable: false,
|
||||
majorVersion: 2,
|
||||
minorVersion: 2,
|
||||
patchVersion: 3,
|
||||
},
|
||||
SemVersion{
|
||||
version: "1.2.4",
|
||||
isStable: false,
|
||||
majorVersion: 1,
|
||||
minorVersion: 2,
|
||||
patchVersion: 4,
|
||||
},
|
||||
},
|
||||
{"MinorVersionGreater",
|
||||
false,
|
||||
SemVersion{
|
||||
version: "1.3.3",
|
||||
isStable: false,
|
||||
majorVersion: 1,
|
||||
minorVersion: 3,
|
||||
patchVersion: 3,
|
||||
},
|
||||
SemVersion{
|
||||
version: "1.2.3",
|
||||
isStable: false,
|
||||
majorVersion: 1,
|
||||
minorVersion: 2,
|
||||
patchVersion: 3,
|
||||
},
|
||||
},
|
||||
{"PatchVersionGreater",
|
||||
false,
|
||||
SemVersion{
|
||||
version: "1.2.4",
|
||||
isStable: false,
|
||||
majorVersion: 1,
|
||||
minorVersion: 2,
|
||||
patchVersion: 4,
|
||||
},
|
||||
SemVersion{
|
||||
version: "1.2.3",
|
||||
isStable: false,
|
||||
majorVersion: 1,
|
||||
minorVersion: 2,
|
||||
patchVersion: 3,
|
||||
},
|
||||
},
|
||||
}
|
||||
for _, c := range cases {
|
||||
t.Run("Test: "+c.name, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
got := c.s1.IsLessOrEqual(c.s2)
|
||||
if c.want != got {
|
||||
t.Errorf("Expected %+v got %+v", c.want, got)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestSemVersion_IsGreaterOrEqual(t *testing.T) {
|
||||
cases := []struct {
|
||||
name string
|
||||
want bool
|
||||
s1, s2 SemVersion
|
||||
}{
|
||||
{"IsEqualTo",
|
||||
true,
|
||||
SemVersion{
|
||||
version: "1.2.3",
|
||||
isStable: false,
|
||||
majorVersion: 1,
|
||||
minorVersion: 2,
|
||||
patchVersion: 3,
|
||||
},
|
||||
SemVersion{
|
||||
version: "1.2.3",
|
||||
isStable: false,
|
||||
majorVersion: 1,
|
||||
minorVersion: 2,
|
||||
patchVersion: 3,
|
||||
},
|
||||
},
|
||||
{"MajorVersionLess",
|
||||
false,
|
||||
SemVersion{
|
||||
version: "1.2.3",
|
||||
isStable: false,
|
||||
majorVersion: 1,
|
||||
minorVersion: 2,
|
||||
patchVersion: 3,
|
||||
},
|
||||
SemVersion{
|
||||
version: "2.2.3",
|
||||
isStable: false,
|
||||
majorVersion: 2,
|
||||
minorVersion: 2,
|
||||
patchVersion: 3,
|
||||
},
|
||||
},
|
||||
{"MinorVersionLess",
|
||||
false,
|
||||
SemVersion{
|
||||
version: "1.2.3",
|
||||
isStable: false,
|
||||
majorVersion: 1,
|
||||
minorVersion: 2,
|
||||
patchVersion: 3,
|
||||
},
|
||||
SemVersion{
|
||||
version: "1.3.3",
|
||||
isStable: false,
|
||||
majorVersion: 1,
|
||||
minorVersion: 3,
|
||||
patchVersion: 3,
|
||||
},
|
||||
},
|
||||
{"PatchVersionLess",
|
||||
false,
|
||||
SemVersion{
|
||||
version: "1.2.3",
|
||||
isStable: false,
|
||||
majorVersion: 1,
|
||||
minorVersion: 2,
|
||||
patchVersion: 3,
|
||||
},
|
||||
SemVersion{
|
||||
version: "1.2.3",
|
||||
isStable: false,
|
||||
majorVersion: 2,
|
||||
minorVersion: 2,
|
||||
patchVersion: 3,
|
||||
},
|
||||
},
|
||||
{"MajorVersionGreater",
|
||||
true,
|
||||
SemVersion{
|
||||
version: "2.2.3",
|
||||
isStable: false,
|
||||
majorVersion: 2,
|
||||
minorVersion: 2,
|
||||
patchVersion: 3,
|
||||
},
|
||||
SemVersion{
|
||||
version: "1.2.4",
|
||||
isStable: false,
|
||||
majorVersion: 1,
|
||||
minorVersion: 2,
|
||||
patchVersion: 4,
|
||||
},
|
||||
},
|
||||
{"MinorVersionGreater",
|
||||
true,
|
||||
SemVersion{
|
||||
version: "1.3.3",
|
||||
isStable: false,
|
||||
majorVersion: 1,
|
||||
minorVersion: 3,
|
||||
patchVersion: 3,
|
||||
},
|
||||
SemVersion{
|
||||
version: "1.2.3",
|
||||
isStable: false,
|
||||
majorVersion: 1,
|
||||
minorVersion: 2,
|
||||
patchVersion: 3,
|
||||
},
|
||||
},
|
||||
{"PatchVersionGreater",
|
||||
true,
|
||||
SemVersion{
|
||||
version: "1.2.4",
|
||||
isStable: false,
|
||||
majorVersion: 1,
|
||||
minorVersion: 2,
|
||||
patchVersion: 4,
|
||||
},
|
||||
SemVersion{
|
||||
version: "1.2.3",
|
||||
isStable: false,
|
||||
majorVersion: 1,
|
||||
minorVersion: 2,
|
||||
patchVersion: 3,
|
||||
},
|
||||
},
|
||||
}
|
||||
for _, c := range cases {
|
||||
t.Run("Test: "+c.name, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
got := c.s1.IsGreaterOrEqual(c.s2)
|
||||
if c.want != got {
|
||||
t.Errorf("Expected %+v got %+v", c.want, got)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
@ -5,6 +5,4 @@ package versionedTerraform
|
||||
|
||||
const (
|
||||
fileSuffix = "_darwin_amd64.zip"
|
||||
minVersion = "0.0.0"
|
||||
alternateSuffix = ""
|
||||
)
|
||||
|
@ -5,6 +5,4 @@ package versionedTerraform
|
||||
|
||||
const (
|
||||
fileSuffix = "_darwin_arm64.zip"
|
||||
minVersion = "1.0.2"
|
||||
alternateSuffix = "_darwin_amd64.zip"
|
||||
)
|
||||
|
@ -5,6 +5,4 @@ package versionedTerraform
|
||||
|
||||
const (
|
||||
fileSuffix = "_freebsd_386.zip"
|
||||
minVersion = "0.0.0"
|
||||
alternateSuffix = ""
|
||||
)
|
||||
|
@ -5,6 +5,4 @@ package versionedTerraform
|
||||
|
||||
const (
|
||||
fileSuffix = "_freebsd_amd64.zip"
|
||||
minVersion = "0.0.0"
|
||||
alternateSuffix = ""
|
||||
)
|
||||
|
@ -5,6 +5,4 @@ package versionedTerraform
|
||||
|
||||
const (
|
||||
fileSuffix = "_freebsd_arm.zip"
|
||||
minVersion = "0.0.0"
|
||||
alternateSuffix = ""
|
||||
)
|
||||
|
@ -5,6 +5,4 @@ package versionedTerraform
|
||||
|
||||
const (
|
||||
fileSuffix = "_linux_386.zip"
|
||||
minVersion = "0.0.0"
|
||||
alternateSuffix = ""
|
||||
)
|
||||
|
@ -5,6 +5,4 @@ package versionedTerraform
|
||||
|
||||
const (
|
||||
fileSuffix = "_linux_amd64.zip"
|
||||
minVersion = "0.0.0"
|
||||
alternateSuffix = ""
|
||||
)
|
||||
|
@ -5,6 +5,4 @@ package versionedTerraform
|
||||
|
||||
const (
|
||||
fileSuffix = "_linux_arm.zip"
|
||||
minVersion = "0.0.0"
|
||||
alternateSuffix = ""
|
||||
)
|
||||
|
@ -5,6 +5,4 @@ package versionedTerraform
|
||||
|
||||
const (
|
||||
fileSuffix = "_linux_arm64.zip"
|
||||
minVersion = "0.0.0"
|
||||
alternateSuffix = ""
|
||||
)
|
||||
|
@ -5,6 +5,4 @@ package versionedTerraform
|
||||
|
||||
const (
|
||||
fileSuffix = "_openbsd_386.zip"
|
||||
minVersion = "0.0.0"
|
||||
alternateSuffix = ""
|
||||
)
|
||||
|
@ -5,6 +5,4 @@ package versionedTerraform
|
||||
|
||||
const (
|
||||
fileSuffix = "_openbsd_amd64.zip"
|
||||
minVersion = "0.0.0"
|
||||
alternateSuffix = ""
|
||||
)
|
||||
|
@ -5,6 +5,4 @@ package versionedTerraform
|
||||
|
||||
const (
|
||||
fileSuffix = "_solaris_amd64.zip"
|
||||
minVersion = "0.0.0"
|
||||
alternateSuffix = ""
|
||||
)
|
||||
|
@ -5,7 +5,6 @@ import (
|
||||
"bufio"
|
||||
"bytes"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
@ -63,6 +62,7 @@ func (v *Version) getOneLessRelease() {
|
||||
|
||||
//getLatestRelease returns the latest release from Version
|
||||
func (v *Version) getLatestRelease() {
|
||||
//todo clean up
|
||||
for _, release := range v.availableVersions {
|
||||
if release.majorVersion > v.Version.majorVersion &&
|
||||
(release.isStable || !needsStable) {
|
||||
@ -86,59 +86,51 @@ func (v *Version) getLatestRelease() {
|
||||
//configuration directory
|
||||
func (v *Version) InstallTerraformVersion() error {
|
||||
homeDir, _ := os.UserHomeDir()
|
||||
suffix := fileSuffix
|
||||
minV := NewSemVersion(minVersion)
|
||||
if v.Version.IsLessThan(*minV) {
|
||||
suffix = alternateSuffix
|
||||
}
|
||||
url := hashicorpUrl +
|
||||
resp, err := http.Get(hashicorpUrl +
|
||||
v.Version.ToString() +
|
||||
"/" + terraformPrefix +
|
||||
v.Version.ToString() +
|
||||
suffix
|
||||
|
||||
resp, err := http.Get(url)
|
||||
fileSuffix)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to download Terraform: %v", err)
|
||||
return err
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
body, err := ioutil.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to read response body: %v", err)
|
||||
return err
|
||||
}
|
||||
|
||||
zipReader, err := zip.NewReader(bytes.NewReader(body), int64(len(body)))
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to create zip reader: %v", err)
|
||||
return err
|
||||
}
|
||||
|
||||
versionedFileName := homeDir + versionedTerraformFolder + "/" + terraformPrefix + v.Version.ToString()
|
||||
versionedFile, err := os.OpenFile(versionedFileName, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0755)
|
||||
versionedFile, err := os.OpenFile(versionedFileName, os.O_WRONLY, 0755)
|
||||
if os.IsNotExist(err) {
|
||||
versionedFile, err = os.OpenFile(versionedFileName, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0755)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to create output file: %v", err)
|
||||
return err
|
||||
}
|
||||
}
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer versionedFile.Close()
|
||||
|
||||
for _, zipFile := range zipReader.File {
|
||||
if zipFile.Name != "terraform" {
|
||||
continue
|
||||
}
|
||||
|
||||
zr, err := zipFile.Open()
|
||||
for _, zipFIle := range zipReader.File {
|
||||
zr, err := zipFIle.Open()
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to open zip file: %v", err)
|
||||
return err
|
||||
}
|
||||
defer zr.Close()
|
||||
unzippedFileBytes, _ := ioutil.ReadAll(zr)
|
||||
|
||||
_, err = io.Copy(versionedFile, zr)
|
||||
_, err = versionedFile.Write(unzippedFileBytes)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to write terraform binary: %v", err)
|
||||
return err
|
||||
}
|
||||
|
||||
break
|
||||
zr.Close()
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -5,6 +5,4 @@ package versionedTerraform
|
||||
|
||||
const (
|
||||
fileSuffix = "_windows_386.zip"
|
||||
minVersion = "0.0.0"
|
||||
alternateSuffix = ""
|
||||
)
|
||||
|
@ -5,6 +5,4 @@ package versionedTerraform
|
||||
|
||||
const (
|
||||
fileSuffix = "_windows_amd64.zip"
|
||||
minVersion = "0.0.0"
|
||||
alternateSuffix = ""
|
||||
)
|
||||
|
Loading…
Reference in New Issue
Block a user