-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add
--cache-all-databases
flag (#68)
- Loading branch information
Showing
4 changed files
with
89 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package lockfile | ||
|
||
func KnownEcosystems() []Ecosystem { | ||
return []Ecosystem{ | ||
NpmEcosystem, | ||
CargoEcosystem, | ||
BundlerEcosystem, | ||
ComposerEcosystem, | ||
GoEcosystem, | ||
PipEcosystem, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package lockfile_test | ||
|
||
import ( | ||
"io/ioutil" | ||
"osv-detector/internal/lockfile" | ||
"strings" | ||
"testing" | ||
) | ||
|
||
func numberOfLockfileParsers(t *testing.T) int { | ||
t.Helper() | ||
|
||
directories, err := ioutil.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, and pnpm all use the same ecosystem, | ||
// so "ignore" those parsers in the count | ||
expectedCount -= 2 | ||
|
||
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) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters