Skip to content

Commit

Permalink
Use path builder more
Browse files Browse the repository at this point in the history
  • Loading branch information
kkrull committed Aug 29, 2024
1 parent 33cb7bb commit e10dbcb
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions src/go/userepository/register_local_repositories_command_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,11 @@ var _ = Describe("RegisterLocalRepositoriesCommand", func() {
var (
dirFixture *testsupportfs.DirFixture
pathBuilder *testsupportfs.PathBuilder
validPath = func() string {
return pathBuilder.AsAbsolute()
}
)

var validPaths = func() []string {
return []string{"/path/to/repo"}
}

BeforeEach(func() {
dirFixture = testsupportfs.NewDirFixture("RegisterLocalRepositoriesCommand")
Expect(dirFixture.Setup()).To(Succeed())
Expand All @@ -49,31 +48,31 @@ var _ = Describe("RegisterLocalRepositoriesCommand", func() {
})

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

It("adds local repositories to the source, for the given paths", func() {
subject.Run([]string{"/path/to/a", "/path/to/b"})
runV("/path/to/a", "/path/to/b")
source.AddLocalsExpected("/path/to/a", "/path/to/b")
})

It("returns no error, upon success", func() {
Expect(subject.Run(validPaths())).To(Succeed())
Expect(runV(validPath())).To(Succeed())
})

It("returns an error, when adding repositories fails", func() {
source.AddLocalsFails(errors.New("bang!"))
Expect(subject.Run(validPaths())).To(
Expect(runV(validPath())).To(
MatchError(ContainSubstring("failed to add local repositories; bang!")))
})

It("normalizes paths by replacing redundant/repeated parts with shorter equivalents", func() {
subject.Run([]string{"/path/to/a/../b"})
runV("/path/to/a/../b")
source.AddLocalsExpected("/path/to/b")
})

It("resolves relative paths to absolute paths", func() {
subject.Run([]string{"some-name-in-cwd"})
runV("some-name-in-cwd")
Expect(source.AddLocalsReceived()[0]).To(
HaveSuffix(string(os.PathSeparator) + "some-name-in-cwd"))
})
Expand Down

0 comments on commit e10dbcb

Please # to comment.