Skip to content

Commit

Permalink
test: added failing test for #11
Browse files Browse the repository at this point in the history
  • Loading branch information
caarlos0 committed Mar 6, 2018
1 parent f0ada6f commit 21bef16
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
6 changes: 5 additions & 1 deletion rpm/rpm.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,12 @@ func getRpmbuildVersion() (rpmbuildVersion, error) {
if err != nil {
return rpmbuildVersion{}, errors.Wrap(err, "failed to get rpmbuild version")
}
return parseRPMbuildVersion(string(bts))
}

func parseRPMbuildVersion(out string) (rpmbuildVersion, error) {
var v = make([]int, 3)
vs := strings.TrimSuffix(strings.TrimPrefix(string(bts), "RPM version "), "\n")
vs := strings.TrimSuffix(strings.TrimPrefix(out, "RPM version "), "\n")
for i, part := range strings.Split(vs, ".")[:3] {
pi, err := strconv.Atoi(part)
if err != nil {
Expand Down
15 changes: 15 additions & 0 deletions rpm/rpm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,3 +116,18 @@ func TestRpmBuildVersion(t *testing.T) {
assert.True(t, v.Minor >= 11)
assert.True(t, v.Path >= 0)
}

func TestParseRpmbuildVersion(t *testing.T) {
for _, version := range []string{
"RPM-Version 4.14.1",
"RPM version 4.14.1",
} {
t.Run(version, func(t *testing.T) {
v, err := parseRPMbuildVersion(version)
assert.NoError(t, err)
assert.Equal(t, 4, v.Major)
assert.Equal(t, 14, v.Minor)
assert.Equal(t, 1, v.Path)
})
}
}

0 comments on commit 21bef16

Please sign in to comment.