60 lines
2.4 KiB
Go
60 lines
2.4 KiB
Go
package console
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"errors"
|
|
"strings"
|
|
"testing"
|
|
|
|
"git.novox.be/novox/mesh-sdk/go/views"
|
|
)
|
|
|
|
// viewer is a Source that also holds first views.
|
|
type viewer struct {
|
|
busSource
|
|
asked []string
|
|
}
|
|
|
|
func (v *viewer) Status() []views.Status {
|
|
return []views.Status{{Owner: "mesh-delivery-assigner", Tool: "placement", State: "placement", Revision: 4, Asks: 1}}
|
|
}
|
|
|
|
func (v *viewer) Again(_ context.Context, why string) []error {
|
|
v.asked = append(v.asked, why)
|
|
return nil
|
|
}
|
|
|
|
// issue 1966 TLS-6: the console's mesh_first_views shows each first view, mesh_first_view_again asks them again with its
|
|
// reason, and a source holding none refuses both in words.
|
|
func TestTheConsoleShowsAndAsksAgainTheRunnersFirstViews(t *testing.T) {
|
|
text := func(r map[string]any) string {
|
|
c, _ := json.Marshal(r["content"])
|
|
return string(c)
|
|
}
|
|
v := &viewer{}
|
|
var recorded []map[string]any
|
|
s := &Surface{src: v, who: "desk.node-tools", Record: func(a map[string]any) error { recorded = append(recorded, a); return nil }}
|
|
if got := text(s.discover(context.Background(), "mesh_first_views", nil)); !strings.Contains(got, "mesh-delivery-assigner") || !strings.Contains(got, "placement") {
|
|
t.Errorf("mesh_first_views shows %s", got)
|
|
}
|
|
got := s.discover(context.Background(), "mesh_first_view_again", map[string]any{"why": "doubted"})
|
|
if len(v.asked) != 1 || v.asked[0] != "doubted" || !strings.Contains(text(got), "asked again") {
|
|
t.Errorf("mesh_first_view_again asked %v and answered %s", v.asked, text(got))
|
|
}
|
|
if len(recorded) != 1 || recorded[0]["why"] != "doubted" || recorded[0]["cause"] != "first-view-again" {
|
|
t.Errorf("the hand act recorded is %v", recorded)
|
|
}
|
|
// An act that cannot be recorded is not done.
|
|
refusing := &Surface{src: v, who: "desk.node-tools", Record: func(map[string]any) error { return errors.New("no answer") }}
|
|
if r := refusing.discover(context.Background(), "mesh_first_view_again", map[string]any{"why": "x"}); r["isError"] != true || len(v.asked) != 1 {
|
|
t.Errorf("an unrecorded hand act was done: %s (asked %v)", text(r), v.asked)
|
|
}
|
|
for _, name := range []string{"mesh_first_views", "mesh_first_view_again"} {
|
|
none := &Surface{src: busSource{}, who: "desk.node-tools"}
|
|
if r := none.discover(context.Background(), name, nil); r["isError"] != true || !strings.Contains(text(r), "holds no first views") {
|
|
t.Errorf("%s without first views answers %s", name, text(r))
|
|
}
|
|
}
|
|
}
|