Skip to content

Commit

Permalink
test(proxy): re-define access to repo root (#96)
Browse files Browse the repository at this point in the history
  • Loading branch information
plastikfan committed Jan 4, 2024
1 parent 3466683 commit 6a03e5a
Show file tree
Hide file tree
Showing 9 changed files with 21 additions and 17 deletions.
1 change: 1 addition & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
"structcheck",
"stylecheck",
"thelper",
"toplevel",
"tparallel",
"typecheck",
"unconvert",
Expand Down
4 changes: 1 addition & 3 deletions src/app/command/bootstrap_test.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package command_test

import (
"path/filepath"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"github.com/snivilised/cobrass/src/assistant/configuration"
Expand Down Expand Up @@ -55,7 +53,7 @@ var _ = Describe("Bootstrap", Ordered, func() {
)

BeforeAll(func() {
repo = helpers.Repo(filepath.Join("..", "..", ".."))
repo = helpers.Repo("")
l10nPath = helpers.Path(repo, "test/data/l10n")
configPath = helpers.Path(repo, "test/data/configuration")
})
Expand Down
4 changes: 1 addition & 3 deletions src/app/command/magick-cmd_test.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package command_test

import (
"path/filepath"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"go.uber.org/mock/gomock"
Expand Down Expand Up @@ -33,7 +31,7 @@ var _ = Describe("MagickCmd", Ordered, func() {

BeforeAll(func() {
vfs = storage.UseNativeFS()
repo = helpers.Repo(filepath.Join("..", "..", ".."))
repo = helpers.Repo("")
l10nPath = helpers.Path(repo, "test/data/l10n")
configPath = helpers.Path(repo, "test/data/configuration")
})
Expand Down
3 changes: 1 addition & 2 deletions src/app/command/root-cmd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package command_test

import (
"fmt"
"path/filepath"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
Expand All @@ -28,7 +27,7 @@ var _ = Describe("RootCmd", Ordered, func() {
)

BeforeAll(func() {
repo = helpers.Repo(filepath.Join("..", "..", ".."))
repo = helpers.Repo("")
l10nPath = helpers.Path(repo, "test/data/l10n")
configPath = helpers.Path(repo, "test/data/configuration")
})
Expand Down
3 changes: 1 addition & 2 deletions src/app/command/shrink-cmd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package command_test

import (
"fmt"
"path/filepath"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
Expand Down Expand Up @@ -117,7 +116,7 @@ var _ = Describe("ShrinkCmd", Ordered, func() {
)

BeforeAll(func() {
repo = helpers.Repo(filepath.Join("..", "..", ".."))
repo = helpers.Repo("")
l10nPath = helpers.Path(repo, "test/data/l10n")
configPath = helpers.Path(repo, "test/data/configuration")
})
Expand Down
4 changes: 2 additions & 2 deletions src/app/proxy/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func expectValidShrinkCmdInvocation(vfs storage.VirtualFS, entry *configTE,
"--profile", entry.profile,
}

repo := helpers.Repo(filepath.Join("..", "..", ".."))
repo := helpers.Repo("")
configPath := filepath.Join(repo, "test", "data", "configuration")
tester := helpers.CommandTester{
Args: append(options, entry.args...),
Expand Down Expand Up @@ -95,7 +95,7 @@ var _ = Describe("Config", Ordered, func() {
)

BeforeAll(func() {
repo = helpers.Repo(filepath.Join("..", "..", ".."))
repo = helpers.Repo("")
l10nPath = helpers.Path(repo, "test/data/l10n")
configPath = helpers.Path(repo, "test/data/configuration")
})
Expand Down
2 changes: 1 addition & 1 deletion src/app/proxy/controller-sampler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ var _ = Describe("SamplerController", Ordered, func() {
)

BeforeAll(func() {
repo = helpers.Repo(filepath.Join("..", "..", ".."))
repo = helpers.Repo("")
l10nPath = helpers.Path(repo, "test/data/l10n")
configPath = helpers.Path(repo, "test/data/configuration")
})
Expand Down
2 changes: 1 addition & 1 deletion src/internal/helpers/directory-tree-builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ type File struct {
const doWrite = true

func Scientist(vfs storage.VirtualFS, index string, silent bool) string {
repo := Repo(filepath.Join("..", "..", ".."))
repo := Repo("")
research := filepath.Join(repo, "test", "data", "research")
scientist := filepath.Join(research, "scientist")
indexPath := filepath.Join(research, index)
Expand Down
15 changes: 12 additions & 3 deletions src/internal/helpers/test-utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package helpers
import (
"fmt"
"os"
"os/exec"
"path/filepath"
"runtime"
"strings"

"github.com/onsi/ginkgo/v2"
Expand Down Expand Up @@ -71,8 +71,17 @@ func Root() string {
}

func Repo(relative string) string {
_, filename, _, _ := runtime.Caller(0) //nolint:dogsled // use of 3 _ is out of our control
return Path(filepath.Dir(filename), relative)
cmd := exec.Command("git", "rev-parse", "--show-toplevel")
if bytes, err := cmd.Output(); err != nil {
panic(errors.Wrap(err, "couldn't get repo root"))
} else {
segments := strings.Split(relative, "/")
output := strings.TrimSuffix(string(bytes), "\n")
path := []string{output}
path = append(path, segments...)

return filepath.Join(path...)
}
}

func Log() string {
Expand Down

0 comments on commit 6a03e5a

Please sign in to comment.