test(01-04): cover config, lifecycle, services, events and context
- Table-driven compass precedence, malformed YAML, snake_case env and concurrent reads - Party duplicate/missing/cycle, reordered manifest, HasConfig/HasCommands discovery - Isolated backpack services, festival panic payload omission, towel nested isolation
This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
||||
"context"
|
||||
"os"
|
||||
"strings"
|
||||
"sync"
|
||||
"testing"
|
||||
)
|
||||
|
||||
@@ -33,6 +34,85 @@ func TestContextAccessorsRoundTrip(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestNestedContextIsolation(t *testing.T) {
|
||||
parent := WithActor(context.Background(), "parent")
|
||||
parent = WithOrganization(parent, "org-parent")
|
||||
child := WithActor(parent, "child")
|
||||
child = WithCollection(child, "col-child")
|
||||
child = WithLocale(child, "pl")
|
||||
|
||||
if got, ok := Actor(parent); !ok || got != "parent" {
|
||||
t.Fatalf("parent Actor mutated: (%q, %v)", got, ok)
|
||||
}
|
||||
if got, ok := Actor(child); !ok || got != "child" {
|
||||
t.Fatalf("child Actor = (%q, %v)", got, ok)
|
||||
}
|
||||
if got, ok := Organization(child); !ok || got != "org-parent" {
|
||||
t.Fatalf("child should inherit organization, got (%q, %v)", got, ok)
|
||||
}
|
||||
if _, ok := Collection(parent); ok {
|
||||
t.Fatal("collection leaked to parent")
|
||||
}
|
||||
if _, ok := Locale(parent); ok {
|
||||
t.Fatal("locale leaked to parent")
|
||||
}
|
||||
if got, ok := Collection(child); !ok || got != "col-child" {
|
||||
t.Fatalf("child Collection = (%q, %v)", got, ok)
|
||||
}
|
||||
}
|
||||
|
||||
func TestNilContextAccessors(t *testing.T) {
|
||||
if _, ok := Actor(nil); ok {
|
||||
t.Fatal("Actor(nil) should be absent")
|
||||
}
|
||||
if _, ok := Organization(nil); ok {
|
||||
t.Fatal("Organization(nil) should be absent")
|
||||
}
|
||||
if _, ok := Collection(nil); ok {
|
||||
t.Fatal("Collection(nil) should be absent")
|
||||
}
|
||||
if _, ok := Locale(nil); ok {
|
||||
t.Fatal("Locale(nil) should be absent")
|
||||
}
|
||||
ctx := WithActor(nil, "user-1")
|
||||
if got, ok := Actor(ctx); !ok || got != "user-1" {
|
||||
t.Fatalf("WithActor(nil) = (%q, %v)", got, ok)
|
||||
}
|
||||
}
|
||||
|
||||
func TestConcurrentContextAccessors(t *testing.T) {
|
||||
ctx := WithActor(context.Background(), "user-1")
|
||||
ctx = WithOrganization(ctx, "org-9")
|
||||
ctx = WithCollection(ctx, "col-3")
|
||||
ctx = WithLocale(ctx, "pl")
|
||||
var wg sync.WaitGroup
|
||||
for i := 0; i < 16; i++ {
|
||||
wg.Add(1)
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
for j := 0; j < 80; j++ {
|
||||
if got, ok := Actor(ctx); !ok || got != "user-1" {
|
||||
t.Errorf("Actor = (%q, %v)", got, ok)
|
||||
return
|
||||
}
|
||||
if got, ok := Organization(ctx); !ok || got != "org-9" {
|
||||
t.Errorf("Organization = (%q, %v)", got, ok)
|
||||
return
|
||||
}
|
||||
if got, ok := Collection(ctx); !ok || got != "col-3" {
|
||||
t.Errorf("Collection = (%q, %v)", got, ok)
|
||||
return
|
||||
}
|
||||
if got, ok := Locale(ctx); !ok || got != "pl" {
|
||||
t.Errorf("Locale = (%q, %v)", got, ok)
|
||||
return
|
||||
}
|
||||
}
|
||||
}()
|
||||
}
|
||||
wg.Wait()
|
||||
}
|
||||
|
||||
func TestNoPackageGlobalRequestState(t *testing.T) {
|
||||
entries, err := os.ReadDir(".")
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user