mirror of
https://github.com/jwetzell/showbridge-go.git
synced 2026-04-27 13:25:40 +00:00
add basic tests for bad module creation
This commit is contained in:
@@ -34,3 +34,75 @@ func TestNATSClientFromRegistry(t *testing.T) {
|
||||
t.Fatalf("nats.client module has wrong type: %s", moduleInstance.Type())
|
||||
}
|
||||
}
|
||||
|
||||
func TestBadNATSClient(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
params map[string]any
|
||||
errorString string
|
||||
}{
|
||||
{
|
||||
name: "no url param",
|
||||
params: map[string]any{
|
||||
"subject": "test/subject",
|
||||
},
|
||||
errorString: "nats.client requires a url parameter",
|
||||
},
|
||||
{
|
||||
name: "non-string url",
|
||||
params: map[string]any{
|
||||
"url": 123,
|
||||
"subject": "test/subject",
|
||||
},
|
||||
errorString: "nats.client url must be a string",
|
||||
},
|
||||
{
|
||||
name: "no subject param",
|
||||
params: map[string]any{
|
||||
"url": "nats://127.0.0.1:4222",
|
||||
},
|
||||
errorString: "nats.client requires a subject parameter",
|
||||
},
|
||||
{
|
||||
name: "non-string subject",
|
||||
params: map[string]any{
|
||||
"url": "nats://127.0.0.1:4222",
|
||||
"subject": 123,
|
||||
},
|
||||
errorString: "nats.client subject must be a string",
|
||||
},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
|
||||
registration, ok := module.ModuleRegistry["nats.client"]
|
||||
if !ok {
|
||||
t.Fatalf("nats.client module not registered")
|
||||
}
|
||||
|
||||
moduleInstance, err := registration.New(config.ModuleConfig{
|
||||
Id: "test",
|
||||
Type: "nats.client",
|
||||
Params: test.params,
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
if test.errorString != err.Error() {
|
||||
t.Fatalf("nats.client got error '%s', expected '%s'", err.Error(), test.errorString)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
err = moduleInstance.Start(t.Context())
|
||||
|
||||
if err == nil {
|
||||
t.Fatalf("nats.client expected to fail")
|
||||
}
|
||||
|
||||
if err.Error() != test.errorString {
|
||||
t.Fatalf("nats.client got error '%s', expected '%s'", err.Error(), test.errorString)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user