Skip to content

Commit 8a43c78

Browse files
committed
Address Copilot review: precise assertions, guarded type checks, fix comment
- visitor_lint_test.go: assert Target.Name and Target.Module separately to prevent false positives - visitor_widgets_test.go: use guarded type assertion with len check instead of direct assertion that would panic - mock_page_mutator.go: clarify doc comment that ContainerType defaults to ContainerPage, not zero value
1 parent ad2c0e5 commit 8a43c78

3 files changed

Lines changed: 14 additions & 5 deletions

File tree

mdl/backend/mock/mock_page_mutator.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ var _ backend.PageMutator = (*MockPageMutator)(nil)
1212

1313
// MockPageMutator implements backend.PageMutator. Every interface method is
1414
// backed by a public function field. If the field is nil the method returns
15-
// zero values / nil error (never panics).
15+
// nil error (never panics). ContainerType defaults to ContainerPage when unset;
16+
// all other methods return zero values.
1617
type MockPageMutator struct {
1718
ContainerTypeFunc func() backend.ContainerKind
1819
SetWidgetPropertyFunc func(widgetRef string, prop string, value any) error

mdl/visitor/visitor_lint_test.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,11 @@ func TestLint_ModuleOnly(t *testing.T) {
4545
if stmt.Target == nil {
4646
t.Fatal("Expected non-nil Target")
4747
}
48-
// For "LINT MyModule.*", qualifiedName is just "MyModule" (no module prefix)
49-
if stmt.Target.Name != "MyModule" && stmt.Target.Module != "MyModule" {
50-
t.Errorf("Target mismatch: got Module=%q Name=%q", stmt.Target.Module, stmt.Target.Name)
48+
if stmt.Target.Name != "MyModule" {
49+
t.Errorf("Expected Target.Name %q, got %q", "MyModule", stmt.Target.Name)
50+
}
51+
if stmt.Target.Module != "" {
52+
t.Errorf("Expected Target.Module %q, got %q", "", stmt.Target.Module)
5153
}
5254
}
5355

mdl/visitor/visitor_widgets_test.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,13 @@ func TestUpdateWidgets_DryRun(t *testing.T) {
4444
}
4545
return
4646
}
47-
stmt := prog.Statements[0].(*ast.UpdateWidgetsStmt)
47+
if len(prog.Statements) == 0 {
48+
t.Fatal("Expected at least one statement")
49+
}
50+
stmt, ok := prog.Statements[0].(*ast.UpdateWidgetsStmt)
51+
if !ok {
52+
t.Fatalf("Expected *ast.UpdateWidgetsStmt, got %T", prog.Statements[0])
53+
}
4854
if !stmt.DryRun {
4955
t.Error("Expected DryRun true")
5056
}

0 commit comments

Comments
 (0)