-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathecosystems_test.go
More file actions
58 lines (42 loc) · 1.16 KB
/
ecosystems_test.go
File metadata and controls
58 lines (42 loc) · 1.16 KB
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
package lockfile_test
import (
"os"
"strings"
"testing"
"github.com/g-rath/osv-detector/pkg/lockfile"
)
func numberOfLockfileParsers(t *testing.T) int {
t.Helper()
directories, err := os.ReadDir(".")
if err != nil {
t.Fatalf("unable to read current directory: ")
}
count := 0
for _, directory := range directories {
if strings.HasPrefix(directory.Name(), "parse-") &&
!strings.HasSuffix(directory.Name(), "_test.go") {
count++
}
}
return count
}
func TestKnownEcosystems(t *testing.T) {
t.Parallel()
expectedCount := numberOfLockfileParsers(t)
// - npm, yarn, bun, and pnpm,
// - pip, poetry, uv, pdm and pipenv,
// - maven and gradle,
// all use the same ecosystem so "ignore" those parsers in the count
expectedCount -= 8
ecosystems := lockfile.KnownEcosystems()
if knownCount := len(ecosystems); knownCount != expectedCount {
t.Errorf("Expected to know about %d ecosystems, but knew about %d", expectedCount, knownCount)
}
uniq := make(map[lockfile.Ecosystem]int)
for _, ecosystem := range ecosystems {
uniq[ecosystem]++
if uniq[ecosystem] > 1 {
t.Errorf(`Ecosystem "%s" was listed more than once`, ecosystem)
}
}
}