announcetest.Check starts the module against a bus of the test's own and holds its announcement equal to what its code declares; testbus leaves internal/ so a module's own integration tests can start it.
33 lines
1.1 KiB
Go
33 lines
1.1 KiB
Go
package announcetest
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
|
|
"git.novox.be/novox/mesh-sdk/go/announce"
|
|
)
|
|
|
|
// The comparison is exact up to order: a state missing, one extra, a readability that differs or another module's
|
|
// announcement each fail, naming what differs.
|
|
func TestAnAnnouncementDiffersFromTheCodeByNameAndReadability(t *testing.T) {
|
|
got := announce.States{Module: "m", States: []announce.State{{Name: "a", Readable: true}, {Name: "b"}}}
|
|
if p := differs(got, "m", []announce.State{{Name: "b"}, {Name: "a", Readable: true}}); p != "" {
|
|
t.Fatalf("an equal announcement differs: %s", p)
|
|
}
|
|
for _, want := range [][]announce.State{
|
|
{{Name: "a", Readable: true}},
|
|
{{Name: "a", Readable: true}, {Name: "b"}, {Name: "c"}},
|
|
{{Name: "a"}, {Name: "b"}},
|
|
} {
|
|
if p := differs(got, "m", want); p == "" || !strings.Contains(p, "declares") {
|
|
t.Errorf("want %v: %q", want, p)
|
|
}
|
|
}
|
|
if p := differs(got, "other", nil); !strings.Contains(p, `"other"`) {
|
|
t.Errorf("another module's announcement: %q", p)
|
|
}
|
|
if p := differs(announce.States{Module: "m"}, "m", nil); p != "" {
|
|
t.Errorf("a module keeping nothing: %q", p)
|
|
}
|
|
}
|