Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
run: go build ./...

- name: Unit tests
run: go test ./internal/... ./gen/... ./test/e2e/ -v -coverprofile=coverage.out -covermode=atomic
run: go test ./cmd/... ./internal/... ./gen/... . -v -coverprofile=coverage.out -covermode=atomic

- name: Upload coverage to Codecov
uses: codecov/codecov-action@57e3a136b779b570ffcdbf80b3bdc90e7fab3de2 # v5
Expand Down
28 changes: 18 additions & 10 deletions cmd/batch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4027,16 +4027,24 @@ func TestRunBatch_MaxExitPropagated(t *testing.T) {
func TestBatchTemplateApply_LookupError(t *testing.T) {
tmpHome := t.TempDir()
t.Setenv("HOME", tmpHome)

// On macOS, os.UserConfigDir() returns $HOME/Library/Application Support.
// Create a regular file where the templates directory should be, so
// os.ReadDir fails with "not a directory".
templatesPath := filepath.Join(tmpHome, "Library", "Application Support", "jr", "templates")
if err := os.MkdirAll(filepath.Dir(templatesPath), 0o755); err != nil {
t.Fatal(err)
}
if err := os.WriteFile(templatesPath, []byte("not a dir"), 0o644); err != nil {
t.Fatal(err)
// Pin XDG_CONFIG_HOME so os.UserConfigDir() resolves into tmpHome on Linux
// regardless of the runner's ambient XDG_CONFIG_HOME value.
t.Setenv("XDG_CONFIG_HOME", filepath.Join(tmpHome, ".config"))

// os.UserConfigDir() is platform-specific: macOS → $HOME/Library/Application
// Support, Linux → $XDG_CONFIG_HOME (or $HOME/.config). Write the sentinel
// at both paths so os.ReadDir fails with "not a directory" regardless of OS.
for _, rel := range []string{
"Library/Application Support/jr/templates",
".config/jr/templates",
} {
path := filepath.Join(tmpHome, rel)
if err := os.MkdirAll(filepath.Dir(path), 0o755); err != nil {
t.Fatal(err)
}
if err := os.WriteFile(path, []byte("not a dir"), 0o644); err != nil {
t.Fatal(err)
}
}

var stdout, stderr bytes.Buffer
Expand Down
5 changes: 5 additions & 0 deletions cmd/template_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -889,6 +889,9 @@ func TestRunTemplateShow_LookupConfigError(t *testing.T) {
// expected, so that os.ReadDir returns a non-ErrNotExist error.
tmpHome := t.TempDir()
t.Setenv("HOME", tmpHome)
// Pin XDG_CONFIG_HOME; on Linux os.UserConfigDir reads it first and would
// otherwise resolve outside tmpHome on CI runners.
t.Setenv("XDG_CONFIG_HOME", filepath.Join(tmpHome, ".config"))

// On macOS UserConfigDir returns $HOME/Library/Application Support.
// On Linux it returns $HOME/.config. Create a file at both possible paths
Expand Down Expand Up @@ -970,6 +973,7 @@ func TestRunTemplateCreate_NoClientWithFrom(t *testing.T) {
func TestRunTemplateList_ListError(t *testing.T) {
tmpHome := t.TempDir()
t.Setenv("HOME", tmpHome)
t.Setenv("XDG_CONFIG_HOME", filepath.Join(tmpHome, ".config"))
for _, rel := range []string{
"Library/Application Support/jr/templates",
".config/jr/templates",
Expand Down Expand Up @@ -1013,6 +1017,7 @@ func TestRunTemplateList_ListError(t *testing.T) {
func TestRunTemplateApply_LookupError(t *testing.T) {
tmpHome := t.TempDir()
t.Setenv("HOME", tmpHome)
t.Setenv("XDG_CONFIG_HOME", filepath.Join(tmpHome, ".config"))
for _, rel := range []string{
"Library/Application Support/jr/templates",
".config/jr/templates",
Expand Down
6 changes: 6 additions & 0 deletions internal/template/template_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,12 @@ func TestRenderFieldsEmptyOmitted(t *testing.T) {
}

func TestList(t *testing.T) {
// Sandbox user templates to a clean empty dir so List() returns only
// builtin templates, regardless of whatever the runner's real HOME contains.
origDir := userTemplatesDir
userTemplatesDir = func() string { return t.TempDir() }
defer func() { userTemplatesDir = origDir }()

data, err := List()
if err != nil {
t.Fatalf("unexpected error: %v", err)
Expand Down
194 changes: 0 additions & 194 deletions test/e2e/e2e_test.go

This file was deleted.

Loading