MCPcopy Create free account
hub / github.com/cli/cli / TestBinaryContentType

Function TestBinaryContentType

pkg/iostreams/content_test.go:14–46  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

12)
13
14func TestBinaryContentType(t *testing.T) {
15 tests := []struct {
16 name string
17 content []byte
18 wantMIME string
19 wantBinary bool
20 }{
21 {
22 name: "empty content is not binary",
23 content: []byte{},
24 wantBinary: false,
25 },
26 {
27 name: "plain text is not binary",
28 content: []byte("hello world\n"),
29 wantBinary: false,
30 },
31 {
32 name: "png is binary",
33 content: append([]byte("\x89PNG\r\n\x1a\n"), make([]byte, 16)...),
34 wantMIME: "image/png",
35 wantBinary: true,
36 },
37 }
38
39 for _, tt := range tests {
40 t.Run(tt.name, func(t *testing.T) {
41 mime, ok := BinaryContentType(tt.content)
42 assert.Equal(t, tt.wantBinary, ok)
43 assert.Equal(t, tt.wantMIME, mime)
44 })
45 }
46}
47
48func TestContainsEscapeSequence(t *testing.T) {
49 assert.False(t, ContainsEscapeSequence([]byte("plain text")))

Callers

nothing calls this directly

Calls 3

BinaryContentTypeFunction · 0.85
EqualMethod · 0.80
RunMethod · 0.65

Tested by

no test coverage detected