forked from longtao.wu/droboticflow
55 lines
2.0 KiB
Go
55 lines
2.0 KiB
Go
package store
|
|
|
|
import (
|
|
"droboticflow/internal/domain"
|
|
"errors"
|
|
"testing"
|
|
)
|
|
|
|
func TestQueryReplicaCandidateCachePrivateMetadataAndIsolation(t *testing.T) {
|
|
original := domain.HumanItemRecord{ID: "i", LegacyAssignment: map[string]string{"role": "u"}, AccountHandoff: &domain.AccountTaskHandoff{Pending: true}, AcceptanceClaim: &domain.AcceptanceClaimAccess{UserID: "u", SupplierID: "s"}, Subject: domain.HumanSubjectRef{Payload: map[string]any{"annotationDraft": "never copy"}}}
|
|
safe := cloneQueryCountRow(original)
|
|
raw, e := encodeQueryCountRows([]domain.HumanItemRecord{safe})
|
|
if e != nil {
|
|
t.Fatal(e)
|
|
}
|
|
rows, e := decodeQueryCountRows(raw)
|
|
if e != nil || len(rows) != 1 {
|
|
t.Fatal(e)
|
|
}
|
|
if rows[0].Subject.Payload != nil || !rows[0].AccountHandoff.Pending || rows[0].AcceptanceClaim.UserID != "u" {
|
|
t.Fatal("private eligibility metadata lost")
|
|
}
|
|
private := cloneQueryCountRow(rows[0])
|
|
private.AcceptanceClaim.SupplierID = "other"
|
|
private.AccountHandoff.Pending = false
|
|
private.LegacyAssignment["role"] = "other"
|
|
if rows[0].AcceptanceClaim.SupplierID != "s" || !rows[0].AccountHandoff.Pending || rows[0].LegacyAssignment["role"] != "u" {
|
|
t.Fatal("caller modified cached data")
|
|
}
|
|
if _, e = decodeQueryCountRows([]byte("invalid-cache")); e == nil {
|
|
t.Fatal("corrupt shared cache accepted")
|
|
}
|
|
}
|
|
|
|
func TestQueryReplicaMissingConfigurationCannotPanicCoreCache(t *testing.T) {
|
|
t.Setenv("QUERY_REPLICA_REPORTS", "1")
|
|
t.Setenv("QUERY_REPLICA_POOLS", "1")
|
|
t.Setenv("QUERY_SOURCE_TRACKING", "0")
|
|
s := &MongoStore{}
|
|
close, e := s.ConfigureQueryReplicaFromEnvironment(t.Context())
|
|
defer close()
|
|
if e == nil {
|
|
t.Fatal("serving without write tracking accepted")
|
|
}
|
|
if _, e = s.poolReplica(WithQueryReplicaPoolRead(t.Context())); !errors.Is(e, ErrQueryReplicaNotReady) {
|
|
t.Fatal("invalid query configuration fell back to source pool", e)
|
|
}
|
|
if s.SharedQueryCache() != nil {
|
|
t.Fatal("invalid replica returned source cache")
|
|
}
|
|
if _, e = s.reportReplica(t.Context()); !errors.Is(e, ErrQueryReplicaNotReady) {
|
|
t.Fatal(e)
|
|
}
|
|
}
|