Skip to content

Commit

Permalink
wip: add cache tests
Browse files Browse the repository at this point in the history
Signed-off-by: Brian McGee <[email protected]>
  • Loading branch information
brianmcgee committed Jul 23, 2024
1 parent 9cfe7db commit bfea769
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions cache/cache_test.go
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")
}

0 comments on commit bfea769

Please sign in to comment.