Skip to content

Commit

Permalink
Introduce PathBuilder
Browse files Browse the repository at this point in the history
  • Loading branch information
kkrull committed Aug 29, 2024
1 parent 6e866a9 commit 33cb7bb
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 8 deletions.
6 changes: 6 additions & 0 deletions src/go/testsupportfs/dir_fixture.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ type dirFixtureState interface {
BasePath() (string, error)
Create() (dirFixtureState, error)
Destroy() (dirFixtureState, error)
PathBuilder() (*PathBuilder, error)
}

/* Use */
Expand All @@ -40,3 +41,8 @@ type dirFixtureState interface {
func (fixture *DirFixture) BasePath() (string, error) {
return fixture.state.BasePath()
}

// Get something to build paths inside of the test directory, provided it has been created.
func (fixture *DirFixture) PathBuilder() (*PathBuilder, error) {
return fixture.state.PathBuilder()
}
4 changes: 4 additions & 0 deletions src/go/testsupportfs/dir_fixture_down.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,7 @@ func (down *dirFixtureDown) Create() (dirFixtureState, error) {
func (down *dirFixtureDown) Destroy() (dirFixtureState, error) {
return down, nil
}

func (down *dirFixtureDown) PathBuilder() (*PathBuilder, error) {
return nil, fmt.Errorf("test directory starting with <%s> not created yet", down.prefix)
}
4 changes: 4 additions & 0 deletions src/go/testsupportfs/dir_fixture_up.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,7 @@ func (up *dirFixtureUp) Destroy() (dirFixtureState, error) {

return &dirFixtureDown{prefix: up.createdWithPrefix}, nil
}

func (up *dirFixtureUp) PathBuilder() (*PathBuilder, error) {
return &PathBuilder{basePath: up.dirPath}, nil
}
10 changes: 10 additions & 0 deletions src/go/testsupportfs/path_builder.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package testsupportfs

// Builds paths with certain properties inside of an existing base directory.
type PathBuilder struct {
basePath string
}

func (builder *PathBuilder) AsAbsolute() string {
return builder.basePath
}
26 changes: 18 additions & 8 deletions src/go/userepository/register_local_repositories_command_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,17 @@ import (

var _ = Describe("RegisterLocalRepositoriesCommand", func() {
var (
dirFixture *testsupportfs.DirFixture
source *mock.RepositorySource
subject *userepository.RegisterLocalRepositoriesCommand
subject *userepository.RegisterLocalRepositoriesCommand
runV = func(paths ...string) error {
return subject.Run(paths)
}
)

var source *mock.RepositorySource

var (
dirFixture *testsupportfs.DirFixture
pathBuilder *testsupportfs.PathBuilder
)

var validPaths = func() []string {
Expand All @@ -28,18 +36,20 @@ var _ = Describe("RegisterLocalRepositoriesCommand", func() {
dirFixture = testsupportfs.NewDirFixture("RegisterLocalRepositoriesCommand")
Expect(dirFixture.Setup()).To(Succeed())
DeferCleanup(dirFixture.Teardown)
pathBuilder = expect.NoError(dirFixture.PathBuilder())

source = mock.NewRepositorySource()
factory := use.NewCommandFactory().WithRepositorySource(source)
subject = expect.NoError(factory.NewRegisterLocalRepositories())
})

Describe("#Run", func() {
It("accepts absolute and relative paths", func() {
Expect(subject.Run([]string{
"/home/me/absolute",
"../git/relative",
})).To(Succeed())
It("accepts absolute paths", func() {
Expect(runV(pathBuilder.AsAbsolute())).To(Succeed())
})

It("accepts relative paths", func() {
Expect(subject.Run([]string{"../git/relative"})).To(Succeed())
})

It("adds local repositories to the source, for the given paths", func() {
Expand Down

0 comments on commit 33cb7bb

Please # to comment.