@@ -20,6 +20,8 @@ import (
2020 "io"
2121 "io/fs"
2222 "net/url"
23+ "path/filepath"
24+ "runtime"
2325 "testing"
2426 "time"
2527
@@ -30,9 +32,10 @@ import (
3032
3133func (c * fsCache ) Close () error { return c .root .Close () }
3234
33- func makeRoot (t testing.TB ) * url.URL {
35+ func makeRootURL (t testing.TB ) * url.URL {
3436 t .Helper ()
35- u , err := url .Parse ("fscache://" + t .TempDir () + "?appname=testapp" )
37+ tempDir := filepath .ToSlash (t .TempDir ())
38+ u , err := url .Parse ("fscache://" + tempDir + "?appname=testapp" )
3639 if err != nil {
3740 t .Fatalf ("Failed to parse cache URL: %v" , err )
3841 }
@@ -41,7 +44,7 @@ func makeRoot(t testing.TB) *url.URL {
4144
4245func TestFSCache_Acceptance (t * testing.T ) {
4346 acceptance .Run (t , acceptance .FactoryFunc (func () (driver.Conn , func ()) {
44- u := makeRoot (t )
47+ u := makeRootURL (t )
4548 cache , err := fromURL (u )
4649 testutil .RequireNoError (t , err , "Failed to create fscache" )
4750 cleanup := func () { cache .Close () }
@@ -50,7 +53,7 @@ func TestFSCache_Acceptance(t *testing.T) {
5053}
5154
5255func Test_fsCache_SetError (t * testing.T ) {
53- u := makeRoot (t )
56+ u := makeRootURL (t )
5457 cache , err := fromURL (u )
5558 testutil .RequireNoError (t , err , "Failed to create fscache" )
5659 t .Cleanup (func () { cache .Close () })
@@ -63,7 +66,7 @@ func Test_fsCache_SetError(t *testing.T) {
6366}
6467
6568func Test_fsCache_KeysError (t * testing.T ) {
66- u := makeRoot (t )
69+ u := makeRootURL (t )
6770 cache , err := fromURL (u )
6871 testutil .RequireNoError (t , err , "Failed to create fscache" )
6972 t .Cleanup (func () { cache .Close () })
@@ -96,7 +99,7 @@ func TestOpen(t *testing.T) {
9699 {
97100 name : "Valid Root Directory" ,
98101 args : args {
99- dsn : "fscache://" + t .TempDir () + "?appname=myapp" ,
102+ dsn : "fscache://" + filepath . ToSlash ( t .TempDir () ) + "?appname=myapp" ,
100103 },
101104 assertion : func (tt * testing.T , got * fsCache , err error ) {
102105 testutil .RequireNoError (tt , err )
@@ -119,8 +122,13 @@ func TestOpen(t *testing.T) {
119122 dsn : "fscache://?appname=myapp" ,
120123 },
121124 setup : func (tt * testing.T ) {
122- tt .Setenv ("XDG_CACHE_HOME" , "" )
123- tt .Setenv ("HOME" , "" )
125+ switch runtime .GOOS {
126+ case "windows" :
127+ tt .Setenv ("LocalAppData" , "" )
128+ default :
129+ tt .Setenv ("XDG_CACHE_HOME" , "" )
130+ tt .Setenv ("HOME" , "" )
131+ }
124132 },
125133 assertion : func (tt * testing.T , got * fsCache , err error ) {
126134 testutil .RequireErrorIs (tt , err , ErrUserCacheDir )
@@ -140,7 +148,14 @@ func TestOpen(t *testing.T) {
140148 {
141149 name : "Invalid Root Directory" ,
142150 args : args {
143- dsn : "fscache:///../invalid?appname=myapp" ,
151+ dsn : "fscache://" + filepath .ToSlash (
152+ filepath .VolumeName (t .TempDir ())+ "/../invalid" ,
153+ ) + "?appname=myapp" ,
154+ },
155+ setup : func (tt * testing.T ) {
156+ if runtime .GOOS == "windows" {
157+ tt .Skip ("Skipping invalid path test on Windows" )
158+ }
144159 },
145160 assertion : func (tt * testing.T , got * fsCache , err error ) {
146161 testutil .RequireErrorIs (tt , err , ErrCreateCacheDir )
@@ -150,10 +165,7 @@ func TestOpen(t *testing.T) {
150165 {
151166 name : "Encryption Enabled with Key" ,
152167 args : args {
153- dsn : "fscache://?appname=myapp&encrypt=aesgcm&encrypt_key=" + mustBase64Key (
154- t ,
155- 16 ,
156- ),
168+ dsn : "fscache://?appname=myapp&encrypt=aesgcm&encrypt_key=" + mustBase64Key (t , 16 ),
157169 },
158170 assertion : func (tt * testing.T , got * fsCache , err error ) {
159171 testutil .RequireNoError (tt , err )
@@ -190,6 +202,11 @@ func TestOpen(t *testing.T) {
190202 args : args {
191203 dsn : "fscache://?appname=myapp&connect_timeout=1ns&timeout=10s" ,
192204 },
205+ setup : func (tt * testing.T ) {
206+ if runtime .GOOS == "windows" {
207+ tt .Skip ("Skipping connect timeout test on Windows" )
208+ }
209+ },
193210 assertion : func (tt * testing.T , got * fsCache , err error ) {
194211 testutil .RequireErrorIs (tt , err , context .DeadlineExceeded )
195212 testutil .AssertNil (tt , got )
@@ -231,7 +248,7 @@ func Test_parseTimeout(t *testing.T) {
231248}
232249
233250func TestFSCache_SetGet_WithEncryption (t * testing.T ) {
234- u , err := url .Parse ("fscache://" + t .TempDir () +
251+ u , err := url .Parse ("fscache://" + filepath . ToSlash ( t .TempDir () ) +
235252 "?appname=testapp&encrypt=aesgcm&encrypt_key=6S-Ks2YYOW0xMvTzKSv6QD30gZeOi1c6Ydr-As5csWk=" )
236253 testutil .RequireNoError (t , err )
237254 cache , err := fromURL (u )
0 commit comments