dont change dir, add more tests
This commit is contained in:
parent
efc5a3267f
commit
f3e356f314
14
helpers.go
Normal file
14
helpers.go
Normal file
@ -0,0 +1,14 @@
|
||||
package main
|
||||
|
||||
import "os"
|
||||
|
||||
func tempChdir(directory string) string {
|
||||
wd, _ := os.Getwd()
|
||||
os.Chdir(directory)
|
||||
return wd
|
||||
|
||||
}
|
||||
|
||||
func fixWD(directory string) {
|
||||
os.Chdir(directory)
|
||||
}
|
4
main.go
4
main.go
@ -57,7 +57,9 @@ func main() {
|
||||
func getDirectory(c *cli.Context) string {
|
||||
// Return a directory if it's in the arguments
|
||||
if len(c.Args()) > 0 {
|
||||
return c.Args().First()
|
||||
path := c.Args().First()
|
||||
path = strings.TrimRight(path, "/")
|
||||
return path
|
||||
}
|
||||
return "."
|
||||
}
|
||||
|
@ -3,7 +3,6 @@ package main
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
|
||||
"github.com/bmatcuk/doublestar"
|
||||
)
|
||||
@ -115,11 +114,10 @@ var (
|
||||
//
|
||||
// returns string[] of filenames relative to the directory passed in.
|
||||
func getListOfManifestFilenames(directory string) []string {
|
||||
os.Chdir(directory)
|
||||
matchingFiles := make([]string, 0)
|
||||
|
||||
for _, glob := range manifestGlobs {
|
||||
files := getListOfGlobMatches(glob)
|
||||
files := getListOfGlobMatches(directory, glob)
|
||||
|
||||
if len(files) > 0 {
|
||||
matchingFiles = append(matchingFiles, files...)
|
||||
@ -132,8 +130,8 @@ func getListOfManifestFilenames(directory string) []string {
|
||||
// all instances of a manifest file pattern, in your given directory
|
||||
//
|
||||
// returns string[] of all matching file patterns
|
||||
func getListOfGlobMatches(glob string) []string {
|
||||
pathGlob := fmt.Sprintf("**/%s", glob)
|
||||
func getListOfGlobMatches(directory string, glob string) []string {
|
||||
pathGlob := fmt.Sprintf("%s/**/%s", directory, glob)
|
||||
|
||||
files, err := doublestar.Glob(pathGlob)
|
||||
if err != nil {
|
||||
|
@ -1,7 +1,6 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"os"
|
||||
"sort"
|
||||
"testing"
|
||||
|
||||
@ -10,12 +9,12 @@ import (
|
||||
|
||||
func TestGetListOfGlobMatches(t *testing.T) {
|
||||
//assert getManifestMatches gets all requirements.txt
|
||||
os.Chdir("test/good_config")
|
||||
expected := []string{
|
||||
"subdir/requirements.txt",
|
||||
"a/b/c/d/e/f/g/requirements.txt",
|
||||
"test/good_config/subdir/requirements.txt",
|
||||
"test/good_config/a/b/c/d/e/f/g/requirements.txt",
|
||||
}
|
||||
got := getListOfGlobMatches("**/requirements.txt")
|
||||
got := getListOfGlobMatches("test/good_config", "**/requirements.txt")
|
||||
|
||||
sort.Strings(expected)
|
||||
sort.Strings(got)
|
||||
|
||||
@ -24,10 +23,10 @@ func TestGetListOfGlobMatches(t *testing.T) {
|
||||
|
||||
func TestGetListOfManifestFilenames(t *testing.T) {
|
||||
expected := []string{
|
||||
"yarn.lock",
|
||||
"Gemfile",
|
||||
"a/b/c/d/e/f/g/requirements.txt",
|
||||
"subdir/requirements.txt",
|
||||
"test/good_config/yarn.lock",
|
||||
"test/good_config/Gemfile",
|
||||
"test/good_config/a/b/c/d/e/f/g/requirements.txt",
|
||||
"test/good_config/subdir/requirements.txt",
|
||||
}
|
||||
got := getListOfManifestFilenames("test/good_config")
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
@ -9,8 +10,9 @@ import (
|
||||
)
|
||||
|
||||
func verifyTideliftYamlExists(directory string) bool {
|
||||
os.Chdir(directory)
|
||||
if _, err := os.Stat(".tidelift.yml"); err == nil {
|
||||
filepath := fmt.Sprintf("%s/.tidelift.yml", directory)
|
||||
|
||||
if fileExists(filepath) {
|
||||
return true
|
||||
}
|
||||
|
||||
@ -52,3 +54,13 @@ func check(e error) {
|
||||
panic(e)
|
||||
}
|
||||
}
|
||||
|
||||
func fileExists(filename string) bool {
|
||||
|
||||
info, err := os.Stat(filename)
|
||||
|
||||
if os.IsNotExist(err) {
|
||||
return false
|
||||
}
|
||||
return !info.IsDir()
|
||||
}
|
||||
|
16
tidelift_yml_test.go
Normal file
16
tidelift_yml_test.go
Normal file
@ -0,0 +1,16 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestVerifyTideliftYamlExists(t *testing.T) {
|
||||
verifiedFalse := verifyTideliftYamlExists("test/no_config")
|
||||
assert.False(t, verifiedFalse, "should not be a .tidelift.yml in test/no_config")
|
||||
|
||||
verifiedTrue := verifyTideliftYamlExists("test/bad_config")
|
||||
assert.True(t, verifiedTrue, "should be a .tidelift.yml in test/bad_config")
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user