Skip to content

Commit c3af85b

Browse files
fix: use require.Error for error assertions per linter requirements
1 parent af09849 commit c3af85b

File tree

4 files changed

+12
-11
lines changed

4 files changed

+12
-11
lines changed

AGENTS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,7 @@ import (
218218
- Use `assert.Equal()` for value comparisons with descriptive messages
219219
- Use `assert.Nil()` and `assert.NotNil()` for pointer checks
220220
- Use `require.*` when the test should stop on failure (e.g., setup operations)
221+
- **Use `require.Error()` for error assertions** - The linter enforces this via testifylint
221222
- **Always include descriptive error messages**
222223

223224
```go

overlay/loader/overlay_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ func TestLoadOverlay_Error_InvalidPath(t *testing.T) {
2727

2828
result, err := LoadOverlay("nonexistent-file.yaml")
2929

30-
assert.Error(t, err, "should return error for nonexistent file")
30+
require.Error(t, err, "should return error for nonexistent file")
3131
assert.Nil(t, result, "should return nil overlay on error")
3232
assert.Contains(t, err.Error(), "failed to parse overlay", "error should mention parsing failure")
3333
}
@@ -42,7 +42,7 @@ func TestLoadOverlay_Error_InvalidYAML(t *testing.T) {
4242

4343
result, err := LoadOverlay(invalidFile)
4444

45-
assert.Error(t, err, "should return error for invalid YAML")
45+
require.Error(t, err, "should return error for invalid YAML")
4646
assert.Nil(t, result, "should return nil overlay on error")
4747
}
4848

overlay/loader/spec_test.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ func TestGetOverlayExtendsPath_Error(t *testing.T) {
9898

9999
result, err := GetOverlayExtendsPath(tt.overlay)
100100

101-
assert.Error(t, err, "should return error")
101+
require.Error(t, err, "should return error")
102102
assert.Empty(t, result, "should return empty path on error")
103103
assert.Contains(t, err.Error(), tt.wantErrorMsg, "error should contain expected message")
104104
})
@@ -155,7 +155,7 @@ func TestLoadSpecification_Error_FileNotFound(t *testing.T) {
155155

156156
result, err := LoadSpecification("nonexistent-file.yaml")
157157

158-
assert.Error(t, err, "should return error for nonexistent file")
158+
require.Error(t, err, "should return error for nonexistent file")
159159
assert.Nil(t, result, "should return nil node on error")
160160
assert.Contains(t, err.Error(), "failed to open schema", "error should mention opening failure")
161161
}
@@ -170,7 +170,7 @@ func TestLoadSpecification_Error_InvalidYAML(t *testing.T) {
170170

171171
result, err := LoadSpecification(testFile)
172172

173-
assert.Error(t, err, "should return error for invalid YAML")
173+
require.Error(t, err, "should return error for invalid YAML")
174174
assert.Nil(t, result, "should return nil node on error")
175175
assert.Contains(t, err.Error(), "failed to parse schema", "error should mention parsing failure")
176176
}
@@ -210,7 +210,7 @@ func TestLoadExtendsSpecification_Error_NoExtends(t *testing.T) {
210210

211211
result, err := LoadExtendsSpecification(o)
212212

213-
assert.Error(t, err, "should return error when extends is empty")
213+
require.Error(t, err, "should return error when extends is empty")
214214
assert.Nil(t, result, "should return nil node on error")
215215
assert.Contains(t, err.Error(), "overlay does not specify an extends URL", "error should mention missing extends")
216216
}
@@ -224,7 +224,7 @@ func TestLoadExtendsSpecification_Error_InvalidURL(t *testing.T) {
224224

225225
result, err := LoadExtendsSpecification(o)
226226

227-
assert.Error(t, err, "should return error for non-file URL")
227+
require.Error(t, err, "should return error for non-file URL")
228228
assert.Nil(t, result, "should return nil node on error")
229229
assert.Contains(t, err.Error(), "only file:// extends URLs are supported", "error should mention unsupported URL scheme")
230230
}
@@ -238,7 +238,7 @@ func TestLoadExtendsSpecification_Error_FileNotFound(t *testing.T) {
238238

239239
result, err := LoadExtendsSpecification(o)
240240

241-
assert.Error(t, err, "should return error for nonexistent file")
241+
require.Error(t, err, "should return error for nonexistent file")
242242
assert.Nil(t, result, "should return nil node on error")
243243
assert.Contains(t, err.Error(), "failed to open schema", "error should mention file opening failure")
244244
}
@@ -306,7 +306,7 @@ func TestLoadEitherSpecification_Error_NoPathNoExtends(t *testing.T) {
306306

307307
result, name, err := LoadEitherSpecification("", o)
308308

309-
assert.Error(t, err, "should return error when neither path nor extends provided")
309+
require.Error(t, err, "should return error when neither path nor extends provided")
310310
assert.Nil(t, result, "should return nil node on error")
311311
assert.Empty(t, name, "should return empty name on error")
312312
}
@@ -318,7 +318,7 @@ func TestLoadEitherSpecification_Error_InvalidPath(t *testing.T) {
318318

319319
result, name, err := LoadEitherSpecification("nonexistent-file.yaml", o)
320320

321-
assert.Error(t, err, "should return error for invalid path")
321+
require.Error(t, err, "should return error for invalid path")
322322
assert.Nil(t, result, "should return nil node on error")
323323
assert.Equal(t, "nonexistent-file.yaml", name, "should return attempted path as name")
324324
}

system/filesystem_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ func TestFileSystem_Open_Error(t *testing.T) {
4141
fsys := &FileSystem{}
4242
file, err := fsys.Open("nonexistent-file.txt")
4343

44-
assert.Error(t, err, "should return error for nonexistent file")
44+
require.Error(t, err, "should return error for nonexistent file")
4545
assert.Nil(t, file, "should return nil file on error")
4646
}
4747

0 commit comments

Comments
 (0)