diff --git a/main.go b/main.go index 1d3f33b..5e4a5b8 100644 --- a/main.go +++ b/main.go @@ -6,7 +6,6 @@ import ( "os" "strings" - "github.com/bmatcuk/doublestar" "github.com/urfave/cli" ) @@ -48,25 +47,3 @@ func scan(c *cli.Context) error { // TODO, actually scan, don't just print names return nil } - -func getAllManifests(directory string) []string { - matchingFiles := make([]string, 0) - - for _, glob := range manifestGlobs() { - pathGlob := fmt.Sprintf("%s/**/%s", directory, glob) - files := getManifestGlobMatches(pathGlob) - - if len(files) > 0 { - matchingFiles = append(matchingFiles, files...) - } - } - return matchingFiles -} - -func getManifestGlobMatches(glob string) []string { - files, err := doublestar.Glob(glob) - if err != nil { - log.Fatal(err) - } - return files -} diff --git a/main_test.go b/main_test.go index 5e4e008..6e826b0 100644 --- a/main_test.go +++ b/main_test.go @@ -1,6 +1,7 @@ package main import ( + "sort" "testing" "github.com/stretchr/testify/assert" @@ -13,19 +14,24 @@ func TestGetManifestGlobMatches(t *testing.T) { "test/fixtures/a/b/c/d/e/f/g/requirements.txt", } got := getManifestGlobMatches("test/**/requirements.txt") + sort.Strings(expected) + sort.Strings(got) assert.Equal(t, expected, got, "they should be equal") } func TestGetAllManifests(t *testing.T) { - all := []string{ + expected := []string{ "test/fixtures/yarn.lock", "test/fixtures/Gemfile", - "test/fixtures/subdir/requirements.txt", "test/fixtures/a/b/c/d/e/f/g/requirements.txt", + "test/fixtures/subdir/requirements.txt", } got := getAllManifests("test/") - assert.Equal(t, all, got, "they should match") + sort.Strings(expected) + sort.Strings(got) + + assert.Equal(t, expected, got, "they should match") } diff --git a/manifests.go b/manifests.go index 929e62b..43ac30a 100644 --- a/manifests.go +++ b/manifests.go @@ -1,5 +1,12 @@ package main +import ( + "fmt" + "log" + + "github.com/bmatcuk/doublestar" +) + /* When adding new manifest types, for new package managers add a new entry here. @@ -104,3 +111,25 @@ func manifestGlobs() []string { return globs } + +func getAllManifests(directory string) []string { + matchingFiles := make([]string, 0) + + for _, glob := range manifestGlobs() { + pathGlob := fmt.Sprintf("%s/**/%s", directory, glob) + files := getManifestGlobMatches(pathGlob) + + if len(files) > 0 { + matchingFiles = append(matchingFiles, files...) + } + } + return matchingFiles +} + +func getManifestGlobMatches(glob string) []string { + files, err := doublestar.Glob(glob) + if err != nil { + log.Fatal(err) + } + return files +}