/
versions_test.go
59 lines (49 loc) · 1.08 KB
/
versions_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
package releases
import (
"context"
"testing"
"github.com/google/go-cmp/cmp"
"github.com/hashicorp/go-version"
"github.com/hashicorp/hc-install/internal/testutil"
"github.com/hashicorp/hc-install/product"
"github.com/hashicorp/hc-install/src"
)
func TestVersions_List(t *testing.T) {
testutil.EndToEndTest(t)
cons, err := version.NewConstraint(">= 1.0.0, < 1.0.10")
if err != nil {
t.Fatal(err)
}
versions := &Versions{
Product: product.Terraform,
Constraints: cons,
}
ctx := context.Background()
sources, err := versions.List(ctx)
if err != nil {
t.Fatal(err)
}
expectedVersions := []string{
"1.0.0",
"1.0.1",
"1.0.2",
"1.0.3",
"1.0.4",
"1.0.5",
"1.0.6",
"1.0.7",
"1.0.8",
"1.0.9",
}
if diff := cmp.Diff(expectedVersions, sourcesToRawVersions(sources)); diff != "" {
t.Fatalf("unexpected versions: %s", diff)
}
}
func sourcesToRawVersions(srcs []src.Source) []string {
rawVersions := make([]string, len(srcs))
for idx, src := range srcs {
source := src.(*ExactVersion)
rawVersions[idx] = source.Version.String()
}
return rawVersions
}