Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix integration test failure to parse eksctl version (#2742)
- Loading branch information
1 parent
e3b9a35
commit 3ad9e4b
Showing
5 changed files
with
63 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package version | ||
|
||
import ( | ||
"strings" | ||
|
||
"github.com/blang/semver" | ||
"github.com/pkg/errors" | ||
) | ||
|
||
// ParseEksctlVersion parses the an eksctl version as semver while ignoring | ||
// extra build metadata | ||
func ParseEksctlVersion(raw string) (semver.Version, error) { | ||
// We don't want any extra info from the version | ||
semverVersion := strings.Split(raw, ExtraSep)[0] | ||
v, err := semver.ParseTolerant(semverVersion) | ||
if err != nil { | ||
return v, errors.Wrapf(err, "unexpected error parsing eksctl version %q", raw) | ||
} | ||
return v, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package version | ||
|
||
import ( | ||
"github.com/blang/semver" | ||
. "github.com/onsi/ginkgo" | ||
. "github.com/onsi/gomega" | ||
) | ||
|
||
var _ = Describe("ParseEksctlVersion", func() { | ||
It("handles versions with metadata", func() { | ||
gitVersion := "0.27.0-dev+001eeced.2020-08-27T03:03:31Z" | ||
|
||
v, err := ParseEksctlVersion(gitVersion) | ||
|
||
Expect(err).NotTo(HaveOccurred()) | ||
Expect(v).To(Equal( | ||
semver.Version{ | ||
Major: 0, | ||
Minor: 27, | ||
Patch: 0, | ||
}, | ||
)) | ||
}) | ||
It("handles versions without metadata", func() { | ||
gitVersion := "0.27.0" | ||
|
||
v, err := ParseEksctlVersion(gitVersion) | ||
|
||
Expect(err).NotTo(HaveOccurred()) | ||
Expect(v).To(Equal( | ||
semver.Version{ | ||
Major: 0, | ||
Minor: 27, | ||
Patch: 0, | ||
}, | ||
)) | ||
}) | ||
}) |