diff --git a/.vscode/settings.json b/.vscode/settings.json index e3b8e85..7fc0423 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -68,6 +68,7 @@ "structcheck", "stylecheck", "thelper", + "toplevel", "tparallel", "typecheck", "unconvert", diff --git a/src/app/command/bootstrap_test.go b/src/app/command/bootstrap_test.go index b0d5f6e..360c5bb 100644 --- a/src/app/command/bootstrap_test.go +++ b/src/app/command/bootstrap_test.go @@ -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" @@ -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") }) diff --git a/src/app/command/magick-cmd_test.go b/src/app/command/magick-cmd_test.go index 3b06d8e..4f1abe6 100644 --- a/src/app/command/magick-cmd_test.go +++ b/src/app/command/magick-cmd_test.go @@ -1,8 +1,6 @@ package command_test import ( - "path/filepath" - . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" "go.uber.org/mock/gomock" @@ -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") }) diff --git a/src/app/command/root-cmd_test.go b/src/app/command/root-cmd_test.go index 9996539..d0b3edc 100644 --- a/src/app/command/root-cmd_test.go +++ b/src/app/command/root-cmd_test.go @@ -2,7 +2,6 @@ package command_test import ( "fmt" - "path/filepath" . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" @@ -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") }) diff --git a/src/app/command/shrink-cmd_test.go b/src/app/command/shrink-cmd_test.go index 7396e39..218f7c9 100644 --- a/src/app/command/shrink-cmd_test.go +++ b/src/app/command/shrink-cmd_test.go @@ -2,7 +2,6 @@ package command_test import ( "fmt" - "path/filepath" . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" @@ -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") }) diff --git a/src/app/proxy/config_test.go b/src/app/proxy/config_test.go index 45e1a8c..b2b27c4 100644 --- a/src/app/proxy/config_test.go +++ b/src/app/proxy/config_test.go @@ -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...), @@ -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") }) diff --git a/src/app/proxy/controller-sampler_test.go b/src/app/proxy/controller-sampler_test.go index 9158608..1849bc2 100644 --- a/src/app/proxy/controller-sampler_test.go +++ b/src/app/proxy/controller-sampler_test.go @@ -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") }) diff --git a/src/internal/helpers/directory-tree-builder.go b/src/internal/helpers/directory-tree-builder.go index ef8b54b..b0a3a0c 100644 --- a/src/internal/helpers/directory-tree-builder.go +++ b/src/internal/helpers/directory-tree-builder.go @@ -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) diff --git a/src/internal/helpers/test-utils.go b/src/internal/helpers/test-utils.go index 530ef46..5762b6b 100644 --- a/src/internal/helpers/test-utils.go +++ b/src/internal/helpers/test-utils.go @@ -3,6 +3,7 @@ package helpers import ( "fmt" "os" + "os/exec" "path/filepath" "runtime" "strings" @@ -71,7 +72,18 @@ func Root() string { } func Repo(relative string) string { + cmd := exec.Command("git", "rev-parse", "--show-toplevel") + if bytes, err := cmd.Output(); err == nil { + segments := strings.Split(relative, "/") + output := strings.TrimSuffix(string(bytes), "\n") + path := []string{output} + path = append(path, segments...) + + return filepath.Join(path...) + } + _, filename, _, _ := runtime.Caller(0) //nolint:dogsled // use of 3 _ is out of our control + return Path(filepath.Dir(filename), relative) }