Public source validation / validate (push) Failing after 3m8s
29 lines
1.3 KiB
Go
29 lines
1.3 KiB
Go
package inventory
|
|
|
|
import (
|
|
"encoding/json"
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
func TestEffectiveValuesPreserveFactsAndPreferOverrides(t *testing.T) {
|
|
now := time.Date(2026, 8, 12, 1, 0, 0, 0, time.UTC)
|
|
facts := []FactView{
|
|
{FieldName: "image", SourceID: "primary", SourceName: "Unraid", Value: json.RawMessage(`"stable"`), ObservedAt: now, Confidence: 1},
|
|
{FieldName: "image", SourceID: "secondary", SourceName: "Agent", Value: json.RawMessage(`"older"`), ObservedAt: now.Add(-time.Hour), Confidence: .8},
|
|
{FieldName: "status", SourceID: "primary", SourceName: "Unraid", Value: json.RawMessage(`"running"`), ObservedAt: now, Confidence: 1},
|
|
}
|
|
overrides := []OverrideView{{FieldName: "image", Value: json.RawMessage(`"manual"`), UpdatedAt: now.Add(time.Minute)}}
|
|
|
|
effective := effectiveValues(facts, overrides)
|
|
if len(effective) != 2 || len(facts) != 3 {
|
|
t.Fatalf("effective=%d facts=%d", len(effective), len(facts))
|
|
}
|
|
if effective[0].FieldName != "image" || effective[0].Origin != "override" || string(effective[0].Value) != `"manual"` {
|
|
t.Fatalf("override did not win: %+v", effective[0])
|
|
}
|
|
if effective[1].FieldName != "status" || effective[1].Origin != "discovered" || effective[1].SourceName != "Unraid" {
|
|
t.Fatalf("discovered provenance lost: %+v", effective[1])
|
|
}
|
|
}
|