MCPcopy Index your code
hub / github.com/perkeep/perkeep / TestMagic

Function TestMagic

internal/magic/magic_test.go:65–93  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

63}
64
65func TestMagic(t *testing.T) {
66 var hasFile bool
67 if _, err := exec.LookPath("file"); err == nil {
68 hasFile = true
69 }
70
71 for i, tt := range tests {
72 var err error
73 data := []byte(tt.data)
74 if tt.fileName != "" {
75 data, err = os.ReadFile("testdata/" + tt.fileName)
76 if err != nil {
77 t.Fatalf("Error reading %s: %v", tt.fileName,
78 err)
79 }
80 }
81 mime := MIMEType(data)
82 if mime != tt.want {
83 t.Errorf("%d. got %q; want %q", i, mime, tt.want)
84 }
85 if !hasFile {
86 continue
87 }
88 fmime, ok := runFileCmd(data)
89 if ok && fmime != tt.want {
90 t.Logf("%d. warning: got %q via file; want %q", i, fmime, tt.want)
91 }
92 }
93}
94
95func TestIsVideoFilename(t *testing.T) {
96 for _, tt := range tests {

Callers

nothing calls this directly

Calls 5

MIMETypeFunction · 0.85
runFileCmdFunction · 0.85
LogfMethod · 0.80
LookPathMethod · 0.65
FatalfMethod · 0.65

Tested by

no test coverage detected