mirror of
https://github.com/jwetzell/showbridge-go.git
synced 2026-04-27 13:25:40 +00:00
add test for loading from registry for all modules
This commit is contained in:
27
internal/module/test/http-client_test.go
Normal file
27
internal/module/test/http-client_test.go
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
package module_test
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/jwetzell/showbridge-go/internal/config"
|
||||||
|
"github.com/jwetzell/showbridge-go/internal/module"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestHTTPClientFromRegistry(t *testing.T) {
|
||||||
|
registration, ok := module.ModuleRegistry["http.client"]
|
||||||
|
if !ok {
|
||||||
|
t.Fatalf("http.client module not registered")
|
||||||
|
}
|
||||||
|
|
||||||
|
moduleInstance, err := registration.New(config.ModuleConfig{
|
||||||
|
Type: "http.client",
|
||||||
|
})
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("failed to create http.client module: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if moduleInstance.Type() != "http.client" {
|
||||||
|
t.Fatalf("http.client module has wrong type: %s", moduleInstance.Type())
|
||||||
|
}
|
||||||
|
}
|
||||||
30
internal/module/test/http-server_test.go
Normal file
30
internal/module/test/http-server_test.go
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
package module_test
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/jwetzell/showbridge-go/internal/config"
|
||||||
|
"github.com/jwetzell/showbridge-go/internal/module"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestHTTPServerFromRegistry(t *testing.T) {
|
||||||
|
registration, ok := module.ModuleRegistry["http.server"]
|
||||||
|
if !ok {
|
||||||
|
t.Fatalf("http.server module not registered")
|
||||||
|
}
|
||||||
|
|
||||||
|
moduleInstance, err := registration.New(config.ModuleConfig{
|
||||||
|
Type: "http.server",
|
||||||
|
Params: map[string]any{
|
||||||
|
"port": 3000.0,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("failed to create http.server module: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if moduleInstance.Type() != "http.server" {
|
||||||
|
t.Fatalf("http.server module has wrong type: %s", moduleInstance.Type())
|
||||||
|
}
|
||||||
|
}
|
||||||
30
internal/module/test/midi-input_test.go
Normal file
30
internal/module/test/midi-input_test.go
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
package module_test
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/jwetzell/showbridge-go/internal/config"
|
||||||
|
"github.com/jwetzell/showbridge-go/internal/module"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestMIDIInputFromRegistry(t *testing.T) {
|
||||||
|
registration, ok := module.ModuleRegistry["midi.input"]
|
||||||
|
if !ok {
|
||||||
|
t.Fatalf("midi.input module not registered")
|
||||||
|
}
|
||||||
|
|
||||||
|
moduleInstance, err := registration.New(config.ModuleConfig{
|
||||||
|
Type: "midi.input",
|
||||||
|
Params: map[string]any{
|
||||||
|
"port": "test",
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("failed to create midi.input module: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if moduleInstance.Type() != "midi.input" {
|
||||||
|
t.Fatalf("midi.input module has wrong type: %s", moduleInstance.Type())
|
||||||
|
}
|
||||||
|
}
|
||||||
30
internal/module/test/midi-output_test.go
Normal file
30
internal/module/test/midi-output_test.go
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
package module_test
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/jwetzell/showbridge-go/internal/config"
|
||||||
|
"github.com/jwetzell/showbridge-go/internal/module"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestMIDIOutputFromRegistry(t *testing.T) {
|
||||||
|
registration, ok := module.ModuleRegistry["midi.output"]
|
||||||
|
if !ok {
|
||||||
|
t.Fatalf("midi.output module not registered")
|
||||||
|
}
|
||||||
|
|
||||||
|
moduleInstance, err := registration.New(config.ModuleConfig{
|
||||||
|
Type: "midi.output",
|
||||||
|
Params: map[string]any{
|
||||||
|
"port": "test",
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("failed to create midi.output module: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if moduleInstance.Type() != "midi.output" {
|
||||||
|
t.Fatalf("midi.output module has wrong type: %s", moduleInstance.Type())
|
||||||
|
}
|
||||||
|
}
|
||||||
32
internal/module/test/mqtt-client_test.go
Normal file
32
internal/module/test/mqtt-client_test.go
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
package module_test
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/jwetzell/showbridge-go/internal/config"
|
||||||
|
"github.com/jwetzell/showbridge-go/internal/module"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestMQTTClientFromRegistry(t *testing.T) {
|
||||||
|
registration, ok := module.ModuleRegistry["mqtt.client"]
|
||||||
|
if !ok {
|
||||||
|
t.Fatalf("mqtt.client module not registered")
|
||||||
|
}
|
||||||
|
|
||||||
|
moduleInstance, err := registration.New(config.ModuleConfig{
|
||||||
|
Type: "mqtt.client",
|
||||||
|
Params: map[string]any{
|
||||||
|
"broker": "mqtt://localhost:1883",
|
||||||
|
"topic": "test/topic",
|
||||||
|
"clientId": "test",
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("failed to create mqtt.client module: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if moduleInstance.Type() != "mqtt.client" {
|
||||||
|
t.Fatalf("mqtt.client module has wrong type: %s", moduleInstance.Type())
|
||||||
|
}
|
||||||
|
}
|
||||||
31
internal/module/test/nats-client_test.go
Normal file
31
internal/module/test/nats-client_test.go
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
package module_test
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/jwetzell/showbridge-go/internal/config"
|
||||||
|
"github.com/jwetzell/showbridge-go/internal/module"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestNATSClientFromRegistry(t *testing.T) {
|
||||||
|
registration, ok := module.ModuleRegistry["nats.client"]
|
||||||
|
if !ok {
|
||||||
|
t.Fatalf("nats.client module not registered")
|
||||||
|
}
|
||||||
|
|
||||||
|
moduleInstance, err := registration.New(config.ModuleConfig{
|
||||||
|
Type: "nats.client",
|
||||||
|
Params: map[string]any{
|
||||||
|
"url": "nats://127.0.0.1:4222",
|
||||||
|
"subject": "test",
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("failed to create nats.client module: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if moduleInstance.Type() != "nats.client" {
|
||||||
|
t.Fatalf("nats.client module has wrong type: %s", moduleInstance.Type())
|
||||||
|
}
|
||||||
|
}
|
||||||
27
internal/module/test/psn-client_test.go
Normal file
27
internal/module/test/psn-client_test.go
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
package module_test
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/jwetzell/showbridge-go/internal/config"
|
||||||
|
"github.com/jwetzell/showbridge-go/internal/module"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestPSNClientFromRegistry(t *testing.T) {
|
||||||
|
registration, ok := module.ModuleRegistry["psn.client"]
|
||||||
|
if !ok {
|
||||||
|
t.Fatalf("psn.client module not registered")
|
||||||
|
}
|
||||||
|
|
||||||
|
moduleInstance, err := registration.New(config.ModuleConfig{
|
||||||
|
Type: "psn.client",
|
||||||
|
})
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("failed to create psn.client module: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if moduleInstance.Type() != "psn.client" {
|
||||||
|
t.Fatalf("psn.client module has wrong type: %s", moduleInstance.Type())
|
||||||
|
}
|
||||||
|
}
|
||||||
32
internal/module/test/serial-client_test.go
Normal file
32
internal/module/test/serial-client_test.go
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
package module_test
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/jwetzell/showbridge-go/internal/config"
|
||||||
|
"github.com/jwetzell/showbridge-go/internal/module"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestSerialClientFromRegistry(t *testing.T) {
|
||||||
|
registration, ok := module.ModuleRegistry["serial.client"]
|
||||||
|
if !ok {
|
||||||
|
t.Fatalf("serial.client module not registered")
|
||||||
|
}
|
||||||
|
|
||||||
|
moduleInstance, err := registration.New(config.ModuleConfig{
|
||||||
|
Type: "serial.client",
|
||||||
|
Params: map[string]any{
|
||||||
|
"port": "/dev/ttyUSB0",
|
||||||
|
"framing": "LF",
|
||||||
|
"baudRate": 9600.0,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("failed to create serial.client module: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if moduleInstance.Type() != "serial.client" {
|
||||||
|
t.Fatalf("serial.client module has wrong type: %s", moduleInstance.Type())
|
||||||
|
}
|
||||||
|
}
|
||||||
27
internal/module/test/sip-call-server_test.go
Normal file
27
internal/module/test/sip-call-server_test.go
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
package module_test
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/jwetzell/showbridge-go/internal/config"
|
||||||
|
"github.com/jwetzell/showbridge-go/internal/module"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestSIPCallServerFromRegistry(t *testing.T) {
|
||||||
|
registration, ok := module.ModuleRegistry["sip.call.server"]
|
||||||
|
if !ok {
|
||||||
|
t.Fatalf("sip.call.server module not registered")
|
||||||
|
}
|
||||||
|
|
||||||
|
moduleInstance, err := registration.New(config.ModuleConfig{
|
||||||
|
Type: "sip.call.server",
|
||||||
|
})
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("failed to create sip.call.server module: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if moduleInstance.Type() != "sip.call.server" {
|
||||||
|
t.Fatalf("sip.call.server module has wrong type: %s", moduleInstance.Type())
|
||||||
|
}
|
||||||
|
}
|
||||||
30
internal/module/test/sip-dtmf-server_test.go
Normal file
30
internal/module/test/sip-dtmf-server_test.go
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
package module_test
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/jwetzell/showbridge-go/internal/config"
|
||||||
|
"github.com/jwetzell/showbridge-go/internal/module"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestSIPDTMFServerFromRegistry(t *testing.T) {
|
||||||
|
registration, ok := module.ModuleRegistry["sip.dtmf.server"]
|
||||||
|
if !ok {
|
||||||
|
t.Fatalf("sip.dtmf.server module not registered")
|
||||||
|
}
|
||||||
|
|
||||||
|
moduleInstance, err := registration.New(config.ModuleConfig{
|
||||||
|
Type: "sip.dtmf.server",
|
||||||
|
Params: map[string]any{
|
||||||
|
"separator": "#",
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("failed to create sip.dtmf.server module: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if moduleInstance.Type() != "sip.dtmf.server" {
|
||||||
|
t.Fatalf("sip.dtmf.server module has wrong type: %s", moduleInstance.Type())
|
||||||
|
}
|
||||||
|
}
|
||||||
32
internal/module/test/tcp-client_test.go
Normal file
32
internal/module/test/tcp-client_test.go
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
package module_test
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/jwetzell/showbridge-go/internal/config"
|
||||||
|
"github.com/jwetzell/showbridge-go/internal/module"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestTCPClientFromRegistry(t *testing.T) {
|
||||||
|
registration, ok := module.ModuleRegistry["net.tcp.client"]
|
||||||
|
if !ok {
|
||||||
|
t.Fatalf("net.tcp.client module not registered")
|
||||||
|
}
|
||||||
|
|
||||||
|
moduleInstance, err := registration.New(config.ModuleConfig{
|
||||||
|
Type: "net.tcp.client",
|
||||||
|
Params: map[string]any{
|
||||||
|
"host": "localhost",
|
||||||
|
"port": 8000.0,
|
||||||
|
"framing": "LF",
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("failed to create net.tcp.client module: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if moduleInstance.Type() != "net.tcp.client" {
|
||||||
|
t.Fatalf("net.tcp.client module has wrong type: %s", moduleInstance.Type())
|
||||||
|
}
|
||||||
|
}
|
||||||
31
internal/module/test/tcp-server_test.go
Normal file
31
internal/module/test/tcp-server_test.go
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
package module_test
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/jwetzell/showbridge-go/internal/config"
|
||||||
|
"github.com/jwetzell/showbridge-go/internal/module"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestTCPServerFromRegistry(t *testing.T) {
|
||||||
|
registration, ok := module.ModuleRegistry["net.tcp.server"]
|
||||||
|
if !ok {
|
||||||
|
t.Fatalf("net.tcp.server module not registered")
|
||||||
|
}
|
||||||
|
|
||||||
|
moduleInstance, err := registration.New(config.ModuleConfig{
|
||||||
|
Type: "net.tcp.server",
|
||||||
|
Params: map[string]any{
|
||||||
|
"port": 8000.0,
|
||||||
|
"framing": "LF",
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("failed to create net.tcp.server module: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if moduleInstance.Type() != "net.tcp.server" {
|
||||||
|
t.Fatalf("net.tcp.server module has wrong type: %s", moduleInstance.Type())
|
||||||
|
}
|
||||||
|
}
|
||||||
32
internal/module/test/udp-client_test.go
Normal file
32
internal/module/test/udp-client_test.go
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
package module_test
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/jwetzell/showbridge-go/internal/config"
|
||||||
|
"github.com/jwetzell/showbridge-go/internal/module"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestUDPClientFromRegistry(t *testing.T) {
|
||||||
|
registration, ok := module.ModuleRegistry["net.udp.client"]
|
||||||
|
if !ok {
|
||||||
|
t.Fatalf("udp.client module not registered")
|
||||||
|
}
|
||||||
|
|
||||||
|
moduleInstance, err := registration.New(config.ModuleConfig{
|
||||||
|
Type: "net.udp.client",
|
||||||
|
Params: map[string]any{
|
||||||
|
"host": "localhost",
|
||||||
|
"port": 8000.0,
|
||||||
|
"framing": "LF",
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("failed to create net.udp.client module: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if moduleInstance.Type() != "net.udp.client" {
|
||||||
|
t.Fatalf("net.udp.client module has wrong type: %s", moduleInstance.Type())
|
||||||
|
}
|
||||||
|
}
|
||||||
31
internal/module/test/udp-multicast_test.go
Normal file
31
internal/module/test/udp-multicast_test.go
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
package module_test
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/jwetzell/showbridge-go/internal/config"
|
||||||
|
"github.com/jwetzell/showbridge-go/internal/module"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestUDPMulticastFromRegistry(t *testing.T) {
|
||||||
|
registration, ok := module.ModuleRegistry["net.udp.multicast"]
|
||||||
|
if !ok {
|
||||||
|
t.Fatalf("udp.multicast module not registered")
|
||||||
|
}
|
||||||
|
|
||||||
|
moduleInstance, err := registration.New(config.ModuleConfig{
|
||||||
|
Type: "net.udp.multicast",
|
||||||
|
Params: map[string]any{
|
||||||
|
"ip": "236.10.10.10",
|
||||||
|
"port": 56565.0,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("failed to create udp.multicast module: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if moduleInstance.Type() != "net.udp.multicast" {
|
||||||
|
t.Fatalf("udp.multicast module has wrong type: %s", moduleInstance.Type())
|
||||||
|
}
|
||||||
|
}
|
||||||
30
internal/module/test/udp-server_test.go
Normal file
30
internal/module/test/udp-server_test.go
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
package module_test
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/jwetzell/showbridge-go/internal/config"
|
||||||
|
"github.com/jwetzell/showbridge-go/internal/module"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestUDPServerFromRegistry(t *testing.T) {
|
||||||
|
registration, ok := module.ModuleRegistry["net.udp.server"]
|
||||||
|
if !ok {
|
||||||
|
t.Fatalf("net.udp.server module not registered")
|
||||||
|
}
|
||||||
|
|
||||||
|
moduleInstance, err := registration.New(config.ModuleConfig{
|
||||||
|
Type: "net.udp.server",
|
||||||
|
Params: map[string]any{
|
||||||
|
"port": 8000.0,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("failed to create udp.server module: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if moduleInstance.Type() != "net.udp.server" {
|
||||||
|
t.Fatalf("net.udp.server module has wrong type: %s", moduleInstance.Type())
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -18,7 +18,7 @@ func TestArtnetPacketCreateFromRegistry(t *testing.T) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("failed to decode artnet.packet.decode processor: %s", err)
|
t.Fatalf("failed to create artnet.packet.decode processor: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if processorInstance.Type() != "artnet.packet.decode" {
|
if processorInstance.Type() != "artnet.packet.decode" {
|
||||||
|
|||||||
Reference in New Issue
Block a user