Files
ITWorx-Pulse-Public/internal/inventory/readmodel_test.go
T
ITWorx Pulse release export bd774932d5
Public source validation / validate (push) Failing after 3m8s
Publish ITWorx Pulse source
2026-09-03 02:09:19 +02:00

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])
}
}