Skip to content

Commit 95794c1

Browse files
committed
chore: use OS-appropriate cache directory
1 parent bd87c92 commit 95794c1

File tree

7 files changed

+29
-26
lines changed

7 files changed

+29
-26
lines changed

internal/collections/manager_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99
"github.com/maniac-en/req/internal/testutils"
1010
)
1111

12-
1312
func TestCollectionsManagerCRUD(t *testing.T) {
1413
db := testutils.SetupTestDB(t, "collections")
1514
manager := NewCollectionsManager(db)

internal/endpoints/manager_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88
"github.com/maniac-en/req/internal/testutils"
99
)
1010

11-
1211
func TestEndpointsManagerCRUD(t *testing.T) {
1312
db := testutils.SetupTestDB(t, "collections", "endpoints")
1413
manager := NewEndpointsManager(db)
@@ -402,4 +401,4 @@ func TestEndpointsManagerValidation(t *testing.T) {
402401
t.Errorf("Expected ErrInvalidInput, got %v", err)
403402
}
404403
})
405-
}
404+
}

internal/history/manager_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88
"github.com/maniac-en/req/internal/testutils"
99
)
1010

11-
1211
func TestHistoryManagerCRUD(t *testing.T) {
1312
ctx := context.Background()
1413
db := testutils.SetupTestDB(t, "history")

internal/log/handler_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,4 @@ func TestMultiHandler(t *testing.T) {
5151
if !strings.Contains(buf2.String(), "multi test") {
5252
t.Error("second handler should receive message")
5353
}
54-
}
54+
}

internal/log/logger_test.go

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,21 @@ import (
1212

1313
func TestLoggerFactory(t *testing.T) {
1414
factory := NewLoggerFactory()
15-
15+
1616
t.Run("creates working logger", func(t *testing.T) {
1717
config := Config{Level: slog.LevelInfo, Verbose: true}
1818
logger := factory.CreateLogger(config)
19-
19+
2020
if logger == nil {
2121
t.Fatal("factory should create logger")
2222
}
2323
})
24-
24+
2525
t.Run("creates independent instances", func(t *testing.T) {
2626
config := Config{Level: slog.LevelInfo}
2727
logger1 := factory.CreateLogger(config)
2828
logger2 := factory.CreateLogger(config)
29-
29+
3030
if logger1 == logger2 {
3131
t.Error("factory should create independent instances")
3232
}
@@ -36,15 +36,15 @@ func TestLoggerFactory(t *testing.T) {
3636
func TestDualHandler(t *testing.T) {
3737
var buf bytes.Buffer
3838
handler := NewDualHandler(&buf, false, slog.LevelInfo)
39-
39+
4040
record := slog.NewRecord(time.Now(), slog.LevelInfo, "test message", 0)
4141
record.Add("key", "value")
42-
42+
4343
err := handler.Handle(context.Background(), record)
4444
if err != nil {
4545
t.Fatalf("handler failed: %v", err)
4646
}
47-
47+
4848
output := buf.String()
4949
if !strings.Contains(output, "test message") {
5050
t.Error("output should contain message")
@@ -57,17 +57,17 @@ func TestDualHandler(t *testing.T) {
5757
func TestRequestIDFunctions(t *testing.T) {
5858
id1 := GenerateRequestID()
5959
id2 := GenerateRequestID()
60-
60+
6161
if id1 == id2 {
6262
t.Error("IDs should be unique")
6363
}
6464
if !strings.HasPrefix(id1, "req_") {
6565
t.Error("ID should have req_ prefix")
6666
}
67-
67+
6868
ctx := ContextWithRequestID(context.Background(), "test123")
6969
retrieved := RequestIDFromContext(ctx)
70-
70+
7171
if retrieved != "test123" {
7272
t.Errorf("expected test123, got %s", retrieved)
7373
}
@@ -76,10 +76,10 @@ func TestRequestIDFunctions(t *testing.T) {
7676
func TestGlobalLogger(t *testing.T) {
7777
// Test that global functions work
7878
Info("test info message")
79-
Debug("test debug message")
79+
Debug("test debug message")
8080
Warn("test warn message")
8181
Error("test error message")
82-
82+
8383
logger := Global()
8484
if logger == nil {
8585
t.Error("Global() should return logger")
@@ -93,17 +93,17 @@ func TestLoggerWithFile(t *testing.T) {
9393
}
9494
defer os.Remove(tempFile.Name())
9595
tempFile.Close()
96-
96+
9797
factory := NewLoggerFactory()
9898
logger := factory.CreateLogger(Config{
9999
Level: slog.LevelInfo,
100100
LogFilePath: tempFile.Name(),
101101
})
102-
102+
103103
logger.Info("test file logging")
104-
104+
105105
err = logger.Close()
106106
if err != nil {
107107
t.Errorf("Close should not error: %v", err)
108108
}
109-
}
109+
}

internal/testutils/database.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ func SetupTestDB(t *testing.T, tables ...string) *database.Queries {
2323
if schema == "" {
2424
t.Fatalf("Unknown table: %s", table)
2525
}
26-
26+
2727
if _, err := db.Exec(schema); err != nil {
2828
t.Fatalf("Failed to create %s table: %v", table, err)
2929
}
@@ -75,7 +75,7 @@ func getTableSchema(table string) string {
7575
executed_at TEXT NOT NULL DEFAULT CURRENT_TIMESTAMP
7676
);`,
7777
}
78-
78+
7979
return schemas[table]
8080
}
8181

@@ -86,4 +86,4 @@ func CreateTestCollection(t *testing.T, db *database.Queries, name string) int64
8686
t.Fatalf("Failed to create test collection: %v", err)
8787
}
8888
return collection.ID
89-
}
89+
}

main.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,19 @@ type Config struct {
4545
}
4646

4747
func initPaths() error {
48-
// setup paths based on user's home directory
48+
// setup paths using OS-appropriate cache directory
4949
userHomeDir, err := os.UserHomeDir()
5050
if err != nil {
5151
return fmt.Errorf("error reading user's home path: %w", err)
5252
}
5353
USERHOMEDIR = userHomeDir
54-
APPDIR = filepath.Join(USERHOMEDIR, ".cache", "req")
54+
55+
// use OS-appropriate cache directory
56+
userCacheDir, err := os.UserCacheDir()
57+
if err != nil {
58+
return fmt.Errorf("error reading user's cache path: %w", err)
59+
}
60+
APPDIR = filepath.Join(userCacheDir, "req")
5561
if err := os.MkdirAll(APPDIR, 0o755); err != nil {
5662
return fmt.Errorf("error creating app directory: %w", err)
5763
}

0 commit comments

Comments
 (0)