-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain_test.go
More file actions
35 lines (27 loc) · 852 Bytes
/
Copy pathmain_test.go
File metadata and controls
35 lines (27 loc) · 852 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package main
import (
"os"
"path/filepath"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestMapCacheDirFollowsCacheDir(t *testing.T) {
previous := cacheDir
t.Cleanup(func() { cacheDir = previous })
cacheDir = filepath.Join(t.TempDir(), "custom")
dir := mapCacheDir()
assert.Equal(t, filepath.Join(cacheDir, "maplibre"), dir)
info, err := os.Stat(dir)
require.NoError(t, err)
assert.True(t, info.IsDir())
}
func TestMapCacheDirReportsFailureAsEmpty(t *testing.T) {
previous := cacheDir
t.Cleanup(func() { cacheDir = previous })
// A regular file where the cache directory must go makes creation fail.
blocker := filepath.Join(t.TempDir(), "blocker")
require.NoError(t, os.WriteFile(blocker, []byte("not a directory"), 0o600))
cacheDir = blocker
assert.Empty(t, mapCacheDir())
}