(t *testing.T)
| 16 | ) |
| 17 | |
| 18 | func TestComparableBuildVersion(t *testing.T) { |
| 19 | // An *ascending* list of valid versions (order is required for comparison testing) |
| 20 | testDataComparableBuildVersions := []struct { |
| 21 | str string |
| 22 | }{ |
| 23 | {"0.0.0"}, // min |
| 24 | {"0.0.0.1"}, |
| 25 | {"0.0.1"}, |
| 26 | {"0.0.1.1"}, |
| 27 | {"0.1.0"}, |
| 28 | {"0.1.0.1"}, |
| 29 | {"0.1.0.1@2"}, // build ordering |
| 30 | {"0.1.0.1@11"}, |
| 31 | {"0.1.0.2"}, |
| 32 | {"0.1.1"}, |
| 33 | {"0.1.1.1"}, |
| 34 | {"0.1.1.1@1-CE"}, // edition ordering |
| 35 | {"0.1.1.1@1-EE"}, |
| 36 | {"1.0.0"}, |
| 37 | {"1.0.0.1"}, |
| 38 | {"1.1.1.1"}, |
| 39 | {"2.3.4"}, |
| 40 | {"2.3.4.5"}, |
| 41 | {"2.3.5"}, |
| 42 | {"11.0.0"}, // check for lexicographic ordering |
| 43 | {"31.3.3.7"}, |
| 44 | {"32.1.0"}, |
| 45 | {"1:22.3.25"}, // maintain ordering with new epoch when defining new versioning scheme (yy.m.d) |
| 46 | {"2:1.0.0"}, |
| 47 | {"8:7.6.5.4@3-EE"}, |
| 48 | {"255:255.255.255.255@65535-EE"}, // max |
| 49 | } |
| 50 | |
| 51 | for i, test := range testDataComparableBuildVersions { |
| 52 | t.Run(test.str, func(t *testing.T) { |
| 53 | current, err := NewComparableBuildVersionFromString(test.str) |
| 54 | require.NoError(t, err) |
| 55 | |
| 56 | // string->version->string round-trip |
| 57 | assert.Equal(t, test.str, current.String()) |
| 58 | |
| 59 | // comparisons (Less/Equal) |
| 60 | if i > 1 { |
| 61 | prevStr := testDataComparableBuildVersions[i-1].str |
| 62 | previous, err := NewComparableBuildVersionFromString(prevStr) |
| 63 | require.NoError(t, err) |
| 64 | |
| 65 | assert.Truef(t, previous.Less(current), "incorrect comparison: expected %q < %q", prevStr, test.str) |
| 66 | assert.Falsef(t, current.Equal(previous), "incorrect comparison: expected %q != %q", prevStr, test.str) |
| 67 | assert.Falsef(t, current.Less(previous), "incorrect comparison: expected %q > %q", test.str, prevStr) |
| 68 | } |
| 69 | }) |
| 70 | } |
| 71 | } |
| 72 | |
| 73 | func TestInvalidComparableBuildVersion(t *testing.T) { |
| 74 | // A list of invalid ComparableBuildVersion |
nothing calls this directly
no test coverage detected