MCPcopy Create free account
hub / github.com/docker/docker-agent / TestIsTextFile_ByteSniffing

Function TestIsTextFile_ByteSniffing

pkg/chat/chat_test.go:119–140  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

117}
118
119func TestIsTextFile_ByteSniffing(t *testing.T) {
120 t.Parallel()
121 tmpDir := t.TempDir()
122
123 // File with unknown extension but text content
124 textFile := filepath.Join(tmpDir, "data.custom")
125 err := os.WriteFile(textFile, []byte("This is plain text content\nwith multiple lines\n"), 0o644)
126 require.NoError(t, err)
127 assert.True(t, IsTextFile(textFile), "text content with unknown extension should be detected as text")
128
129 // File with unknown extension and binary content (null bytes)
130 binFile := filepath.Join(tmpDir, "data.custom2")
131 err = os.WriteFile(binFile, []byte{0x00, 0x01, 0x02, 0x03, 0xFF}, 0o644)
132 require.NoError(t, err)
133 assert.False(t, IsTextFile(binFile), "binary content should not be detected as text")
134
135 // Empty file should be treated as text
136 emptyFile := filepath.Join(tmpDir, "empty.custom")
137 err = os.WriteFile(emptyFile, []byte{}, 0o644)
138 require.NoError(t, err)
139 assert.True(t, IsTextFile(emptyFile), "empty file should be treated as text")
140}
141
142func TestReadFileForInline(t *testing.T) {
143 t.Parallel()

Callers

nothing calls this directly

Calls 1

IsTextFileFunction · 0.85

Tested by

no test coverage detected