package check import ( "testing" "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-builder/buildrun" "git.novox.be/novox/mesh-sdk/go/seatdef" ) // The holders of the build seats in the tests' seat list: names the checker's code does not know, found by the seats' // acting rules (design 47 G A-82). const ( goBuildModule = "mesh-build-go" nodeBuildModule = "mesh-build-node" ) // testSeats is the finder over the build seats of the tests' seat list. func testSeats() *buildrun.BuildSeats { rule := func(on string) seatdef.Definition { return seatdef.Definition{Acts: []seatdef.ActingRule{{Step: seatdef.StepBuild, On: on}}} } defs := map[string]seatdef.Definition{"node-build-go": rule("go"), "node-build-node": rule("typescript")} holders := map[string]string{"node-build-go": goBuildModule, "node-build-node": nodeBuildModule} return buildrun.NewBuildSeats(func() map[string]seatdef.Definition { return defs }, func(seat string) (string, bool) { h, ok := holders[seat]; return h, ok }) } // stepStatesOf is a Reader's StepStates over fixed states. func stepStatesOf(m map[string]StateRead) func() map[string]StateRead { return func() map[string]StateRead { return m } } // The checker names no build module (design 47 G A-82): it finds each by the language its seat's acting rule builds, whatever the // holder is called, and says that holder's name in what it judges. func TestTheBuildModulesAreFoundOnTheSeatListWhateverTheyAreCalled(t *testing.T) { rule := func(on string) seatdef.Definition { return seatdef.Definition{Acts: []seatdef.ActingRule{{Step: seatdef.StepBuild, On: on}}} } defs := map[string]seatdef.Definition{"node-build-go": rule("go"), "node-build-node": rule("typescript"), "node-build-image": rule("kind:image")} holders := map[string]string{"node-build-go": "compilers", "node-build-node": "bundlers"} j := &Examiner{Seats: buildrun.NewBuildSeats(func() map[string]seatdef.Definition { return defs }, func(seat string) (string, bool) { h, ok := holders[seat]; return h, ok })} if got := j.goModule(); got != "compilers" { t.Errorf("the module that judges Go = %q, want its seat's holder", got) } if got, lang, ask := j.buildModuleOf(languageTypeScript), j.languageOf("bundlers"), j.askLanguageOf("bundlers"); got != "bundlers" || lang != languageTypeScript || ask != "node" { t.Errorf("TypeScript: module %q, language %q, ask language %q", got, lang, ask) } if got := j.languageOf("mesh-build-go"); got != "" { t.Errorf("a module that holds no build seat builds with %q", got) } if !changesBuildGo(catalogueRepository, "compilers", []string{"modules/compilers/main.go"}) || changesBuildGo(catalogueRepository, "compilers", []string{"modules/mesh-build-go/main.go"}) { t.Error("a change under the Go build module's own directory is the one that changes it") } // With no seat on the list the failure still names where it is: the seat. none := &Examiner{Seats: buildrun.NewBuildSeats(func() map[string]seatdef.Definition { return defs }, nil)} if got := none.goModule(); got != "node-build-go" { t.Errorf("a build seat no module holds is named by the seat, got %q", got) } }