From 7f3aa2e932c610dde0be5809b835a4e1e7c3db09 Mon Sep 17 00:00:00 2001 From: Heitham Omar Date: Wed, 11 Apr 2018 19:05:47 +0100 Subject: [PATCH] Failing parser test Test fails when version A and range B are the same --- ext/versionfmt/rpm/parser.go | 2 ++ ext/versionfmt/rpm/parser_test.go | 24 ++++++++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/ext/versionfmt/rpm/parser.go b/ext/versionfmt/rpm/parser.go index 55266ca5..a5f66c7c 100644 --- a/ext/versionfmt/rpm/parser.go +++ b/ext/versionfmt/rpm/parser.go @@ -126,6 +126,8 @@ func (p parser) InRange(versionA, rangeB string) (bool, error) { if err != nil { return false, err } + // FIXME: Fails when version and range are the same + //return cmp <= 0, nil return cmp < 0, nil } diff --git a/ext/versionfmt/rpm/parser_test.go b/ext/versionfmt/rpm/parser_test.go index 73c6df89..6389e9a6 100644 --- a/ext/versionfmt/rpm/parser_test.go +++ b/ext/versionfmt/rpm/parser_test.go @@ -184,3 +184,27 @@ func TestParseAndCompare(t *testing.T) { assert.Equal(t, -c.expected, cmp, "%s vs. %s, = %d, expected %d", c.v2, c.v1, cmp, -c.expected) } } + +func TestInRange(t *testing.T) { + cases := []struct { + v1 string + expected bool + v2 string + }{ + {"5.4.2-1", true, "5.4.2-1"}, + {"2.7.6-1", true, "2.7.6-2"}, + {"1.1.0-3", true, "1.1.1-1"}, + {"20101121", true, "20101122"}, + {"2", false, "xyz.4"}, + {"10.0039", false, "10.0001"}, + {"1.0~rc1", false, "1.0~rc1~git123"}, + {"5.0", false, "4.999.9"}, + } + + var p parser + for _, c := range cases { + b, err := p.InRange(c.v1, c.v2) + assert.Nil(t, err) + assert.Equal(t, c.expected, b, "%s vs. %s, = %d, expected %d", c.v1, c.v2, b, c.expected) + } +}