-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Brian McGee <[email protected]>
- Loading branch information
1 parent
9cfe7db
commit bfea769
Showing
1 changed file
with
41 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package cache | ||
|
||
import ( | ||
"github.com/adrg/xdg" | ||
"github.com/stretchr/testify/assert" | ||
"os" | ||
"strings" | ||
"testing" | ||
) | ||
|
||
func TestCache_Open(t *testing.T) { | ||
as := assert.New(t) | ||
|
||
tempDir := t.TempDir() | ||
xdgPrefix, err := xdg.CacheFile("") | ||
|
||
// normal open | ||
cache, err := Open(tempDir, false) | ||
path := cache.db.Path() | ||
|
||
as.NoError(err) | ||
as.True( | ||
strings.HasPrefix(path, xdgPrefix), | ||
"db path %s does not contain the xdg cache file prefix %s", | ||
path, xdgPrefix, | ||
) | ||
|
||
// normal close | ||
as.NoError(cache.Close()) | ||
_, err = os.Stat(path) | ||
as.NoError(err, "db path %s should still exist after closing the cache", path) | ||
|
||
// open a temporary cache e.g. --no-cache | ||
tempDir = t.TempDir() | ||
cache, err = Open(tempDir, true) | ||
as.NoError(err) | ||
|
||
as.NoError(cache.Close()) | ||
_, err = os.Stat(cache.db.Path()) | ||
as.ErrorIs(err, os.ErrNotExist, "temp db path %s should not exist after closing the cache") | ||
} |