Go 69 lines
package memory
import (
"strings"
"testing"
"time"
)
// Validate residual branches: the nil-receiver guard and the
// required-field checks that the happy-path tests never trip.
func TestValidate_NilFact(t *testing.T) {
var f *Fact
err := f.Validate()
if err == nil {
t.Fatal("expected nil fact to error")
}
if !strings.Contains(err.Error(), "fact is nil") {
t.Errorf("err = %v, want substring fact is nil", err)
}
}
func TestValidate_CreatedZero(t *testing.T) {
f := &Fact{Name: "a", Description: "b", Type: TypeUser}
err := f.Validate()
if err == nil {
t.Fatal("expected zero created to error")
}
if !strings.Contains(err.Error(), "created is required") {
t.Errorf("err = %v, want substring created is required", err)
}
}
func TestValidate_LastUsedZero(t *testing.T) {
f := &Fact{
Name: "a",
Description: "b",
Type: TypeUser,
Created: time.Date(2026, 5, 19, 0, 0, 0, 0, time.UTC),
}
err := f.Validate()
if err == nil {
t.Fatal("expected zero last_used to error")
}
if !strings.Contains(err.Error(), "last_used is required") {
t.Errorf("err = %v, want substring last_used is required", err)
}
}
func TestValidate_FindingBadStatus(t *testing.T) {
f := makeFact("f", "d", TypeFinding, withStatus("bogus"))
err := f.Validate()
if err == nil {
t.Fatal("expected bad finding status to error")
}
if !strings.Contains(err.Error(), "finding status must be open or resolved") {
t.Errorf("err = %v, want substring about finding status", err)
}
}
func TestValidateRef_EmptyDirect(t *testing.T) {
// validateRef("") is unreachable through Validate (which guards
// f.Ref != ""); call it directly to pin that the empty-ref guard
// returns nil rather than erroring.
if err := validateRef(""); err != nil {
t.Errorf("validateRef(\"\") = %v, want nil", err)
}
}