MCPcopy Create free account
hub / github.com/Azure/peerd / TestFetchFile

Function TestFetchFile

pkg/files/files_test.go:31–60  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

29}
30
31func TestFetchFile(t *testing.T) {
32 d := map[string][]byte{
33 "0": []byte("abc"),
34 "3": []byte("def"),
35 }
36
37 r := &mockReader{data: d}
38
39 if b, err := FetchFile(r, "test", 0, 3); err != nil {
40 t.Errorf("expected no error, got %v", err)
41 } else if string(b) != "abc" {
42 t.Errorf("expected %s, got %s", "abc", string(b))
43 }
44
45 if b, err := FetchFile(r, "test", 0, 4); err != nil {
46 t.Errorf("expected no error, got %v", err)
47 } else if string(b[:3]) != "abc" {
48 t.Errorf("expected %s, got %s", "abc", string(b))
49 }
50
51 if b, err := FetchFile(r, "test", 3, 3); err != nil {
52 t.Errorf("expected no error, got %v", err)
53 } else if string(b) != "def" {
54 t.Errorf("expected %s, got %s", "def", string(b))
55 }
56
57 if b, err := FetchFile(r, "test", 31, 4); err == nil {
58 t.Errorf("expected error, got %s", string(b))
59 }
60}
61
62type mockReader struct {
63 data map[string][]byte

Callers

nothing calls this directly

Calls 1

FetchFileFunction · 0.85

Tested by

no test coverage detected