-
Notifications
You must be signed in to change notification settings - Fork 0
/
main_test.go
77 lines (70 loc) · 2.26 KB
/
main_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package main
import (
"testing"
"github.com/coreos/go-semver/semver"
)
func stringToVersionSlice(stringSlice []string) []*semver.Version {
versionSlice := make([]*semver.Version, len(stringSlice))
for i, versionString := range stringSlice {
versionSlice[i] = semver.New(versionString)
}
return versionSlice
}
func versionToStringSlice(versionSlice []*semver.Version) []string {
stringSlice := make([]string, len(versionSlice))
for i, version := range versionSlice {
stringSlice[i] = version.String()
}
return stringSlice
}
func TestLatestVersions(t *testing.T) {
testCases := []struct {
versionSlice []string
expectedResult []string
minVersion *semver.Version
}{
{
versionSlice: []string{"1.8.11", "1.9.6", "1.10.1", "1.9.5", "1.8.10", "1.10.0", "1.7.14", "1.8.9", "1.9.5"},
expectedResult: []string{"1.10.1", "1.9.6", "1.8.11"},
minVersion: semver.New("1.8.0"),
},
{
versionSlice: []string{"1.8.11", "1.9.6", "1.10.1", "1.9.5", "1.8.10", "1.10.0", "1.7.14", "1.8.9", "1.9.5"},
expectedResult: []string{"1.10.1", "1.9.6"},
minVersion: semver.New("1.8.12"),
},
{
versionSlice: []string{"1.10.1", "1.9.5", "1.8.10", "1.10.0", "1.7.14", "1.8.9", "1.9.5"},
expectedResult: []string{"1.10.1"},
minVersion: semver.New("1.10.0"),
},
{
versionSlice: []string{"2.2.1", "2.2.0"},
expectedResult: []string{"2.2.1"},
minVersion: semver.New("2.2.1"),
},
{
versionSlice: []string{"2.2.1", "2.2.0", "1.9.8", "1.7.6"},
expectedResult: []string{"2.2.1", "1.9.8"},
minVersion: semver.New("1.9.2"),
},
{
versionSlice: []string{"1.3.4", "1.5.2"},
expectedResult: []string{},
minVersion: semver.New("1.6.1"),
},
// Implement more relevant test cases here, if you can think of any
}
test := func(versionData []string, expectedResult []string, minVersion *semver.Version) {
stringSlice := versionToStringSlice(LatestVersions(stringToVersionSlice(versionData), minVersion))
for i, versionString := range stringSlice {
if versionString != expectedResult[i] {
t.Errorf("Received %s, expected %s", stringSlice, expectedResult)
return
}
}
}
for _, testValues := range testCases {
test(testValues.versionSlice, testValues.expectedResult, testValues.minVersion)
}
}