41 lines
1 KiB
Go
41 lines
1 KiB
Go
package commands
|
|
|
|
import (
|
|
"os/user"
|
|
"path/filepath"
|
|
"testing"
|
|
)
|
|
|
|
func TestGetCacheDirDefault(t *testing.T) {
|
|
configuration, _ := NewConfigFromYamlBytes([]byte(""))
|
|
|
|
if configuration.GetCacheDir() != getDefaultCacheDirectory() {
|
|
t.Errorf("Expected default %s, got %s instead.", getDefaultCacheDirectory(), configuration.GetCacheDir())
|
|
}
|
|
}
|
|
|
|
func TestGetCacheDirExpandsTilde(t *testing.T) {
|
|
configuration, _ := NewConfigFromYamlBytes([]byte(""))
|
|
user, _ := user.Current()
|
|
|
|
cacheDir := configuration.GetCacheDir()
|
|
if filepath.HasPrefix(configuration.GetCacheDir(), "~") {
|
|
t.Errorf("Expected tilde to be expanded, was not.")
|
|
}
|
|
|
|
if !filepath.HasPrefix(cacheDir, user.HomeDir) {
|
|
t.Errorf("Expected tilder to be expanded, was not.")
|
|
}
|
|
}
|
|
|
|
func TestGetCacheDirReturnsCachePath(t *testing.T) {
|
|
sample := `
|
|
cache:
|
|
dir: "/tmp/cache-dir"
|
|
`
|
|
configuration, _ := NewConfigFromYamlBytes([]byte(sample))
|
|
cacheDir := configuration.GetCacheDir()
|
|
if cacheDir != "/tmp/cache-dir" {
|
|
t.Errorf("Unexpected cache path: %s", cacheDir)
|
|
}
|
|
}
|