Commit ffebf0b6 authored by Boris Mühmer's avatar Boris Mühmer
Browse files

corrected gdp.Walk() to return a stream of .git pathes

parent fe9522d1
Loading
Loading
Loading
Loading
+20 −18
Original line number Diff line number Diff line
@@ -18,11 +18,13 @@ func NewGitDirectoryPath(rootPath string) *GitDirectoryPath {
}

// Walk ...
func (g *GitDirectoryPath) Walk(done <-chan bool) (chan<- string, error) {
func (g *GitDirectoryPath) Walk() <-chan string {
	pathStream := make(chan string)

	go func() {
		defer close(pathStream)

	if err := filepath.Walk(g.rootPath,
		filepath.Walk(g.rootPath,
			func(path string, info os.FileInfo, err error) error {
				if err != nil {
					return err
@@ -35,10 +37,10 @@ func (g *GitDirectoryPath) Walk(done <-chan bool) (chan<- string, error) {
				}
				pathStream <- path
				return nil
		}); err != nil {
		return nil, err
	}
	return pathStream, nil
			})
	}()

	return pathStream
}

// GitDirectory returns all .git directories below a given rootPath.
+22 −4
Original line number Diff line number Diff line
@@ -8,17 +8,23 @@ import (
	"testing"
)

func TestJugglerSearchProjects(t *testing.T) {

func dirPath() (string, error) {
	//basePath := "/home/MUEHMER/bsmr/repositories"
	basePath := "repositories"

	usr, err := user.Current()
	if err != nil {
		t.Fatalf("user.Current() failed: %s", err)
		return "", err
	}

	return path.Join(usr.HomeDir, basePath), nil
}

	dirPath := path.Join(usr.HomeDir, basePath)
func TestJugglerSearchProjectsNormal(t *testing.T) {
	dirPath, err := dirPath()
	if err != nil {
		t.Fatalf("dirPath() failed: %s", err)
	}

	err = filepath.Walk(dirPath,
		func(path string, info os.FileInfo, err error) error {
@@ -39,6 +45,18 @@ func TestJugglerSearchProjects(t *testing.T) {
	}
}

func TestJugglerSearchProjectsStream(t *testing.T) {
	dirPath, err := dirPath()
	if err != nil {
		t.Fatalf("dirPath() failed: %s", err)
	}

	gdp := NewGitDirectoryPath(dirPath)
	for path := range gdp.Walk() {
		t.Logf("path: %s", path)
	}
}

func TestJugglerProcessProjectsSequential(t *testing.T) {

}