Skip to content

Commit abd06e9

Browse files
committed
fix: check errors in test helpers and simplify nil-reader tests
Address Copilot review comments on PR mendixlabs#255: - Check INSERT OR IGNORE error in setupMicroflowsDB (empty_test.go) - Check INSERT OR IGNORE error in setupEntitiesDB (domain_size_test.go) - Pass nil db directly in SEC002/SEC003 nil-reader tests (security_test.go) - Remove unused sql/sqlite imports from security_test.go
1 parent dde5320 commit abd06e9

3 files changed

Lines changed: 8 additions & 13 deletions

File tree

mdl/linter/rules/domain_size_test.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,9 @@ func setupEntitiesDB(t *testing.T, entities [][]any) *sql.DB {
4242
t.Fatalf("failed to insert entity: %v", err)
4343
}
4444
moduleName := row[3].(string)
45-
db.Exec(`INSERT OR IGNORE INTO modules (Name, Source) VALUES (?, '')`, moduleName)
45+
if _, err := db.Exec(`INSERT OR IGNORE INTO modules (Name, Source) VALUES (?, '')`, moduleName); err != nil {
46+
t.Fatalf("failed to insert module: %v", err)
47+
}
4648
}
4749

4850
return db

mdl/linter/rules/empty_test.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,9 @@ func setupMicroflowsDB(t *testing.T, rows [][]any) *sql.DB {
4242
}
4343
// Ensure module exists
4444
moduleName := row[3].(string)
45-
db.Exec(`INSERT OR IGNORE INTO modules (Name, Source) VALUES (?, '')`, moduleName)
45+
if _, err := db.Exec(`INSERT OR IGNORE INTO modules (Name, Source) VALUES (?, '')`, moduleName); err != nil {
46+
t.Fatalf("failed to insert module: %v", err)
47+
}
4648
}
4749

4850
return db

mdl/linter/rules/security_test.go

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,9 @@
33
package rules
44

55
import (
6-
"database/sql"
76
"testing"
87

98
"github.com/mendixlabs/mxcli/mdl/linter"
10-
11-
_ "modernc.org/sqlite"
129
)
1310

1411
func TestNoEntityAccessRulesRule_NoViolation(t *testing.T) {
@@ -93,10 +90,7 @@ func TestNoEntityAccessRulesRule_Metadata(t *testing.T) {
9390
// Full behavioral coverage requires integration tests with a real .mpr project.
9491

9592
func TestWeakPasswordPolicyRule_NilReader(t *testing.T) {
96-
db, _ := sql.Open("sqlite", ":memory:")
97-
defer db.Close()
98-
99-
ctx := linter.NewLintContextFromDB(db)
93+
ctx := linter.NewLintContextFromDB(nil)
10094
rule := NewWeakPasswordPolicyRule()
10195
violations := rule.Check(ctx)
10296

@@ -116,10 +110,7 @@ func TestWeakPasswordPolicyRule_Metadata(t *testing.T) {
116110
}
117111

118112
func TestDemoUsersActiveRule_NilReader(t *testing.T) {
119-
db, _ := sql.Open("sqlite", ":memory:")
120-
defer db.Close()
121-
122-
ctx := linter.NewLintContextFromDB(db)
113+
ctx := linter.NewLintContextFromDB(nil)
123114
rule := NewDemoUsersActiveRule()
124115
violations := rule.Check(ctx)
125116

0 commit comments

Comments
 (0)