@@ -2,7 +2,7 @@ package run_test
22
33import (
44 "os"
5- "path"
5+ "path/filepath "
66 "testing"
77
88 "github.com/oalders/debounce/run"
@@ -43,7 +43,7 @@ func TestEnsureDir(t *testing.T) {
4343 err = run .MaybeMakeCacheDir (tempDir , dirName )
4444 require .NoError (t , err , "first attempt to make dir" )
4545
46- _ , err = os .Stat (path .Join (tempDir , dirName ))
46+ _ , err = os .Stat (filepath .Join (tempDir , dirName ))
4747 require .NoError (t , err )
4848
4949 err = run .MaybeMakeCacheDir (tempDir , dirName )
@@ -76,3 +76,35 @@ func TestRunWithNonExistentCacheDir(t *testing.T) {
7676 assert .False (t , success )
7777 assert .Empty (t , output )
7878}
79+
80+ func TestRunCreatesDefaultCacheDir (t * testing.T ) {
81+ t .Parallel ()
82+ // Create a temporary home directory
83+ tempHome , err := os .MkdirTemp ("" , "test-home" )
84+ require .NoError (t , err )
85+ defer os .RemoveAll (tempHome )
86+
87+ // Don't create the cache dir ahead of time - let Run create it
88+ args := & types.DebounceCommand {
89+ Quantity : "1" ,
90+ Unit : "s" ,
91+ Command : []string {"echo" , "Hello, World!" },
92+ Debug : false ,
93+ }
94+
95+ // Run should succeed even when cache dir doesn't exist
96+ success , output , err := run .Run (args , tempHome )
97+ assert .NoError (t , err )
98+ assert .True (t , success )
99+ assert .Equal (t , string (output ), "Hello, World!\n " )
100+
101+ // Verify the cache directory was created
102+ cacheDir := filepath .Join (tempHome , ".cache" , "debounce" )
103+ _ , err = os .Stat (cacheDir )
104+ assert .NoError (t , err , "cache directory should be created" )
105+
106+ // Verify the cache file was created
107+ entries , err := os .ReadDir (cacheDir )
108+ require .NoError (t , err )
109+ assert .Len (t , entries , 1 , "should have created one cache file" )
110+ }
0 commit comments