From 104aa44ef58df5ccfeb2e862ac21c3827c5305ee Mon Sep 17 00:00:00 2001 From: Tyrel Souza Date: Tue, 14 May 2019 22:09:14 -0400 Subject: [PATCH] chdir --- main.go | 5 +++++ manifests.go | 4 +++- manifests_test.go | 18 ++++++++++-------- 3 files changed, 18 insertions(+), 9 deletions(-) diff --git a/main.go b/main.go index 1d25500..a050be0 100644 --- a/main.go +++ b/main.go @@ -9,6 +9,11 @@ import ( "github.com/urfave/cli" ) +/* + + scan,s [directory-with-.tidelift.yml] + configure,c [directory-with-.tidelift.yml] +*/ func main() { app := cli.NewApp() diff --git a/manifests.go b/manifests.go index 761fd07..60da3b9 100644 --- a/manifests.go +++ b/manifests.go @@ -3,6 +3,7 @@ package main import ( "fmt" "log" + "os" "github.com/bmatcuk/doublestar" ) @@ -112,10 +113,11 @@ func manifestGlobs() []string { } func getListOfManifestFilenames(directory string) []string { + os.Chdir(directory) matchingFiles := make([]string, 0) for _, glob := range manifestGlobs() { - pathGlob := fmt.Sprintf("%s/**/%s", directory, glob) + pathGlob := fmt.Sprintf("**/%s", glob) files := getListOfGlobMatches(pathGlob) if len(files) > 0 { diff --git a/manifests_test.go b/manifests_test.go index c9e82af..597aac0 100644 --- a/manifests_test.go +++ b/manifests_test.go @@ -1,6 +1,7 @@ package main import ( + "os" "sort" "testing" @@ -9,11 +10,12 @@ import ( func TestGetListOfGlobMatches(t *testing.T) { //assert getManifestMatches gets all requirements.txt + os.Chdir("test/fixtures") expected := []string{ - "test/fixtures/subdir/requirements.txt", - "test/fixtures/a/b/c/d/e/f/g/requirements.txt", + "subdir/requirements.txt", + "a/b/c/d/e/f/g/requirements.txt", } - got := getListOfGlobMatches("test/**/requirements.txt") + got := getListOfGlobMatches("**/requirements.txt") sort.Strings(expected) sort.Strings(got) @@ -22,12 +24,12 @@ func TestGetListOfGlobMatches(t *testing.T) { func TestGetListOfManifestFilenames(t *testing.T) { expected := []string{ - "test/fixtures/yarn.lock", - "test/fixtures/Gemfile", - "test/fixtures/a/b/c/d/e/f/g/requirements.txt", - "test/fixtures/subdir/requirements.txt", + "yarn.lock", + "Gemfile", + "a/b/c/d/e/f/g/requirements.txt", + "subdir/requirements.txt", } - got := getListOfManifestFilenames("test/") + got := getListOfManifestFilenames("test/fixtures") sort.Strings(expected) sort.Strings(got)