MCPcopy Create free account
hub / github.com/dearcode/candy / TestFileUploadAndDownload

Function TestFileUploadAndDownload

client/candy_test.go:265–300  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

263}
264
265func TestFileUploadAndDownload(t *testing.T) {
266 keys := make(map[string]struct{})
267 for name := range userNames {
268 id, err := client.Login(name, passwd[name])
269 if err != nil {
270 t.Fatalf("Login error:%v", err)
271 }
272 t.Logf("login user:%v, id:%d", name, id)
273 key, err := client.FileUpload([]byte(name))
274 if err != nil {
275 t.Fatalf("FileUpload error:%v", err)
276 }
277
278 t.Logf("upload user:%s, file:%s", name, key)
279 if _, ok := keys[key]; ok {
280 t.Fatalf("key:%s exist", key)
281 }
282 keys[key] = struct{}{}
283
284 ok, err := client.FileExist(key)
285 if err != nil {
286 t.Fatalf("FileExist error:%v", err)
287 }
288
289 if !ok {
290 t.Fatalf("key:%s not exist", key)
291 }
292 data, err := client.FileDownload(key)
293 if err != nil {
294 t.Fatalf("FileDownload error:%v", err)
295 }
296 if !bytes.Equal(data, []byte(name)) {
297 t.Fatalf("FileDownload key:%s, val:%s, expect:%s", key, data, name)
298 }
299 }
300}
301
302func TestHeartbeat(t *testing.T) {
303 err := client.Heartbeat()

Callers

nothing calls this directly

Calls 4

FileUploadMethod · 0.80
FileExistMethod · 0.80
FileDownloadMethod · 0.80
LoginMethod · 0.65

Tested by

no test coverage detected