github.com/jstaf/onedriver@v0.14.2-0.20240420231225-f07678f9e6ef/fs/cache_test.go (about)

     1  // these tests are independent of the mounted fs
     2  package fs
     3  
     4  import (
     5  	"fmt"
     6  	"path/filepath"
     7  	"testing"
     8  
     9  	"github.com/stretchr/testify/assert"
    10  	"github.com/stretchr/testify/require"
    11  )
    12  
    13  func TestRootGet(t *testing.T) {
    14  	t.Parallel()
    15  	cache := NewFilesystem(auth, filepath.Join(testDBLoc, "test_root_get"))
    16  	root, err := cache.GetPath("/", auth)
    17  	require.NoError(t, err)
    18  	assert.Equal(t, "/", root.Path(), "Root path did not resolve correctly.")
    19  }
    20  
    21  func TestRootChildrenUpdate(t *testing.T) {
    22  	t.Parallel()
    23  	cache := NewFilesystem(auth, filepath.Join(testDBLoc, "test_root_children_update"))
    24  	children, err := cache.GetChildrenPath("/", auth)
    25  	require.NoError(t, err)
    26  
    27  	if _, exists := children["documents"]; !exists {
    28  		t.Fatal("Could not find documents folder.")
    29  	}
    30  }
    31  
    32  func TestSubdirGet(t *testing.T) {
    33  	t.Parallel()
    34  	cache := NewFilesystem(auth, filepath.Join(testDBLoc, "test_subdir_get"))
    35  	documents, err := cache.GetPath("/Documents", auth)
    36  	require.NoError(t, err)
    37  	assert.Equal(t, "Documents", documents.Name(), "Failed to fetch \"/Documents\".")
    38  }
    39  
    40  func TestSubdirChildrenUpdate(t *testing.T) {
    41  	t.Parallel()
    42  	cache := NewFilesystem(auth, filepath.Join(testDBLoc, "test_subdir_children_update"))
    43  	children, err := cache.GetChildrenPath("/Documents", auth)
    44  	require.NoError(t, err)
    45  
    46  	if _, exists := children["documents"]; exists {
    47  		fmt.Println("Documents directory found inside itself. " +
    48  			"Likely the cache did not traverse correctly.\n\nChildren:")
    49  		for key := range children {
    50  			fmt.Println(key)
    51  		}
    52  		t.FailNow()
    53  	}
    54  }
    55  
    56  func TestSamePointer(t *testing.T) {
    57  	t.Parallel()
    58  	cache := NewFilesystem(auth, filepath.Join(testDBLoc, "test_same_pointer"))
    59  	item, _ := cache.GetPath("/Documents", auth)
    60  	item2, _ := cache.GetPath("/Documents", auth)
    61  	if item != item2 {
    62  		t.Fatalf("Pointers to cached items do not match: %p != %p\n", item, item2)
    63  	}
    64  	assert.NotNil(t, item)
    65  }