MCPcopy
hub / github.com/pocketbase/pocketbase / TestNewFileFromBytes

Function TestNewFileFromBytes

tools/filesystem/file_test.go:75–101  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

73}
74
75func TestNewFileFromBytes(t *testing.T) {
76 // nil bytes
77 if _, err := filesystem.NewFileFromBytes(nil, "photo.jpg"); err == nil {
78 t.Fatal("Expected error, got nil")
79 }
80
81 // zero bytes
82 if _, err := filesystem.NewFileFromBytes([]byte{}, "photo.jpg"); err == nil {
83 t.Fatal("Expected error, got nil")
84 }
85
86 originalName := "image_!@ special"
87 normalizedNamePattern := regexp.QuoteMeta("image_special_") + `\w{10}` + regexp.QuoteMeta(".txt")
88 f, err := filesystem.NewFileFromBytes([]byte("text\n"), originalName)
89 if err != nil {
90 t.Fatal(err)
91 }
92 if f.Size != 5 {
93 t.Fatalf("Expected Size %v, got %v", 5, f.Size)
94 }
95 if f.OriginalName != originalName {
96 t.Fatalf("Expected OriginalName %q, got %q", originalName, f.OriginalName)
97 }
98 if match, err := regexp.Match(normalizedNamePattern, []byte(f.Name)); !match {
99 t.Fatalf("Expected Name to match %v, got %q (%v)", normalizedNamePattern, f.Name, err)
100 }
101}
102
103func TestNewFileFromMultipart(t *testing.T) {
104 formData, mp, err := tests.MockMultipartData(nil, "test")

Callers

nothing calls this directly

Calls 1

NewFileFromBytesFunction · 0.92

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…