test(01-04): cover config, lifecycle, services, events and context
- Table-driven compass precedence, malformed YAML, snake_case env and concurrent reads - Party duplicate/missing/cycle, reordered manifest, HasConfig/HasCommands discovery - Isolated backpack services, festival panic payload omission, towel nested isolation
This commit is contained in:
97
pact/capabilities_test.go
Normal file
97
pact/capabilities_test.go
Normal file
@@ -0,0 +1,97 @@
|
||||
package pact
|
||||
|
||||
import (
|
||||
"io/fs"
|
||||
"testing"
|
||||
"testing/fstest"
|
||||
|
||||
"git.golem15.com/golem15/summercms/bonfire"
|
||||
)
|
||||
|
||||
type configOnly struct{}
|
||||
|
||||
func (configOnly) ConfigFS() fs.FS {
|
||||
return fstest.MapFS{"config/config.yaml": {Data: []byte("k: 1\n")}}
|
||||
}
|
||||
|
||||
type commandsOnly struct{}
|
||||
|
||||
func (commandsOnly) Commands() []bonfire.Command {
|
||||
return []bonfire.Command{{Name: "demo:run"}}
|
||||
}
|
||||
|
||||
type bothCaps struct {
|
||||
configOnly
|
||||
commandsOnly
|
||||
}
|
||||
|
||||
type neither struct{}
|
||||
|
||||
func TestOptionalCapabilitiesDiscoveredByTypeAssertion(t *testing.T) {
|
||||
plugins := []any{configOnly{}, commandsOnly{}, bothCaps{}, neither{}, extraMessage{}}
|
||||
|
||||
var configs, commands, messages, none int
|
||||
for _, p := range plugins {
|
||||
_, hasCfg := p.(HasConfig)
|
||||
_, hasCmd := p.(HasCommands)
|
||||
_, hasMsg := p.(OptionalMessage)
|
||||
if hasCfg {
|
||||
configs++
|
||||
}
|
||||
if hasCmd {
|
||||
commands++
|
||||
}
|
||||
if hasMsg {
|
||||
messages++
|
||||
}
|
||||
if !hasCfg && !hasCmd && !hasMsg {
|
||||
none++
|
||||
}
|
||||
}
|
||||
if configs != 2 {
|
||||
t.Fatalf("HasConfig count = %d, want 2", configs)
|
||||
}
|
||||
if commands != 2 {
|
||||
t.Fatalf("HasCommands count = %d, want 2", commands)
|
||||
}
|
||||
if messages != 1 {
|
||||
t.Fatalf("OptionalMessage count = %d, want 1", messages)
|
||||
}
|
||||
if none != 1 {
|
||||
t.Fatalf("neither count = %d, want 1", none)
|
||||
}
|
||||
}
|
||||
|
||||
func TestHasConfigReturnsFilesystem(t *testing.T) {
|
||||
var p HasConfig = configOnly{}
|
||||
fsys := p.ConfigFS()
|
||||
if fsys == nil {
|
||||
t.Fatal("ConfigFS returned nil")
|
||||
}
|
||||
raw, err := fs.ReadFile(fsys, "config/config.yaml")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if string(raw) != "k: 1\n" {
|
||||
t.Fatalf("ConfigFS body = %q", raw)
|
||||
}
|
||||
}
|
||||
|
||||
func TestHasCommandsReturnsNamespacedCommand(t *testing.T) {
|
||||
var p HasCommands = commandsOnly{}
|
||||
cmds := p.Commands()
|
||||
if len(cmds) != 1 || cmds[0].Name != "demo:run" {
|
||||
t.Fatalf("Commands = %+v", cmds)
|
||||
}
|
||||
}
|
||||
|
||||
func TestOptionalMessageContract(t *testing.T) {
|
||||
var msg OptionalMessage = extraMessage{s: "hello-from-optional"}
|
||||
if msg.Message() != "hello-from-optional" {
|
||||
t.Fatalf("Message = %q", msg.Message())
|
||||
}
|
||||
}
|
||||
|
||||
type extraMessage struct{ s string }
|
||||
|
||||
func (e extraMessage) Message() string { return e.s }
|
||||
Reference in New Issue
Block a user