85 lines
2.4 KiB
Go
85 lines
2.4 KiB
Go
package pflichttestgate
|
|
|
|
import "testing"
|
|
|
|
// Prüfung 1 (QA-01): CI-Lauf mit absichtlich fehlendem Pflichttest schlägt kontrolliert fehl —
|
|
// Negativtest des Gates selbst.
|
|
func TestCheckDiff_BlocksAuthChangeWithoutTest(t *testing.T) {
|
|
changed := []string{
|
|
"internal/auth/login.go",
|
|
"internal/apiserver/handler.go", // unkritisch, keine Testpflicht
|
|
}
|
|
|
|
violations := CheckDiff(changed)
|
|
|
|
if len(violations) != 1 {
|
|
t.Fatalf("erwartet 1 Verstoß, bekommen %d: %+v", len(violations), violations)
|
|
}
|
|
if violations[0].Package != "internal/auth" {
|
|
t.Errorf("erwartetes Package internal/auth, bekommen %q", violations[0].Package)
|
|
}
|
|
if violations[0].ChangedFile != "internal/auth/login.go" {
|
|
t.Errorf("erwartete Datei internal/auth/login.go, bekommen %q", violations[0].ChangedFile)
|
|
}
|
|
}
|
|
|
|
func TestCheckDiff_PassesWhenTestFileAccompaniesChange(t *testing.T) {
|
|
changed := []string{
|
|
"internal/auth/login.go",
|
|
"internal/auth/login_test.go",
|
|
}
|
|
|
|
violations := CheckDiff(changed)
|
|
|
|
if len(violations) != 0 {
|
|
t.Fatalf("erwartet keinen Verstoß, bekommen %+v", violations)
|
|
}
|
|
}
|
|
|
|
func TestCheckDiff_PassesForNewTestFileEvenWithoutSourceChange(t *testing.T) {
|
|
// Nachtraeglich ergaenzter Test fuer bestehenden Code ist erlaubt/erwuenscht.
|
|
changed := []string{"internal/tenant/registry_test.go"}
|
|
|
|
violations := CheckDiff(changed)
|
|
|
|
if len(violations) != 0 {
|
|
t.Fatalf("erwartet keinen Verstoß, bekommen %+v", violations)
|
|
}
|
|
}
|
|
|
|
func TestCheckDiff_IgnoresUnrelatedPackages(t *testing.T) {
|
|
changed := []string{"internal/config/config.go", "internal/db/db.go"}
|
|
|
|
violations := CheckDiff(changed)
|
|
|
|
if len(violations) != 0 {
|
|
t.Fatalf("erwartet keinen Verstoß fuer unkritische Pakete, bekommen %+v", violations)
|
|
}
|
|
}
|
|
|
|
func TestCheckDiff_CoversAllSensitiveAreas(t *testing.T) {
|
|
cases := []string{
|
|
"internal/auth/session.go",
|
|
"internal/iam/user.go",
|
|
"internal/tenant/provisioner.go",
|
|
"internal/rbac/enforcer.go",
|
|
"internal/policy/decision.go",
|
|
}
|
|
for _, f := range cases {
|
|
violations := CheckDiff([]string{f})
|
|
if len(violations) != 1 {
|
|
t.Errorf("Datei %q sollte als sensibel erkannt werden, Verstöße: %+v", f, violations)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestCheckDiff_IgnoresNonGoFiles(t *testing.T) {
|
|
changed := []string{"internal/auth/README.md"}
|
|
|
|
violations := CheckDiff(changed)
|
|
|
|
if len(violations) != 0 {
|
|
t.Fatalf("Nicht-Go-Dateien duerfen keine Testpflicht ausloesen, bekommen %+v", violations)
|
|
}
|
|
}
|