sorting in tests
This commit is contained in:
parent
e323fc4e70
commit
fcd11a3bd0
23
main.go
23
main.go
@ -6,7 +6,6 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/bmatcuk/doublestar"
|
|
||||||
"github.com/urfave/cli"
|
"github.com/urfave/cli"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -48,25 +47,3 @@ func scan(c *cli.Context) error {
|
|||||||
// TODO, actually scan, don't just print names
|
// TODO, actually scan, don't just print names
|
||||||
return nil
|
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
|
|
||||||
}
|
|
||||||
|
12
main_test.go
12
main_test.go
@ -1,6 +1,7 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"sort"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"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",
|
"test/fixtures/a/b/c/d/e/f/g/requirements.txt",
|
||||||
}
|
}
|
||||||
got := getManifestGlobMatches("test/**/requirements.txt")
|
got := getManifestGlobMatches("test/**/requirements.txt")
|
||||||
|
sort.Strings(expected)
|
||||||
|
sort.Strings(got)
|
||||||
|
|
||||||
assert.Equal(t, expected, got, "they should be equal")
|
assert.Equal(t, expected, got, "they should be equal")
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestGetAllManifests(t *testing.T) {
|
func TestGetAllManifests(t *testing.T) {
|
||||||
all := []string{
|
expected := []string{
|
||||||
"test/fixtures/yarn.lock",
|
"test/fixtures/yarn.lock",
|
||||||
"test/fixtures/Gemfile",
|
"test/fixtures/Gemfile",
|
||||||
"test/fixtures/subdir/requirements.txt",
|
|
||||||
"test/fixtures/a/b/c/d/e/f/g/requirements.txt",
|
"test/fixtures/a/b/c/d/e/f/g/requirements.txt",
|
||||||
|
"test/fixtures/subdir/requirements.txt",
|
||||||
}
|
}
|
||||||
got := getAllManifests("test/")
|
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")
|
||||||
|
|
||||||
}
|
}
|
||||||
|
29
manifests.go
29
manifests.go
@ -1,5 +1,12 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"log"
|
||||||
|
|
||||||
|
"github.com/bmatcuk/doublestar"
|
||||||
|
)
|
||||||
|
|
||||||
/*
|
/*
|
||||||
When adding new manifest types, for new package managers
|
When adding new manifest types, for new package managers
|
||||||
add a new entry here.
|
add a new entry here.
|
||||||
@ -104,3 +111,25 @@ func manifestGlobs() []string {
|
|||||||
|
|
||||||
return globs
|
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
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user