Merge pull request 'Two tests that main broke: bus users after issue 195, and the event consumer made from now (issue 248)' (#52) from fix/the-bus-user-test-follows-issue-195 into main
This commit was merged in pull request #52.
This commit is contained in:
@@ -42,26 +42,37 @@ func theSeatDeclarer() catalogue.Manifest {
|
|||||||
// A module assigned to a machine becomes a user with the authority its manifest declared — and the
|
// A module assigned to a machine becomes a user with the authority its manifest declared — and the
|
||||||
// protocol of a seat declared by a *different* module, which is the whole reason a seat exists.
|
// protocol of a seat declared by a *different* module, which is the whole reason a seat exists.
|
||||||
func TestAnAssignedModuleBecomesAUserWithWhatItDeclared(t *testing.T) {
|
func TestAnAssignedModuleBecomesAUserWithWhatItDeclared(t *testing.T) {
|
||||||
|
// It declares where its account is delivered: a module with no own secret named broker can never
|
||||||
|
// be issued one, and is no user at all (novox/hq issue 195) — the case asserted below.
|
||||||
shop := catalogue.Manifest{
|
shop := catalogue.Manifest{
|
||||||
Module: "shop", Version: "1",
|
Module: "shop", Version: "1",
|
||||||
Emits: []string{"order.placed"}, Tools: []string{"price"},
|
Emits: []string{"order.placed"}, Tools: []string{"price"},
|
||||||
Uses: []string{"telegram-sender"},
|
Uses: []string{"telegram-sender"},
|
||||||
|
OwnSecrets: catalogue.OwnSecrets{"broker": {Path: "/run/broker"}},
|
||||||
}
|
}
|
||||||
inv, ctx := aMeshWith(t, theSeatDeclarer(), shop)
|
quiet := catalogue.Manifest{Module: "quiet", Version: "1", Emits: []string{"thing.happened"}}
|
||||||
|
inv, ctx := aMeshWith(t, theSeatDeclarer(), shop, quiet)
|
||||||
if _, err := inv.AddNode(ctx, "one"); err != nil {
|
if _, err := inv.AddNode(ctx, "one"); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
if _, err := inv.Assign(ctx, "one", "shop"); err != nil {
|
for _, module := range []string{"shop", "quiet"} {
|
||||||
t.Fatal(err)
|
if _, err := inv.Assign(ctx, "one", module); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
records, err := inv.BusRecords(ctx)
|
records, err := inv.BusRecords(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
on := records.Assigned["one"]
|
var on []broker.Declared
|
||||||
if len(on) != 1 || on[0].Module != "shop" {
|
for _, d := range records.Assigned["one"] {
|
||||||
t.Fatalf("the machine's modules read as %+v", on)
|
if d.Module == "shop" {
|
||||||
|
on = append(on, d)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if len(on) != 1 || on[0].NoAccount {
|
||||||
|
t.Fatalf("the machine's modules read as %+v", records.Assigned["one"])
|
||||||
}
|
}
|
||||||
if len(on[0].Uses) != 1 || on[0].Uses[0].Accepts[0] != "send" {
|
if len(on[0].Uses) != 1 || on[0].Uses[0].Accepts[0] != "send" {
|
||||||
t.Fatalf("the seat it uses carries no protocol: %+v — so it would be granted nothing on a "+
|
t.Fatalf("the seat it uses carries no protocol: %+v — so it would be granted nothing on a "+
|
||||||
@@ -98,6 +109,11 @@ func TestAnAssignedModuleBecomesAUserWithWhatItDeclared(t *testing.T) {
|
|||||||
if !found {
|
if !found {
|
||||||
t.Fatal("no user was derived for the assigned module")
|
t.Fatal("no user was derived for the assigned module")
|
||||||
}
|
}
|
||||||
|
for _, u := range users {
|
||||||
|
if u.Username() == "one.quiet" {
|
||||||
|
t.Fatal("a module with nowhere to read an account was made a user (novox/hq issue 195)")
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// A machine holding a live token gets an enrolment user; one whose token is spent or expired does
|
// A machine holding a live token gets an enrolment user; one whose token is spent or expired does
|
||||||
|
|||||||
@@ -315,6 +315,12 @@ func TestNatsTheEventsTheControllerFollowsArriveAndAreAcknowledged(t *testing.T)
|
|||||||
ctx, stop := context.WithCancel(context.Background())
|
ctx, stop := context.WithCancel(context.Background())
|
||||||
defer stop()
|
defer stop()
|
||||||
go func() { _ = s.Serve(ctx) }()
|
go func() { _ = s.Serve(ctx) }()
|
||||||
|
// The controller's event consumer is made from now (novox/hq issue 248): what was published before
|
||||||
|
// it existed is history it never replays. So the announcements are made once it is there.
|
||||||
|
eventually(t, "the controller's event consumer being made", func() bool {
|
||||||
|
_, err := js.Context().ConsumerInfo("EVENTS", broker.ControllerName)
|
||||||
|
return err == nil
|
||||||
|
})
|
||||||
|
|
||||||
moved, _ := json.Marshal(Upgraded{Module: "gitea", Commit: "abcdef0123"})
|
moved, _ := json.Marshal(Upgraded{Module: "gitea", Commit: "abcdef0123"})
|
||||||
if _, err := js.Context().Publish(broker.ControllerFollows[0], moved); err != nil {
|
if _, err := js.Context().Publish(broker.ControllerFollows[0], moved); err != nil {
|
||||||
|
|||||||
Reference in New Issue
Block a user