mirror of
https://gitlab.alpinelinux.org/alpine/aports.git
synced 2025-11-01 08:51:47 +01:00
45 lines
1.6 KiB
Diff
45 lines
1.6 KiB
Diff
From 26fcf56da491433e79e8bbf3436617dd8e07fe8d Mon Sep 17 00:00:00 2001
|
|
From: =?UTF-8?q?S=C3=B6ren=20Tempel?= <soeren+git@soeren-tempel.net>
|
|
Date: Sun, 9 Jun 2024 13:14:05 +0200
|
|
Subject: [PATCH] Determine fixture path using the current working directory
|
|
|
|
Previously, the path was determined using runtime.Caller. However,
|
|
in some cases `runtime.Caller` will not return an absolute file path.
|
|
This, for example, happens when -trimprefix is passed as a compilation
|
|
option which is used by many downstream distributions (e.g. Alpine
|
|
Linux) via GOFLAGS. Thereby causing test failures on such distributions.
|
|
|
|
This commit attempts to workaround that by exploiting the fact that
|
|
go test sets the working directory to the currently tested package
|
|
source. Hence, allowing us to determine the fixture path relative
|
|
to this directory and thereby fixing test failures with -trimprefix.
|
|
---
|
|
internal/util/fixtures/fixtures.go | 10 +++++-----
|
|
1 file changed, 5 insertions(+), 5 deletions(-)
|
|
|
|
diff --git a/internal/util/fixtures/fixtures.go b/internal/util/fixtures/fixtures.go
|
|
index 61d6eba..b6a0011 100644
|
|
--- a/internal/util/fixtures/fixtures.go
|
|
+++ b/internal/util/fixtures/fixtures.go
|
|
@@ -1,15 +1,15 @@
|
|
package fixtures
|
|
|
|
import (
|
|
+ "os"
|
|
"path/filepath"
|
|
- "runtime"
|
|
)
|
|
|
|
// Path returns the absolute path to the given fixture.
|
|
func Path(name string) string {
|
|
- _, callerPath, _, ok := runtime.Caller(1)
|
|
- if !ok {
|
|
- panic("failed to get the caller's path")
|
|
+ cwd, err := os.Getwd()
|
|
+ if err != nil {
|
|
+ panic("failed to obtain current working directory")
|
|
}
|
|
- return filepath.Join(filepath.Dir(callerPath), "testdata", name)
|
|
+ return filepath.Join(cwd, "testdata", name)
|
|
}
|