Isolate user configuration discovery tests by platform
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
# Configuration Discovery Review Findings
|
# Configuration Discovery Review Findings
|
||||||
|
|
||||||
Status: findings 1–2 complete; findings 3–5 remain open.
|
Status: findings 1–3 complete; findings 4–5 remain open.
|
||||||
|
|
||||||
Reviewed commit: `e50fee2`, including the discovery implementation commits after
|
Reviewed commit: `e50fee2`, including the discovery implementation commits after
|
||||||
`424c897`. The review compared the implementation with the
|
`424c897`. The review compared the implementation with the
|
||||||
@@ -101,7 +101,15 @@ still produce no records. Revise the existing nil-primary assertion accordingly.
|
|||||||
|
|
||||||
## 3. Isolate User-Configuration Preset Tests Using The Platform's Go Convention
|
## 3. Isolate User-Configuration Preset Tests Using The Platform's Go Convention
|
||||||
|
|
||||||
Priority: P2. Status: open.
|
Priority: P2. Status: complete.
|
||||||
|
|
||||||
|
**Completed:** the environment-change test selects the environment variable used
|
||||||
|
by Go on Windows, macOS/iOS, Plan 9, or other Unix hosts, and obtains both fixture
|
||||||
|
bases through `os.UserConfigDir`. It remains nonparallel and restores the
|
||||||
|
environment. The redundant relative-XDG failure assumption was removed; existing
|
||||||
|
private-helper tests retain portable failure/short-circuit coverage. Focused
|
||||||
|
tests and `./scripts/check.sh` passed on Linux. The macOS branch was checked
|
||||||
|
against Go's helper implementation; no native macOS gate was added.
|
||||||
|
|
||||||
**Location:** [discovery_load_test.go](../../internal/engine/discovery_load_test.go),
|
**Location:** [discovery_load_test.go](../../internal/engine/discovery_load_test.go),
|
||||||
`TestSearchSourceObservesUserConfigEnvironmentChanges`, lines 231–279.
|
`TestSearchSourceObservesUserConfigEnvironmentChanges`, lines 231–279.
|
||||||
|
|||||||
@@ -326,21 +326,29 @@ func TestSearchSourceObservesFileChangesBetweenLoads(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestSearchSourceObservesUserConfigEnvironmentChanges(t *testing.T) {
|
func TestSearchSourceObservesUserConfigEnvironmentChanges(t *testing.T) {
|
||||||
if runtime.GOOS == "windows" {
|
setBase := func(directory string) string {
|
||||||
t.Setenv("APPDATA", filepath.Join(t.TempDir(), "first"))
|
t.Helper()
|
||||||
} else {
|
switch runtime.GOOS {
|
||||||
t.Setenv("XDG_CONFIG_HOME", filepath.Join(t.TempDir(), "first"))
|
case "windows":
|
||||||
|
t.Setenv("AppData", directory)
|
||||||
|
case "darwin", "ios":
|
||||||
|
t.Setenv("HOME", directory)
|
||||||
|
case "plan9":
|
||||||
|
t.Setenv("home", directory)
|
||||||
|
default:
|
||||||
|
t.Setenv("XDG_CONFIG_HOME", directory)
|
||||||
|
}
|
||||||
|
base, err := os.UserConfigDir()
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
return base
|
||||||
}
|
}
|
||||||
type config struct {
|
type config struct {
|
||||||
Value string `yaml:"value"`
|
Value string `yaml:"value"`
|
||||||
}
|
}
|
||||||
firstBase := os.Getenv("XDG_CONFIG_HOME")
|
firstBase := setBase(filepath.Join(t.TempDir(), "first"))
|
||||||
if runtime.GOOS == "windows" {
|
|
||||||
firstBase = os.Getenv("APPDATA")
|
|
||||||
}
|
|
||||||
first := writeImportFile(t, firstBase, "app/app.yml", "value: first\n")
|
first := writeImportFile(t, firstBase, "app/app.yml", "value: first\n")
|
||||||
secondBase := filepath.Join(t.TempDir(), "second")
|
|
||||||
second := writeImportFile(t, secondBase, "app/app.yml", "value: second\n")
|
|
||||||
source := SearchConfig("app", UserConfigDirectory())
|
source := SearchConfig("app", UserConfigDirectory())
|
||||||
load := func() string {
|
load := func() string {
|
||||||
loaded, err := testLoad[config](source, Options[config]{})
|
loaded, err := testLoad[config](source, Options[config]{})
|
||||||
@@ -352,28 +360,11 @@ func TestSearchSourceObservesUserConfigEnvironmentChanges(t *testing.T) {
|
|||||||
if value := load(); value != "first" {
|
if value := load(); value != "first" {
|
||||||
t.Fatalf("first user-config search value = %q (%s)", value, first)
|
t.Fatalf("first user-config search value = %q (%s)", value, first)
|
||||||
}
|
}
|
||||||
if runtime.GOOS == "windows" {
|
secondBase := setBase(filepath.Join(t.TempDir(), "second"))
|
||||||
t.Setenv("APPDATA", secondBase)
|
second := writeImportFile(t, secondBase, "app/app.yml", "value: second\n")
|
||||||
} else {
|
|
||||||
t.Setenv("XDG_CONFIG_HOME", secondBase)
|
|
||||||
}
|
|
||||||
if value := load(); value != "second" {
|
if value := load(); value != "second" {
|
||||||
t.Fatalf("updated user-config search value = %q (%s)", value, second)
|
t.Fatalf("updated user-config search value = %q (%s)", value, second)
|
||||||
}
|
}
|
||||||
|
|
||||||
// A reached dynamic base failure is terminal, but an earlier match must
|
|
||||||
// prevent the invalid environment value from being resolved at all.
|
|
||||||
direct := writeImportFile(t, t.TempDir(), "direct.yml", "value: direct\n")
|
|
||||||
if runtime.GOOS == "windows" {
|
|
||||||
t.Setenv("APPDATA", "relative")
|
|
||||||
} else {
|
|
||||||
t.Setenv("XDG_CONFIG_HOME", "relative")
|
|
||||||
}
|
|
||||||
early := SearchConfig("app", Searches(Paths(direct), UserConfigDirectory()))
|
|
||||||
loaded, err := testLoad[config](early, Options[config]{})
|
|
||||||
if err != nil || loaded.Config.Value != "direct" {
|
|
||||||
t.Fatalf("early match with unavailable later base = %#v, %v", loaded, err)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestSearchSourceObservesWorkingDirectoryChanges(t *testing.T) {
|
func TestSearchSourceObservesWorkingDirectoryChanges(t *testing.T) {
|
||||||
|
|||||||
Reference in New Issue
Block a user