Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitaly.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJames Fargher <jfargher@gitlab.com>2023-03-15 01:01:08 +0300
committerJames Fargher <jfargher@gitlab.com>2023-03-16 23:47:38 +0300
commit73f73641310ba0c2a6cb7b77339b4dae53be061c (patch)
treea9dd31cf00304c0c8d687105b73b584c111bca68
parent8efccb9a5325525196ae8adad08f1d5eb29dc403 (diff)
testhelper: Add a helper to determine gitaly package paths
We use hard coded package paths variously and these paths would otherwise have to be manually updated when the gitaly major version is updated. So instead we use reflection to determine what the current package path is.
-rw-r--r--internal/testhelper/leakage.go4
-rw-r--r--internal/testhelper/testcfg/binaries.go4
-rw-r--r--internal/testhelper/testhelper.go13
3 files changed, 17 insertions, 4 deletions
diff --git a/internal/testhelper/leakage.go b/internal/testhelper/leakage.go
index 5dc9cae20..e27022217 100644
--- a/internal/testhelper/leakage.go
+++ b/internal/testhelper/leakage.go
@@ -29,13 +29,13 @@ func mustHaveNoGoroutines() {
// eventually, but the pragmatic approach is to just wait until we remove
// the Ruby sidecar altogether.
goleak.IgnoreTopFunction("google.golang.org/grpc.(*ccBalancerWrapper).watcher"),
- goleak.IgnoreTopFunction("gitlab.com/gitlab-org/gitaly/v15/internal/gitaly/rubyserver/balancer.(*builder).monitor"),
+ goleak.IgnoreTopFunction(PkgPath("internal/gitaly/rubyserver/balancer.(*builder).monitor")),
// labkit's logger spawns a Goroutine which cannot be closed when calling
// `Initialize()`.
goleak.IgnoreTopFunction("gitlab.com/gitlab-org/labkit/log.listenForSignalHangup"),
// The backchannel code is somehow stock on closing its connections. I have no clue
// why that is, but we should investigate.
- goleak.IgnoreTopFunction("gitlab.com/gitlab-org/gitaly/v15/internal/backchannel.clientHandshake.serve.func4"),
+ goleak.IgnoreTopFunction(PkgPath("internal/backchannel.clientHandshake.serve.func4")),
); err != nil {
panic(fmt.Errorf("goroutines running: %w", err))
}
diff --git a/internal/testhelper/testcfg/binaries.go b/internal/testhelper/testcfg/binaries.go
index 001860586..c9f4a360b 100644
--- a/internal/testhelper/testcfg/binaries.go
+++ b/internal/testhelper/testcfg/binaries.go
@@ -113,7 +113,7 @@ func BuildBinary(tb testing.TB, targetDir, sourcePath string) string {
"build",
"-buildvcs=false",
"-tags", strings.Join(buildTags, ","),
- "-ldflags", fmt.Sprintf("-X gitlab.com/gitlab-org/gitaly/v15/internal/version.version=%s", version.GetVersion()),
+ "-ldflags", fmt.Sprintf("-X %s/version.version=%s", testhelper.PkgPath("internal"), version.GetVersion()),
"-o", sharedBinaryPath,
sourcePath,
)
@@ -139,5 +139,5 @@ func BuildBinary(tb testing.TB, targetDir, sourcePath string) string {
}
func gitalyCommandPath(command string) string {
- return fmt.Sprintf("gitlab.com/gitlab-org/gitaly/v15/cmd/%s", command)
+ return fmt.Sprintf("%s/cmd/%s", testhelper.PkgPath(), command)
}
diff --git a/internal/testhelper/testhelper.go b/internal/testhelper/testhelper.go
index 9d1ae6094..f35b136b5 100644
--- a/internal/testhelper/testhelper.go
+++ b/internal/testhelper/testhelper.go
@@ -17,7 +17,9 @@ import (
"net/http"
"os"
"os/exec"
+ "path"
"path/filepath"
+ "reflect"
"syscall"
"testing"
"time"
@@ -393,3 +395,14 @@ func SkipQuarantinedTest(t *testing.T, issue string, tests ...string) {
t.Skipf("This test has been quarantined. Please see %s for more information.", issue)
}
}
+
+// pkgPath is used to determine the package path using reflection.
+type pkgPath struct{}
+
+// PkgPath returns the gitaly module package path, including major version
+// number. paths will be path joined to the returned package path.
+func PkgPath(paths ...string) string {
+ internalPkgPath := path.Dir(reflect.TypeOf(pkgPath{}).PkgPath())
+ rootPkgPath := path.Dir(internalPkgPath)
+ return path.Join(append([]string{rootPkgPath}, paths...)...)
+}