56 lines
1.7 KiB
Go
56 lines
1.7 KiB
Go
package main
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"os"
|
|
"path/filepath"
|
|
"slices"
|
|
"testing"
|
|
)
|
|
|
|
// Issues 1483 and 1488 (for the indexer, issue 1444): the guard emits toolchain.reported after each write of the
|
|
// toolchains key, with the node and the language.
|
|
func TestTheGuardEmitsToolchainReportedAfterEachWrite(t *testing.T) {
|
|
m := moduleWith(newStates(), "v26.10.0")
|
|
type event struct {
|
|
typ string
|
|
body map[string]string
|
|
}
|
|
var got []event
|
|
m.Emit = func(typ string, body any) error {
|
|
raw, _ := json.Marshal(body)
|
|
var b map[string]string
|
|
json.Unmarshal(raw, &b)
|
|
got = append(got, event{typ, b})
|
|
return nil
|
|
}
|
|
if err := m.Check(context.Background()); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if len(got) != 1 || got[0].typ != "toolchain.reported" || got[0].body["node"] != "ace" || got[0].body["language"] != "typescript" || len(got[0].body) != 2 {
|
|
t.Errorf("events = %+v, want one toolchain.reported for ace, typescript", got)
|
|
}
|
|
m.Check(context.Background())
|
|
if len(got) != 2 {
|
|
t.Errorf("a second guard pass emitted %d events in all, want 2", len(got))
|
|
}
|
|
}
|
|
|
|
// The event is carried by the module's stream, not named in emits (ADR 0363: one place); the validator checks that.
|
|
func TestTheManifestDeclaresTheToolchainsStream(t *testing.T) {
|
|
raw, err := os.ReadFile(filepath.Join("..", "..", "module.json"))
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
var m struct {
|
|
Streams []struct {
|
|
Name string `json:"name"`
|
|
Events []string `json:"events"`
|
|
} `json:"streams"`
|
|
}
|
|
if err := json.Unmarshal(raw, &m); err != nil || len(m.Streams) != 1 || m.Streams[0].Name != "toolchains-node" || !slices.Equal(m.Streams[0].Events, []string{"toolchain.**"}) {
|
|
t.Errorf("streams = %+v (%v)", m.Streams, err)
|
|
}
|
|
}
|