cleanup function names
This commit is contained in:
parent
b368a97995
commit
8684aedbc2
2
main.go
2
main.go
@ -43,7 +43,7 @@ func main() {
|
|||||||
func scan(c *cli.Context) error {
|
func scan(c *cli.Context) error {
|
||||||
directory := c.Args().First()
|
directory := c.Args().First()
|
||||||
|
|
||||||
fmt.Println(strings.Join(getAllManifests(directory), ", "))
|
fmt.Println(strings.Join(getListOfManifestFilenames(directory), ", "))
|
||||||
// TODO, actually scan, don't just print names
|
// TODO, actually scan, don't just print names
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -10,7 +10,6 @@ import (
|
|||||||
/*
|
/*
|
||||||
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.
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
func manifestGlobs() []string {
|
func manifestGlobs() []string {
|
||||||
@ -112,12 +111,12 @@ func manifestGlobs() []string {
|
|||||||
return globs
|
return globs
|
||||||
}
|
}
|
||||||
|
|
||||||
func getAllManifests(directory string) []string {
|
func getListOfManifestFilenames(directory string) []string {
|
||||||
matchingFiles := make([]string, 0)
|
matchingFiles := make([]string, 0)
|
||||||
|
|
||||||
for _, glob := range manifestGlobs() {
|
for _, glob := range manifestGlobs() {
|
||||||
pathGlob := fmt.Sprintf("%s/**/%s", directory, glob)
|
pathGlob := fmt.Sprintf("%s/**/%s", directory, glob)
|
||||||
files := getManifestGlobMatches(pathGlob)
|
files := getListOfGlobMatches(pathGlob)
|
||||||
|
|
||||||
if len(files) > 0 {
|
if len(files) > 0 {
|
||||||
matchingFiles = append(matchingFiles, files...)
|
matchingFiles = append(matchingFiles, files...)
|
||||||
@ -126,7 +125,7 @@ func getAllManifests(directory string) []string {
|
|||||||
return matchingFiles
|
return matchingFiles
|
||||||
}
|
}
|
||||||
|
|
||||||
func getManifestGlobMatches(glob string) []string {
|
func getListOfGlobMatches(glob string) []string {
|
||||||
files, err := doublestar.Glob(glob)
|
files, err := doublestar.Glob(glob)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
|
@ -7,31 +7,30 @@ import (
|
|||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestGetManifestGlobMatches(t *testing.T) {
|
func TestGetListOfGlobMatches(t *testing.T) {
|
||||||
//assert getManifestMatches gets all requirements.txt
|
//assert getManifestMatches gets all requirements.txt
|
||||||
expected := []string{
|
expected := []string{
|
||||||
"test/fixtures/subdir/requirements.txt",
|
"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",
|
||||||
}
|
}
|
||||||
got := getManifestGlobMatches("test/**/requirements.txt")
|
got := getListOfGlobMatches("test/**/requirements.txt")
|
||||||
sort.Strings(expected)
|
sort.Strings(expected)
|
||||||
sort.Strings(got)
|
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 TestGetListOfManifestFilenames(t *testing.T) {
|
||||||
expected := []string{
|
expected := []string{
|
||||||
"test/fixtures/yarn.lock",
|
"test/fixtures/yarn.lock",
|
||||||
"test/fixtures/Gemfile",
|
"test/fixtures/Gemfile",
|
||||||
"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",
|
"test/fixtures/subdir/requirements.txt",
|
||||||
}
|
}
|
||||||
got := getAllManifests("test/")
|
got := getListOfManifestFilenames("test/")
|
||||||
|
|
||||||
sort.Strings(expected)
|
sort.Strings(expected)
|
||||||
sort.Strings(got)
|
sort.Strings(got)
|
||||||
|
|
||||||
assert.Equal(t, expected, got, "they should match")
|
assert.Equal(t, expected, got, "they should match")
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user