MCPcopy
hub / github.com/rclone/rclone / TestMemoryObject

Function TestMemoryObject

fs/object/object_test.go:83–196  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

81}
82
83func TestMemoryObject(t *testing.T) {
84 remote := "path/to/object"
85 now := time.Now()
86 content := []byte("potatoXXXXXXXXXXXXX")
87 content = content[:6] // make some extra cap
88
89 o := object.NewMemoryObject(remote, now, content)
90 o.WithMimeType("text/plain; charset=utf-8")
91
92 assert.Equal(t, content, o.Content())
93 assert.Equal(t, object.MemoryFs, o.Fs())
94 assert.Equal(t, remote, o.Remote())
95 assert.Equal(t, remote, o.String())
96 assert.Equal(t, now, o.ModTime(context.Background()))
97 assert.Equal(t, int64(len(content)), o.Size())
98 assert.Equal(t, true, o.Storable())
99 assert.Equal(t, "text/plain; charset=utf-8", o.MimeType(context.Background()))
100
101 Hash, err := o.Hash(context.Background(), hash.MD5)
102 assert.NoError(t, err)
103 assert.Equal(t, "8ee2027983915ec78acc45027d874316", Hash)
104
105 Hash, err = o.Hash(context.Background(), hash.SHA1)
106 assert.NoError(t, err)
107 assert.Equal(t, "3e2e95f5ad970eadfa7e17eaf73da97024aa5359", Hash)
108
109 newNow := now.Add(time.Minute)
110 err = o.SetModTime(context.Background(), newNow)
111 assert.NoError(t, err)
112 assert.Equal(t, newNow, o.ModTime(context.Background()))
113
114 checkOpen := func(rc io.ReadCloser, expected string) {
115 t.Helper()
116 actual, err := io.ReadAll(rc)
117 assert.NoError(t, err)
118 err = rc.Close()
119 assert.NoError(t, err)
120 assert.Equal(t, expected, string(actual))
121 }
122
123 checkContent := func(o fs.Object, expected string) {
124 t.Helper()
125 rc, err := o.Open(context.Background())
126 assert.NoError(t, err)
127 checkOpen(rc, expected)
128 }
129
130 checkContent(o, string(content))
131
132 rc, err := o.Open(context.Background(), &fs.RangeOption{Start: 1, End: 3})
133 assert.NoError(t, err)
134 checkOpen(rc, "ota")
135
136 rc, err = o.Open(context.Background(), &fs.RangeOption{Start: 1, End: -1})
137 assert.NoError(t, err)
138 checkOpen(rc, "otato")
139
140 rc, err = o.Open(context.Background(), &fs.RangeOption{Start: 1, End: 4096})

Callers

nothing calls this directly

Calls 15

WithMimeTypeMethod · 0.95
ContentMethod · 0.95
FsMethod · 0.95
RemoteMethod · 0.95
StringMethod · 0.95
ModTimeMethod · 0.95
SizeMethod · 0.95
StorableMethod · 0.95
MimeTypeMethod · 0.95
HashMethod · 0.95
SetModTimeMethod · 0.95
OpenMethod · 0.95

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…