Skip to content

Commit b3ef329

Browse files
committed
refactor(tests): remove example functions and improve path handling in tests
1 parent 773d498 commit b3ef329

File tree

3 files changed

+21
-24
lines changed

3 files changed

+21
-24
lines changed

store/fscache/filenamer_test.go

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,30 +16,13 @@ package fscache
1616

1717
import (
1818
"encoding/base64"
19-
"fmt"
2019
"path/filepath"
2120
"strings"
2221
"testing"
2322

2423
"github.com/bartventer/httpcache/internal/testutil"
2524
)
2625

27-
func Example_fragmentFileName_short() {
28-
url := "https://short.url/test"
29-
path := fragmentFileName(url)
30-
fmt.Println("Fragmented path:", path)
31-
// Output:
32-
// Fragmented path: aHR0cHM6Ly9zaG9ydC51cmwvdGVzdA
33-
}
34-
35-
func Example_fragmentFileName_long() {
36-
url := "https://example.com/" + strings.Repeat("a", 255)
37-
path := fragmentFileName(url)
38-
fmt.Println("Fragmented path:", path)
39-
// Output:
40-
// Fragmented path: aHR0cHM6Ly9leGFtcGxlLmNvbS9hYWFhYWFhYWFhYWFhYWFh/YWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFh/YWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFh/YWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFh/YWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFh/YWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFh/YWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFh/YWFhYWFhYWFhYWFhYWFhYWFhYWFhYWE
41-
}
42-
4326
func Test_fragmentFileName_fragmentedFileNameToKey(t *testing.T) {
4427
cases := []struct {
4528
name string

store/fscache/fscache_test.go

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,11 @@ func TestOpen(t *testing.T) {
152152
filepath.VolumeName(t.TempDir())+"/../invalid",
153153
) + "?appname=myapp",
154154
},
155+
setup: func(tt *testing.T) {
156+
if runtime.GOOS == "windows" {
157+
tt.Skip("Skipping invalid path test on Windows")
158+
}
159+
},
155160
assertion: func(tt *testing.T, got *fsCache, err error) {
156161
testutil.RequireErrorIs(tt, err, ErrCreateCacheDir)
157162
testutil.AssertNil(tt, got)
@@ -160,10 +165,7 @@ func TestOpen(t *testing.T) {
160165
{
161166
name: "Encryption Enabled with Key",
162167
args: args{
163-
dsn: "fscache://?appname=myapp&encrypt=aesgcm&encrypt_key=" + mustBase64Key(
164-
t,
165-
16,
166-
),
168+
dsn: "fscache://?appname=myapp&encrypt=aesgcm&encrypt_key=" + mustBase64Key(t, 16),
167169
},
168170
assertion: func(tt *testing.T, got *fsCache, err error) {
169171
testutil.RequireNoError(tt, err)
@@ -200,6 +202,11 @@ func TestOpen(t *testing.T) {
200202
args: args{
201203
dsn: "fscache://?appname=myapp&connect_timeout=1ns&timeout=10s",
202204
},
205+
setup: func(tt *testing.T) {
206+
if runtime.GOOS == "windows" {
207+
tt.Skip("Skipping connect timeout test on Windows")
208+
}
209+
},
203210
assertion: func(tt *testing.T, got *fsCache, err error) {
204211
testutil.RequireErrorIs(tt, err, context.DeadlineExceeded)
205212
testutil.AssertNil(tt, got)
@@ -212,7 +219,6 @@ func TestOpen(t *testing.T) {
212219
if err != nil {
213220
t.Fatalf("Failed to parse URL: %v", err)
214221
}
215-
t.Attr("URL", u.String())
216222
if tt.setup != nil {
217223
tt.setup(t)
218224
}
@@ -242,7 +248,7 @@ func Test_parseTimeout(t *testing.T) {
242248
}
243249

244250
func TestFSCache_SetGet_WithEncryption(t *testing.T) {
245-
u, err := url.Parse("fscache://" + t.TempDir() +
251+
u, err := url.Parse("fscache://" + filepath.ToSlash(t.TempDir()) +
246252
"?appname=testapp&encrypt=aesgcm&encrypt_key=6S-Ks2YYOW0xMvTzKSv6QD30gZeOi1c6Ydr-As5csWk=")
247253
testutil.RequireNoError(t, err)
248254
cache, err := fromURL(u)

store/fscache/issue16_test.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,15 @@ func Test_Issue16_LongURLFragmentation(t *testing.T) {
4343
{"long URL (1KB)", 1024, true},
4444
{"very long URL (4KB)", 4096, true},
4545
{"extremely long URL (10KB)", 10240, true},
46-
{"massive URL (100KB)", 102400, true},
46+
{
47+
// While Go's stdlib handles long paths via \\?\ prefix on Windows,
48+
// extremely deep directory hierarchies (2844+ levels) may still hit
49+
// practical filesystem or OS limits beyond just path length.
50+
// See fixLongPath logic in os/path_windows.go (https://cs.opensource.google/go/go/+/refs/tags/go1.25.3:src/os/path_windows.go;l=100;drc=79b809afb325ae266497e21597f126a3e98a1ef7)
51+
"massive URL (100KB)",
52+
102400,
53+
runtime.GOOS != "windows",
54+
},
4755
}
4856

4957
for _, tt := range tests {

0 commit comments

Comments
 (0)