(t *testing.T)
| 117 | } |
| 118 | |
| 119 | func 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 | } |
nothing calls this directly
no test coverage detected