package activator import ( "context" "testing" ) func TestBuildStateLocationRidesTheContext(t *testing.T) { ctx := context.Background() if l, ok := BuildStateLocationFrom(ctx); ok { t.Fatalf("a bare context carries %+v", l) } want := BuildStateLocation{Bucket: "data-eu", Prefix: "instances/a.example.com/inc1"} got, ok := BuildStateLocationFrom(WithBuildStateLocation(ctx, want)) if !ok || got != want { t.Fatalf("got %+v, %v; want %+v", got, ok, want) } } // A zero location is no location: it is how a caller that serves many // hosts (the agent's refreshAll) masks one a wake left on its context. func TestAnEmptyBuildStateLocationIsNone(t *testing.T) { ctx := WithBuildStateLocation(context.Background(), BuildStateLocation{Bucket: "b", Prefix: "p"}) for _, l := range []BuildStateLocation{{}, {Bucket: "b"}, {Prefix: "p"}} { if got, ok := BuildStateLocationFrom(WithBuildStateLocation(ctx, l)); ok { t.Fatalf("%+v read back as %+v", l, got) } } }