From 21bef1641cc6d3e9aaeb0396bb39b69e7c2d66f7 Mon Sep 17 00:00:00 2001 From: Carlos Alexandro Becker Date: Mon, 5 Mar 2018 21:02:26 -0300 Subject: [PATCH] test: added failing test for #11 --- rpm/rpm.go | 6 +++++- rpm/rpm_test.go | 15 +++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/rpm/rpm.go b/rpm/rpm.go index 16c01b20..5f441219 100644 --- a/rpm/rpm.go +++ b/rpm/rpm.go @@ -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 { diff --git a/rpm/rpm_test.go b/rpm/rpm_test.go index a920f8d3..e5bfcf99 100644 --- a/rpm/rpm_test.go +++ b/rpm/rpm_test.go @@ -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) + }) + } +}