-
Notifications
You must be signed in to change notification settings - Fork 1
/
manifest_db_test.go
49 lines (40 loc) · 1.09 KB
/
manifest_db_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
package main
import (
"testing"
"github.com/hashicorp/go-version"
)
func TestManifestDB_Satisfies(t *testing.T) {
oldPkgDir := pkgDir
defer func() {
pkgDir = oldPkgDir
}()
pkgDir = "testdata/manifests/valid-manifests"
d, err := LoadDB()
if err != nil {
t.Fatalf("unexpected error: %+v", err)
}
gte1, _ := version.NewConstraint(">= 1.0.0")
for _, test := range []struct {
name string
pkg string
constraint version.Constraints
expect string
}{
{"simple, versioned package", "sample-app", gte1, "sample-app 1.0.0"},
{"simple app, 'latest' version", "sample-app", latest, "sample-app 1.0.0"},
{"app with only so-called pre-releases", "complex-versions-app", latest, "complex-versions-app 3.2.1-r1"},
} {
t.Run(test.name, func(t *testing.T) {
s, err := d.Satisfies(test.pkg, test.constraint)
if err != nil {
t.Fatalf("unexpected error: %+v", err)
}
if len(s) != 1 {
t.Fatalf("expected 1 satisfying manifest, received %d", len(s))
}
if s[0].ID != test.expect {
t.Errorf("expected %q, received %q", test.expect, s[0].ID)
}
})
}
}