-
Notifications
You must be signed in to change notification settings - Fork 67
/
indexer_test.go
83 lines (75 loc) · 1.87 KB
/
indexer_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
78
79
80
81
82
83
// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
// or more contributor license agreements. Licensed under the Elastic License;
// you may not use this file except in compliance with the Elastic License.
package main
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/elastic/package-registry/packages"
)
func TestLatestPackagesVersion(t *testing.T) {
newPackage := func(name string, version string) *packages.Package {
p := new(packages.Package)
p.Name = name
p.Version = version
return p
}
cases := []struct {
title string
source packages.Packages
expected packages.Packages
}{
{
title: "single package",
source: packages.Packages{
newPackage("foo", "1.2.3"),
},
expected: packages.Packages{
newPackage("foo", "1.2.3"),
},
},
{
title: "single package sorted versions",
source: packages.Packages{
newPackage("foo", "1.2.3"),
newPackage("foo", "1.2.2"),
newPackage("foo", "1.2.1"),
},
expected: packages.Packages{
newPackage("foo", "1.2.3"),
},
},
{
title: "single package unsorted versions",
source: packages.Packages{
newPackage("foo", "1.2.2"),
newPackage("foo", "1.2.1"),
newPackage("foo", "1.2.3"),
},
expected: packages.Packages{
newPackage("foo", "1.2.3"),
},
},
{
title: "multiple packages with multiple versions",
source: packages.Packages{
newPackage("foo", "1.2.2"),
newPackage("bar", "1.2.1"),
newPackage("bar", "1.2.2"),
newPackage("foo", "1.2.1"),
newPackage("bar", "1.2.3"),
newPackage("foo", "1.2.3"),
},
expected: packages.Packages{
newPackage("bar", "1.2.3"),
newPackage("foo", "1.2.3"),
},
},
}
for _, c := range cases {
t.Run(c.title, func(t *testing.T) {
result := latestPackagesVersion(c.source)
assert.EqualValues(t, c.expected, result)
})
}
}