Add the client the new backend will use above the wire: it loads the account, finds or creates the main volume, share and root, and lists folders by paging child IDs and fetching their metadata 100 at a time with at most 15 requests in flight, decrypting with the verification keys the SDK's nodes module chooses. A brand-new account has no volume: my-files answers code 2501 and the client creates the volume as the SDK's shares module does, accepting code 2500 from a concurrent creator. Nodes whose name or key can't be decrypted, or whose name is not valid, are left out with one error each; Proton Docs and Sheets are left out with one notice; failed signature checks are logged once and the node is still listed. API calls are paced and retried: 429 waits for Retry-After before retrying, 408 and 5xx are retried, other client errors are not. errExists moves to Task 9, which first uses it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
83 lines
1.9 KiB
Go
83 lines
1.9 KiB
Go
package protondrive
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestNodeCacheDisabled(t *testing.T) {
|
|
c := newNodeCache(false)
|
|
require.Nil(t, c)
|
|
n := &node{ID: "a", ParentID: "root"}
|
|
c.put(n)
|
|
c.setChildren("root", []*node{n})
|
|
assert.Nil(t, c.get("a"))
|
|
_, ok := c.children("root")
|
|
assert.False(t, ok)
|
|
c.invalidate("a")
|
|
c.invalidateChildren("root")
|
|
c.clear()
|
|
}
|
|
|
|
func TestNodeCache(t *testing.T) {
|
|
c := newNodeCache(true)
|
|
dir := &node{ID: "dir", ParentID: "root", IsFolder: true}
|
|
file := &node{ID: "file", ParentID: "dir"}
|
|
|
|
assert.Nil(t, c.get("dir"))
|
|
_, ok := c.children("root")
|
|
assert.False(t, ok)
|
|
|
|
c.setChildren("root", []*node{dir})
|
|
c.setChildren("dir", []*node{file})
|
|
assert.Same(t, dir, c.get("dir"))
|
|
assert.Same(t, file, c.get("file"))
|
|
got, ok := c.children("dir")
|
|
require.True(t, ok)
|
|
assert.Equal(t, []*node{file}, got)
|
|
|
|
// An empty listing is a listing.
|
|
c.setChildren("empty", nil)
|
|
got, ok = c.children("empty")
|
|
assert.True(t, ok)
|
|
assert.Empty(t, got)
|
|
|
|
// put replaces the node in the listing.
|
|
renamed := &node{ID: "file", ParentID: "dir", Name: "new"}
|
|
c.put(renamed)
|
|
got, ok = c.children("dir")
|
|
require.True(t, ok)
|
|
assert.Equal(t, []*node{renamed}, got)
|
|
|
|
// invalidate forgets the node and its parent's listing.
|
|
c.invalidate("file")
|
|
assert.Nil(t, c.get("file"))
|
|
_, ok = c.children("dir")
|
|
assert.False(t, ok)
|
|
_, ok = c.children("root")
|
|
assert.True(t, ok)
|
|
|
|
// and a folder's own listing.
|
|
c.setChildren("dir", []*node{file})
|
|
c.invalidate("dir")
|
|
_, ok = c.children("dir")
|
|
assert.False(t, ok)
|
|
_, ok = c.children("root")
|
|
assert.False(t, ok)
|
|
assert.Same(t, file, c.get("file"))
|
|
|
|
c.setChildren("dir", []*node{file})
|
|
c.invalidateChildren("dir")
|
|
_, ok = c.children("dir")
|
|
assert.False(t, ok)
|
|
assert.Same(t, file, c.get("file"))
|
|
|
|
c.setChildren("dir", []*node{file})
|
|
c.clear()
|
|
assert.Nil(t, c.get("file"))
|
|
_, ok = c.children("dir")
|
|
assert.False(t, ok)
|
|
}
|