| 1 |
// Copyright (c) 2025 Arnaud Rebillout |
| 2 |
// Licensed under the MIT license |
| 3 |
|
| 4 |
package database |
| 5 |
|
| 6 |
import ( |
| 7 |
"fmt" |
| 8 |
"testing" |
| 9 |
) |
| 10 |
|
| 11 |
func TestIsAtLeastVersion(t *testing.T) { |
| 12 |
testsFalse := [] struct { |
| 13 |
have string |
| 14 |
want string |
| 15 |
} { |
| 16 |
{"", "3.2.0"}, |
| 17 |
{"2.0", "3.2.0"}, |
| 18 |
{"2.0.0", "3.2"}, |
| 19 |
{"2.0.0", "3.2.0"}, |
| 20 |
} |
| 21 |
for i, test := range testsFalse { |
| 22 |
r := Redis{ |
| 23 |
version: test.have, |
| 24 |
} |
| 25 |
t.Run(fmt.Sprintf("testsFalse/%d", i), func(t *testing.T) { |
| 26 |
if r.IsAtLeastVersion(test.want) { |
| 27 |
t.Errorf("Expected '%s' < '%s'", test.have, test.want) |
| 28 |
} |
| 29 |
}) |
| 30 |
} |
| 31 |
|
| 32 |
testsTrue := [] struct { |
| 33 |
have string |
| 34 |
want string |
| 35 |
} { |
| 36 |
{"3.2", "3.2.0"}, |
| 37 |
{"3.2.0", "3.2.0"}, |
| 38 |
{"6.0", "3.2.0"}, |
| 39 |
{"6.0.0", "3.2"}, |
| 40 |
{"6.0.0", "3.2.0"}, |
| 41 |
} |
| 42 |
for i, test := range testsTrue { |
| 43 |
r := Redis{ |
| 44 |
version: test.have, |
| 45 |
} |
| 46 |
t.Run(fmt.Sprintf("testsTrue/%d", i), func(t *testing.T) { |
| 47 |
if ! r.IsAtLeastVersion(test.want) { |
| 48 |
t.Errorf("Expected '%s' >= '%s'", test.have, test.want) |
| 49 |
} |
| 50 |
}) |
| 51 |
} |
| 52 |
} |