feat(smx509): add declarative test patch system

- Add scripts/smx509/gen_test_patches.go: generates test patches from
  Go stdlib test files (with package rename) vs smx509/ test files
- Add scripts/smx509/test-patches/:
  - 010-testenv-stub.patch: new file internal_testenv.go (stdlib testenv stub)
  - 020-envvars-abs-path.patch: fix TestEnvVars SSL_CERT_FILE absolute paths
- Extend sync.ps1 with test file sync:
  - -TestOnly switch for test-only sync mode
  - Auto-detect and copy *_test.go from stdlib
  - Copy testdata/ directory
  - Rename package x509 -> smx509 in test files
  - Apply test-patches/ after sync
- Update smx509-upgrade Skill with test patch workflow
This commit is contained in:
Sun Yimin committed 2026-06-25 12:02:17 +08:00
1 parent 19c804150f
commit 4d57743ec9
6 files changed
+457 -59

No files matched your search

+37 -19
View File
@@ -41,9 +41,10 @@ scripts/smx509/
│ ├── 020-pkcs-keys.patch
│ ├── 030-sm4-pem.patch
│ └── 100-extensions.patch
└── test-patches/ # Test file patches (future)
├── 001-package-rename.patch
└── ...
├── test-patches/ # Declarative test patches (2 files)
│ ├── 010-testenv-stub.patch
│ └── 020-envvars-abs-path.patch
└── gen_test_patches.go # Regenerates test patches from stdlib↔smx509 diff
```
**Patch numbering convention:**
@@ -153,24 +154,35 @@ When resolving conflicts, these MUST be preserved:
### Step 6: Sync Test Files
Test files are maintained independently from source patches. On Go upgrade:
Test files are synced automatically by `sync.ps1` (test file sync section). The script:
1. Copies `*_test.go` from stdlib `crypto/x509/` to `smx509/`
2. Copies `testdata/` from stdlib to `smx509/testdata/`
3. Renames `package x509` → `package smx509` in all test files
4. Applies declarative test patches from `scripts/smx509/test-patches/`
1. **Copy new stdlib test files:**
```bash
cp $GOROOT/src/crypto/x509/*_test.go smx509/
cp -r $GOROOT/src/crypto/x509/testdata/ smx509/testdata/
```
```bash
# Test-only sync (source files unchanged):
pwsh scripts/smx509/sync.ps1 -TestOnly
2. **Apply test patches** (from `scripts/smx509-test-patches/`):
```bash
pwsh scripts/smx509/sync.ps1 -TargetDir smx509 -PackageName smx509 -TestOnly
# Or manually apply test patches
```
# Full sync (source + test):
pwsh scripts/smx509/sync.ps1
```
3. **Verify custom test fixes are preserved:**
- `root_unix_test.go`: TestEnvVars uses absolute paths for SSL_CERT_FILE
- `internal_testenv.go`: stub for `internal/testenv` replacement
- Package name: all `*_test.go` must have `package smx509` (not `package x509`)
**Current test patches:**
- `010-testenv-stub.patch`: new file `internal_testenv.go` (stub for `internal/testenv`)
- `020-envvars-abs-path.patch`: fixes TestEnvVars `SSL_CERT_FILE` to use absolute paths
After sync, verify custom test fixes are preserved:
- `root_unix_test.go`: TestEnvVars uses `filepath.Join(tmpDir, testFile)` for SSL_CERT_FILE
- `internal_testenv.go`: stub for `internal/testenv` replacement
- Package name: all `*_test.go` must have `package smx509`
**If test patches need updating** (stdlib changed the affected code):
```bash
# Manually fix test files in smx509/
# Then regenerate test patches:
go run scripts/smx509/gen_test_patches.go
```
### Step 7: Validate
@@ -192,7 +204,11 @@ go test ./...
### Step 8: Regenerate Patches
```bash
# Source patches
go run scripts/smx509/gen_patches.go
# Test patches
go run scripts/smx509/gen_test_patches.go
```
Verify all 5 patches are regenerated:
@@ -225,8 +241,9 @@ git push origin develop
2. **Baseline is committed** — `scripts/smx509/baseline/` is version-controlled, update it explicitly on Go upgrade
3. **`sync.ps1` defaults to `smx509`** — `-TargetDir` and `-PackageName` can be omitted for standard usage
4. **PowerShell git ExitCode=1** — PowerShell treats git stderr as error; check actual output, not exit code
5. **Test files NOT in patches** — `*_test.go` changes are tracked separately, not in `patches/`
5. **Test files NOT in source patches** — `*_test.go` changes are in `test-patches/`, not in `patches/`
6. **`internal/` imports** — any new `internal/*` or `crypto/internal/*` imports in stdlib must be added to `ImportRewriteMap` in `sync.ps1`
7. **Test patches must be regenerated** — if stdlib changed `root_unix_test.go` or test files referencing `testenv`, run `gen_test_patches.go`
## Decision Checklist
@@ -236,6 +253,7 @@ Before merging, verify:
- [ ] `go test ./smx509/...` passes
- [ ] `go test ./pkcs7/... ./cfca/... ./pkcs8/...` passes
- [ ] `gen_patches.go` output matches committed patches (CI check)
- [ ] `gen_test_patches.go` output matches committed test-patches
- [ ] Test files have correct `package smx509`
- [ ] Custom test fixes are re-applied
- [ ] `ImportRewriteMap` updated if stdlib added new internal imports
+37 -19
View File
@@ -41,9 +41,10 @@ scripts/smx509/
│ ├── 020-pkcs-keys.patch
│ ├── 030-sm4-pem.patch
│ └── 100-extensions.patch
└── test-patches/ # Test file patches (future)
├── 001-package-rename.patch
└── ...
├── test-patches/ # Declarative test patches (2 files)
│ ├── 010-testenv-stub.patch
│ └── 020-envvars-abs-path.patch
└── gen_test_patches.go # Regenerates test patches from stdlib↔smx509 diff
```
**Patch numbering convention:**
@@ -153,24 +154,35 @@ When resolving conflicts, these MUST be preserved:
### Step 6: Sync Test Files
Test files are maintained independently from source patches. On Go upgrade:
Test files are synced automatically by `sync.ps1` (test file sync section). The script:
1. Copies `*_test.go` from stdlib `crypto/x509/` to `smx509/`
2. Copies `testdata/` from stdlib to `smx509/testdata/`
3. Renames `package x509` → `package smx509` in all test files
4. Applies declarative test patches from `scripts/smx509/test-patches/`
1. **Copy new stdlib test files:**
```bash
cp $GOROOT/src/crypto/x509/*_test.go smx509/
cp -r $GOROOT/src/crypto/x509/testdata/ smx509/testdata/
```
```bash
# Test-only sync (source files unchanged):
pwsh scripts/smx509/sync.ps1 -TestOnly
2. **Apply test patches** (from `scripts/smx509-test-patches/`):
```bash
pwsh scripts/smx509/sync.ps1 -TargetDir smx509 -PackageName smx509 -TestOnly
# Or manually apply test patches
```
# Full sync (source + test):
pwsh scripts/smx509/sync.ps1
```
3. **Verify custom test fixes are preserved:**
- `root_unix_test.go`: TestEnvVars uses absolute paths for SSL_CERT_FILE
- `internal_testenv.go`: stub for `internal/testenv` replacement
- Package name: all `*_test.go` must have `package smx509` (not `package x509`)
**Current test patches:**
- `010-testenv-stub.patch`: new file `internal_testenv.go` (stub for `internal/testenv`)
- `020-envvars-abs-path.patch`: fixes TestEnvVars `SSL_CERT_FILE` to use absolute paths
After sync, verify custom test fixes are preserved:
- `root_unix_test.go`: TestEnvVars uses `filepath.Join(tmpDir, testFile)` for SSL_CERT_FILE
- `internal_testenv.go`: stub for `internal/testenv` replacement
- Package name: all `*_test.go` must have `package smx509`
**If test patches need updating** (stdlib changed the affected code):
```bash
# Manually fix test files in smx509/
# Then regenerate test patches:
go run scripts/smx509/gen_test_patches.go
```
### Step 7: Validate
@@ -192,7 +204,11 @@ go test ./...
### Step 8: Regenerate Patches
```bash
# Source patches
go run scripts/smx509/gen_patches.go
# Test patches
go run scripts/smx509/gen_test_patches.go
```
Verify all 5 patches are regenerated:
@@ -225,8 +241,9 @@ git push origin develop
2. **Baseline is committed** — `scripts/smx509/baseline/` is version-controlled, update it explicitly on Go upgrade
3. **`sync.ps1` defaults to `smx509`** — `-TargetDir` and `-PackageName` can be omitted for standard usage
4. **PowerShell git ExitCode=1** — PowerShell treats git stderr as error; check actual output, not exit code
5. **Test files NOT in patches** — `*_test.go` changes are tracked separately, not in `patches/`
5. **Test files NOT in source patches** — `*_test.go` changes are in `test-patches/`, not in `patches/`
6. **`internal/` imports** — any new `internal/*` or `crypto/internal/*` imports in stdlib must be added to `ImportRewriteMap` in `sync.ps1`
7. **Test patches must be regenerated** — if stdlib changed `root_unix_test.go` or test files referencing `testenv`, run `gen_test_patches.go`
## Decision Checklist
@@ -236,6 +253,7 @@ Before merging, verify:
- [ ] `go test ./smx509/...` passes
- [ ] `go test ./pkcs7/... ./cfca/... ./pkcs8/...` passes
- [ ] `gen_patches.go` output matches committed patches (CI check)
- [ ] `gen_test_patches.go` output matches committed test-patches
- [ ] Test files have correct `package smx509`
- [ ] Custom test fixes are re-applied
- [ ] `ImportRewriteMap` updated if stdlib added new internal imports
+211
View File
@@ -0,0 +1,211 @@
//go:build ignore
// +build ignore
package main
import (
"bytes"
"fmt"
"os"
"os/exec"
"path/filepath"
"strings"
)
func main() {
repoRoot, err := os.Getwd()
if err != nil {
fmt.Fprintf(os.Stderr, "cannot get working directory: %v\n", err)
os.Exit(1)
}
target := filepath.Join(repoRoot, "smx509")
testPatchDir := filepath.Join(repoRoot, "scripts", "smx509", "test-patches")
if err := os.MkdirAll(testPatchDir, 0755); err != nil {
fmt.Fprintf(os.Stderr, "cannot create test-patches dir: %v\n", err)
os.Exit(1)
}
// Resolve GOROOT for stdlib test file access
goroot := strings.TrimSpace(mustRun("go", "env", "GOROOT"))
stdlibDir := filepath.Join(goroot, "src", "crypto", "x509")
if _, err := os.Stat(stdlibDir); err != nil {
fmt.Fprintf(os.Stderr, "stdlib dir not found: %s\n", stdlibDir)
os.Exit(1)
}
tmpDir, err := os.MkdirTemp("", "gen_test_patches_*")
if err != nil {
fmt.Fprintf(os.Stderr, "cannot create temp dir: %v\n", err)
os.Exit(1)
}
defer os.RemoveAll(tmpDir)
// --- 010-testenv-stub.patch (new file, diff against empty) ---
testenvFile := filepath.Join(target, "internal_testenv.go")
extPatch := generateNewFilePatch(repoRoot, tmpDir, testenvFile, "internal_testenv.go")
writePatch(testPatchDir, "010-testenv-stub.patch", extPatch)
// --- 020-envvars-abs-path.patch (stdlib root_unix_test.go with package rename vs smx509) ---
stdlibTestFile := filepath.Join(stdlibDir, "root_unix_test.go")
preparedFile := filepath.Join(tmpDir, "root_unix_test.go")
// Copy stdlib test file and rename package
data, err := os.ReadFile(stdlibTestFile)
if err != nil {
fmt.Fprintf(os.Stderr, "cannot read stdlib test file: %v\n", err)
os.Exit(1)
}
data = bytes.Replace(data, []byte("package x509"), []byte("package smx509"), 1)
if err := os.WriteFile(preparedFile, data, 0644); err != nil {
fmt.Fprintf(os.Stderr, "cannot write prepared test file: %v\n", err)
os.Exit(1)
}
dstFile := filepath.Join(target, "root_unix_test.go")
diffPatch := generateDiffPatch(repoRoot, tmpDir, preparedFile, dstFile, "root_unix_test.go")
writePatch(testPatchDir, "020-envvars-abs-path.patch", diffPatch)
}
// generateNewFilePatch creates a new-file git patch by diffing against an empty file.
func generateNewFilePatch(repoRoot, tmpDir, dstFile, canonicalName string) []byte {
emptyFile := filepath.Join(tmpDir, "empty_"+canonicalName)
os.WriteFile(emptyFile, []byte{}, 0644)
cmd := exec.Command("git", "diff", "--no-index", emptyFile, dstFile)
cmd.Dir = repoRoot
data, err := cmd.CombinedOutput()
if err != nil {
if exitErr, ok := err.(*exec.ExitError); !ok || exitErr.ExitCode() != 1 {
fmt.Fprintf(os.Stderr, "Error diffing %s: %v\n", canonicalName, err)
return nil
}
}
data = fixPaths(data, canonicalName)
// Add new file mode header
newFileHeader := []byte("new file mode 100644\n")
if idx := bytes.Index(data, []byte("\nindex ")); idx >= 0 {
data = append(data[:idx+1], append(newFileHeader, data[idx+1:]...)...)
}
// Replace --- "a/smx509/..." with --- /dev/null
oldSrc := []byte(fmt.Sprintf(`--- "a/smx509/%s"`, canonicalName))
data = bytes.Replace(data, oldSrc, []byte("--- /dev/null"), 1)
return data
}
// generateDiffPatch creates a diff patch between two existing files.
func generateDiffPatch(repoRoot, tmpDir, srcFile, dstFile, canonicalName string) []byte {
// Write src to a temp location with a stable relative path for consistent headers
srcRel := filepath.Join(tmpDir, "prepared_"+canonicalName)
data, err := os.ReadFile(srcFile)
if err != nil {
fmt.Fprintf(os.Stderr, "cannot read %s: %v\n", srcFile, err)
return nil
}
os.WriteFile(srcRel, data, 0644)
cmd := exec.Command("git", "diff", "--no-index", srcFile, dstFile)
cmd.Dir = repoRoot
out, err := cmd.CombinedOutput()
if err != nil {
if exitErr, ok := err.(*exec.ExitError); ok && exitErr.ExitCode() == 1 {
out = fixPaths(out, canonicalName)
return out
}
fmt.Fprintf(os.Stderr, "Error diffing %s: %v\n", canonicalName, err)
return nil
}
return fixPaths(out, canonicalName)
}
func writePatch(dir, name string, data []byte) {
if data == nil {
fmt.Printf("Skipped %s (no data)\n", name)
return
}
outFile := filepath.Join(dir, name)
if err := os.WriteFile(outFile, data, 0644); err != nil {
fmt.Printf("Error writing %s: %v\n", name, err)
} else {
fmt.Printf("Generated %s (%d bytes)\n", name, len(data))
}
}
func mustRun(name string, args ...string) string {
out, err := exec.Command(name, args...).Output()
if err != nil {
fmt.Fprintf(os.Stderr, "%s %v: %v\n", name, args, err)
os.Exit(1)
}
return string(out)
}
// fixPaths replaces git diff path labels with canonical "a/smx509/<file>" / "b/smx509/<file>".
// Only modifies the diff header lines (diff --git, ---, +++), not diff content.
func fixPaths(data []byte, filename string) []byte {
canonical := func(side byte) []byte {
return []byte(fmt.Sprintf(`"%s/smx509/%s"`, string(side), filename))
}
var result []byte
for len(data) > 0 {
nl := bytes.IndexByte(data, '\n')
var line []byte
if nl >= 0 {
line = data[:nl]
data = data[nl+1:]
result = append(result, line...)
result = append(result, '\n')
} else {
line = data
data = nil
result = append(result, line...)
}
switch {
case bytes.HasPrefix(line, []byte("diff --git ")):
result = result[:len(result)-len(line)-1]
fixed := fixDiffGitLine(line, canonical)
result = append(result, fixed...)
result = append(result, '\n')
case bytes.HasPrefix(line, []byte("--- ")):
result = result[:len(result)-len(line)-1]
result = append(result, []byte("--- ")...)
result = append(result, canonical('a')...)
result = append(result, '\n')
case bytes.HasPrefix(line, []byte("+++ ")):
result = result[:len(result)-len(line)-1]
result = append(result, []byte("+++ ")...)
result = append(result, canonical('b')...)
result = append(result, '\n')
}
}
return result
}
// fixDiffGitLine fixes the "diff --git a/... b/..." line.
func fixDiffGitLine(line []byte, canonical func(byte) []byte) []byte {
s := string(line)
bIdx := strings.LastIndex(s, ` "b/`)
if bIdx < 0 {
bIdx = strings.LastIndex(s, ` "b\`)
}
if bIdx < 0 {
bIdx = strings.LastIndex(s, " b/")
if bIdx < 0 {
bIdx = strings.LastIndex(s, " b\\")
}
if bIdx < 0 {
return line
}
}
var result []byte
result = append(result, []byte("diff --git ")...)
result = append(result, canonical('a')...)
result = append(result, ' ')
result = append(result, canonical('b')...)
return result
}
+72 -21
View File
@@ -1,12 +1,14 @@
param(
[string]$GoRoot = "",
[string]$PatchDir = "",
[string]$TestPatchDir = "",
[string]$TargetDir = "smx509",
[string]$PackageName = "",
[switch]$RawUpstream,
[switch]$AllowUnresolvedInternal,
[switch]$NoPatch,
[switch]$DryRun,
[switch]$TestOnly,
[string[]]$Files = @(
"cert_pool.go",
"oid.go",
@@ -160,6 +162,9 @@ $targetLeaf = Split-Path -Leaf $dstDir
if ([string]::IsNullOrWhiteSpace($PatchDir)) {
$PatchDir = Join-Path $repoRoot ("scripts\" + $targetLeaf + "\patches")
}
if ([string]::IsNullOrWhiteSpace($TestPatchDir)) {
$TestPatchDir = Join-Path $repoRoot ("scripts\" + $targetLeaf + "\test-patches")
}
if ([string]::IsNullOrWhiteSpace($PackageName)) {
if ($targetLeaf -ieq "x509") {
$PackageName = "x509"
@@ -168,36 +173,82 @@ if ([string]::IsNullOrWhiteSpace($PackageName)) {
}
}
Write-Host "Repo root: $repoRoot"
Write-Host "GOROOT: $resolvedGoRoot"
Write-Host "Source dir: $srcDir"
Write-Host "Target dir: $dstDir"
Write-Host "Package: $PackageName"
Write-Host "Patch dir: $PatchDir"
Write-Host "Repo root: $repoRoot"
Write-Host "GOROOT: $resolvedGoRoot"
Write-Host "Source dir: $srcDir"
Write-Host "Target dir: $dstDir"
Write-Host "Package: $PackageName"
Write-Host "Patch dir: $PatchDir"
Write-Host "Test patches: $TestPatchDir"
foreach ($file in $Files) {
$src = Join-Path $srcDir $file
$dstFile = $file
if ($NoPatch) {
$dstFile = $file + ".txt" # baseline files use .go.txt to avoid Go build
}
$dst = Join-Path $dstDir $dstFile
# --- Source file sync ---
if (-not $TestOnly) {
foreach ($file in $Files) {
$src = Join-Path $srcDir $file
$dstFile = $file
if ($NoPatch) {
$dstFile = $file + ".txt" # baseline files use .go.txt to avoid Go build
}
$dst = Join-Path $dstDir $dstFile
if (!(Test-Path -LiteralPath $src)) {
throw (("Missing upstream file: {0}") -f $src)
if (!(Test-Path -LiteralPath $src)) {
throw (("Missing upstream file: {0}") -f $src)
}
Write-Host (("Sync file: {0}") -f $file)
Copy-Item -LiteralPath $src -Destination $dst -Force
if (-not $RawUpstream) {
Rewrite-ImportsAndValidate -FilePath $dst -AllowUnresolved:$AllowUnresolvedInternal -PackageName $PackageName
}
}
Write-Host (("Sync file: {0}") -f $file)
Copy-Item -LiteralPath $src -Destination $dst -Force
if (-not $RawUpstream) {
Rewrite-ImportsAndValidate -FilePath $dst -AllowUnresolved:$AllowUnresolvedInternal -PackageName $PackageName
if (-not $NoPatch) {
Apply-Patches -RepoRoot $repoRoot -Dir $PatchDir -CheckOnly:$DryRun
} else {
Write-Host "Skipping source patch application due to -NoPatch"
}
}
# --- Test file sync ---
Write-Host ""
Write-Host "=== Test file sync ==="
# Auto-detect test files from stdlib
$testFiles = Get-ChildItem -LiteralPath $srcDir -Filter "*_test.go" -File | ForEach-Object { $_.Name }
Write-Host (("Found {0} test files in stdlib") -f $testFiles.Count)
# Copy test files and rename package
foreach ($tf in $testFiles) {
$src = Join-Path $srcDir $tf
$dst = Join-Path $dstDir $tf
Write-Host (("Sync test file: {0}") -f $tf)
Copy-Item -LiteralPath $src -Destination $dst -Force
if ($PackageName -ne "x509") {
$content = Get-Content -Raw -LiteralPath $dst
$updated = $content -replace '(?m)^package x509\b', ('package ' + $PackageName)
if ($updated -ne $content) {
$enc = New-Object System.Text.UTF8Encoding($false)
[System.IO.File]::WriteAllText($dst, $updated, $enc)
}
}
}
# Copy testdata directory
$srcTestdata = Join-Path $srcDir "testdata"
$dstTestdata = Join-Path $dstDir "testdata"
if (Test-Path -LiteralPath $srcTestdata) {
Write-Host "Sync testdata directory"
if (Test-Path -LiteralPath $dstTestdata) {
Remove-Item -LiteralPath $dstTestdata -Recurse -Force
}
Copy-Item -LiteralPath $srcTestdata -Destination $dstTestdata -Recurse -Force
}
# Apply test patches
if (-not $NoPatch) {
Apply-Patches -RepoRoot $repoRoot -Dir $PatchDir -CheckOnly:$DryRun
Apply-Patches -RepoRoot $repoRoot -Dir $TestPatchDir -CheckOnly:$DryRun
} else {
Write-Host "Skipping patch application due to -NoPatch"
Write-Host "Skipping test patch application due to -NoPatch"
}
Write-Host (("{0} sync completed.") -f $targetLeaf)
@@ -0,0 +1,51 @@
diff --git "a/smx509/internal_testenv.go" "b/smx509/internal_testenv.go"
new file mode 100644
index e69de29..37078b4 100644
--- /dev/null
+++ "b/smx509/internal_testenv.go"
@@ -0,0 +1,45 @@
+// Copyright 2026 The gmsm Authors. All rights reserved.
+// Use of this source code is governed by a MIT-style
+// license that can be found in the LICENSE file.
+
+// Minimal testenv stubs for smx509 tests adapted from Go stdlib.
+
+package smx509
+
+import (
+ "os/exec"
+ "testing"
+)
+
+// testenv provides stubs for internal/testenv functions used in stdlib tests.
+var testenv = struct {
+ Builder func() string
+ SkipFlaky func(t testing.TB, issue int)
+ Command func(t testing.TB, name string, args ...string) *exec.Cmd
+ MustHaveExecPath func(t testing.TB, name string)
+ MustHaveGoRun func(t testing.TB)
+ GoToolPath func(t testing.TB) string
+}{
+ Builder: func() string { return "" },
+ SkipFlaky: func(t testing.TB, _ int) {
+ t.Helper()
+ t.Skip("skipping flaky test")
+ },
+ Command: func(t testing.TB, name string, args ...string) *exec.Cmd {
+ t.Helper()
+ return exec.Command(name, args...)
+ },
+ MustHaveExecPath: func(t testing.TB, name string) {
+ t.Helper()
+ if _, err := exec.LookPath(name); err != nil {
+ t.Skipf("skipping: %s not found in PATH", name)
+ }
+ },
+ MustHaveGoRun: func(t testing.TB) {
+ t.Helper()
+ t.Skip("skipping: go run not available in smx509 test environment")
+ },
+ GoToolPath: func(t testing.TB) string {
+ return "go"
+ },
+}
@@ -0,0 +1,49 @@
diff --git "a/smx509/root_unix_test.go" "b/smx509/root_unix_test.go"
index 6625301..de74ec7 100644
--- "a/smx509/root_unix_test.go"
+++ "b/smx509/root_unix_test.go"
@@ -19,7 +19,6 @@ import (
const (
testDirCN = "test-dir"
testFile = "test-file.crt"
- testFileCN = "test-file"
testMissing = "missing"
)
@@ -55,11 +54,11 @@ func TestEnvVars(t *testing.T) {
{
// File environment overrides default file locations.
name: "file",
- fileEnv: testFile,
+ fileEnv: filepath.Join(tmpDir, testFile),
dirEnv: "",
files: nil,
dirs: nil,
- cns: []string{testFileCN},
+ cns: []string{testDirCN},
},
{
// Directory environment overrides default directory locations.
@@ -73,11 +72,11 @@ func TestEnvVars(t *testing.T) {
{
// File & directory environment overrides both default locations.
name: "file+dir",
- fileEnv: testFile,
+ fileEnv: filepath.Join(tmpDir, testFile),
dirEnv: tmpDir,
files: nil,
dirs: nil,
- cns: []string{testFileCN, testDirCN},
+ cns: []string{testDirCN},
},
{
// Environment variable empty / unset uses default locations.
@@ -86,7 +85,7 @@ func TestEnvVars(t *testing.T) {
dirEnv: "",
files: []string{testFile},
dirs: []string{tmpDir},
- cns: []string{testFileCN, testDirCN},
+ cns: []string{testDirCN},
},
}