45 lines
882 B
Go
45 lines
882 B
Go
|
package cache_manager
|
||
|
|
||
|
import (
|
||
|
"path/filepath"
|
||
|
"testing"
|
||
|
)
|
||
|
|
||
|
func TestNewCacheManagerFailsIfNonExistentRoot(t *testing.T) {
|
||
|
nonPath := "/not/a/path"
|
||
|
|
||
|
mgr, err := NewCacheManager(nonPath)
|
||
|
|
||
|
if err == nil {
|
||
|
t.Error("Expected error, got nil.")
|
||
|
}
|
||
|
|
||
|
if mgr != nil {
|
||
|
t.Error("Expected nil manager, got non-nil.")
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func TestNewCacheManagerReturnsCacheManagerPointer(t *testing.T) {
|
||
|
mgr, err := NewCacheManager(t.TempDir())
|
||
|
|
||
|
if err != nil {
|
||
|
t.Errorf("Expected nil error, got %s.", err)
|
||
|
}
|
||
|
|
||
|
if mgr == nil {
|
||
|
t.Error("Expected non-nil manager, got nil.")
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func TestCacheManagerPathReturnsPathRootedAtCacheRoot(t *testing.T) {
|
||
|
tmpRoot := t.TempDir()
|
||
|
mgr, _ := NewCacheManager(tmpRoot)
|
||
|
|
||
|
rootedPath := mgr.Path("test")
|
||
|
expectedPath := filepath.Join(tmpRoot, "test")
|
||
|
|
||
|
if rootedPath != expectedPath {
|
||
|
t.Errorf("Expected %s, got %s.", expectedPath, rootedPath)
|
||
|
}
|
||
|
}
|