MCPcopy
hub / github.com/kopia/kopia / TestStreamingFile

Function TestStreamingFile

fs/virtualfs/virtualfs_test.go:24–76  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

22)
23
24func TestStreamingFile(t *testing.T) {
25 // Create a temporary file with test data
26 content := []byte("Temporary file content")
27
28 r, w, err := os.Pipe()
29 if err != nil {
30 t.Fatalf("error creating pipe file: %v", err)
31 }
32
33 if _, err = w.Write(content); err != nil {
34 t.Fatalf("error writing to pipe file: %v", err)
35 }
36
37 w.Close()
38
39 f := StreamingFileFromReader(testFileName, r)
40
41 rootDir := NewStaticDirectory("root", []fs.Entry{f})
42
43 e, err := rootDir.Child(testlogging.Context(t), testFileName)
44 if err != nil {
45 t.Fatalf("error getting child entry: %v", err)
46 }
47
48 if e.Name() != testFileName {
49 t.Fatalf("did not get expected filename: (actual) %v != %v (expected)", e.Name(), testFileName)
50 }
51
52 entries, err := fs.GetAllEntries(testlogging.Context(t), rootDir)
53 if err != nil {
54 t.Fatalf("error getting dir entries %v", err)
55 }
56
57 if len(entries) == 0 {
58 t.Errorf("expected directory with 1 entry, got %v", rootDir)
59 }
60
61 // Read and compare data
62 reader, err := f.GetReader(testlogging.Context(t))
63 if err != nil {
64 t.Fatalf("error getting streaming file reader: %v", err)
65 }
66
67 result := make([]byte, len(content))
68
69 if _, err = reader.Read(result); err != nil {
70 t.Fatalf("error reading streaming file: %v", err)
71 }
72
73 if !reflect.DeepEqual(result, content) {
74 t.Fatalf("did not get expected file content: (actual) %v != %v (expected)", result, content)
75 }
76}
77
78func TestStreamingFileModTime(t *testing.T) {
79 data := []byte("data")

Callers

nothing calls this directly

Calls 12

ContextFunction · 0.92
GetAllEntriesFunction · 0.92
StreamingFileFromReaderFunction · 0.85
NewStaticDirectoryFunction · 0.85
FatalfMethod · 0.80
ErrorfMethod · 0.80
CloseMethod · 0.65
ChildMethod · 0.65
NameMethod · 0.65
GetReaderMethod · 0.65
WriteMethod · 0.45
ReadMethod · 0.45

Tested by

no test coverage detected