package store import ( "testing" "time" ) func TestRenderInputsSemanticHashCanonicalAndIgnoresFetchState(t *testing.T) { now := time.Now().UTC() a := &RenderInputs{TenantID: "tenant", Modules: []RenderModule{ {Module: &Module{ID: "b", Type: "CDN_CIDRS", Enabled: true}, CDNSources: []*CDNSource{{ID: "s2", URL: "https://b.test", Etag: "old"}, {ID: "s1", URL: "https://a.test", LastRefreshedAt: &now}}}, {Module: &Module{ID: "a", Type: "IP_RANGES", Enabled: true}, IPRanges: []*IPRangeEntry{{ID: "r2", Prefix: "192.0.2.0/24"}, {ID: "r1", Prefix: "198.51.100.0/24"}}}, }} b := &RenderInputs{TenantID: "tenant", Generation: 99, Modules: []RenderModule{ {Module: &Module{ID: "a", Type: "IP_RANGES", Enabled: true}, IPRanges: []*IPRangeEntry{{ID: "r1", Prefix: "198.51.100.0/24"}, {ID: "r2", Prefix: "192.0.2.0/24"}}}, {Module: &Module{ID: "b", Type: "CDN_CIDRS", Enabled: true}, CDNSources: []*CDNSource{{ID: "s1", URL: "https://a.test"}, {ID: "s2", URL: "https://b.test", Etag: "new"}}}, }} ha, err := a.SemanticHash() if err != nil { t.Fatal(err) } hb, err := b.SemanticHash() if err != nil { t.Fatal(err) } if ha != hb { t.Fatalf("same semantic inputs have different hashes: %s %s", ha, hb) } b.Modules[1].CDNSources[0].URL = "https://changed.test" hb, err = b.SemanticHash() if err != nil { t.Fatal(err) } if ha == hb { t.Fatal("source URL change did not change hash") } }