MCPcopy Create free account
hub / github.com/diillson/chatcli / TestReadFileContent_Errors

Function TestReadFileContent_Errors

utils/file_utils_test.go:119–145  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

117}
118
119func TestReadFileContent_Errors(t *testing.T) {
120 tempDir, err := os.MkdirTemp("", "test-readfile-*")
121 require.NoError(t, err)
122 defer os.RemoveAll(tempDir)
123
124 t.Run("File not exist", func(t *testing.T) {
125 _, err := ReadFileContent(filepath.Join(tempDir, "nonexistent.txt"), 1024)
126 assert.Error(t, err)
127 assert.Contains(t, err.Error(), "o arquivo não existe")
128 })
129
130 t.Run("Path is a directory", func(t *testing.T) {
131 _, err := ReadFileContent(tempDir, 1024)
132 assert.Error(t, err)
133 assert.Contains(t, err.Error(), "não aponta para um arquivo regular")
134 })
135
136 t.Run("File too large", func(t *testing.T) {
137 largeFilePath := filepath.Join(tempDir, "large.txt")
138 content := "this is a large file content"
139 require.NoError(t, os.WriteFile(largeFilePath, []byte(content), 0644))
140
141 _, err := ReadFileContent(largeFilePath, 10) // Limite de 10 bytes
142 assert.Error(t, err)
143 assert.Contains(t, err.Error(), "é muito grande")
144 })
145}

Callers

nothing calls this directly

Calls 3

ReadFileContentFunction · 0.85
RunMethod · 0.65
ErrorMethod · 0.65

Tested by

no test coverage detected