mirror of
https://github.com/jwetzell/showbridge-go.git
synced 2026-04-29 14:25:31 +00:00
Compare commits
14 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
988437fccf | ||
|
|
dc19d18b81 | ||
|
|
86f1082159 | ||
|
|
a46054c427 | ||
|
|
9dc4706fd8 | ||
|
|
f91cb9dbbf | ||
|
|
10b5cbae6c | ||
|
|
a9f9f1ba2c | ||
|
|
8e27dc81a2 | ||
|
|
5dc897c4b2 | ||
|
|
7015a9d7a2 | ||
|
|
3c6d98638e | ||
|
|
8ec8ad91a6 | ||
|
|
f919017ca6 |
13
.github/workflows/test-showbridge.yaml
vendored
13
.github/workflows/test-showbridge.yaml
vendored
@@ -17,7 +17,7 @@ on:
|
||||
- 'go.sum'
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
contents: write
|
||||
|
||||
jobs:
|
||||
test:
|
||||
@@ -34,4 +34,13 @@ jobs:
|
||||
run: go mod tidy
|
||||
|
||||
- name: run tests
|
||||
run: go test ./...
|
||||
run: go test ./...
|
||||
|
||||
- name: Update coverage report
|
||||
uses: ncruces/go-coverage-report@v0.3.2
|
||||
with:
|
||||
report: true
|
||||
chart: true
|
||||
amend: true
|
||||
if: github.event_name == 'push'
|
||||
continue-on-error: true
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
<div align="center">
|
||||
|
||||
# showbridge (go edition)
|
||||
# showbridge (go edition)
|
||||
|
||||
[](https://raw.githack.com/wiki/jwetzell/showbridge-go/coverage.html)
|
||||
|
||||
Simple protocol router _/s_
|
||||
|
||||
</div>
|
||||
|
||||
@@ -191,7 +191,6 @@ func (scs *SIPCallServer) Output(ctx context.Context, payload any) error {
|
||||
|
||||
if ok {
|
||||
dtmfWriter := call.inDialog.AudioWriterDTMF()
|
||||
|
||||
time.Sleep(time.Millisecond * time.Duration(payloadDTMFResponse.PreWait))
|
||||
for i, dtmfRune := range payloadDTMFResponse.Digits {
|
||||
err := dtmfWriter.WriteDTMF(dtmfRune)
|
||||
@@ -200,7 +199,7 @@ func (scs *SIPCallServer) Output(ctx context.Context, payload any) error {
|
||||
return fmt.Errorf("sip.dtmf.server error output dtmf digit at index %d", i)
|
||||
}
|
||||
}
|
||||
time.Sleep(time.Millisecond * time.Duration(payloadDTMFResponse.PreWait))
|
||||
time.Sleep(time.Millisecond * time.Duration(payloadDTMFResponse.PostWait))
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@@ -214,7 +214,7 @@ func (sds *SIPDTMFServer) Output(ctx context.Context, payload any) error {
|
||||
return fmt.Errorf("sip.dtmf.server error output dtmf digit at index %d", i)
|
||||
}
|
||||
}
|
||||
time.Sleep(time.Millisecond * time.Duration(payloadDTMFResponse.PreWait))
|
||||
time.Sleep(time.Millisecond * time.Duration(payloadDTMFResponse.PostWait))
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
32
internal/module/test/http-client_test.go
Normal file
32
internal/module/test/http-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 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{
|
||||
Id: "test",
|
||||
Type: "http.client",
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
t.Fatalf("failed to create http.client module: %s", err)
|
||||
}
|
||||
|
||||
if moduleInstance.Id() != "test" {
|
||||
t.Fatalf("http.client module has wrong id: %s", moduleInstance.Id())
|
||||
}
|
||||
|
||||
if moduleInstance.Type() != "http.client" {
|
||||
t.Fatalf("http.client module has wrong type: %s", moduleInstance.Type())
|
||||
}
|
||||
}
|
||||
35
internal/module/test/http-server_test.go
Normal file
35
internal/module/test/http-server_test.go
Normal file
@@ -0,0 +1,35 @@
|
||||
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{
|
||||
Id: "test",
|
||||
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.Id() != "test" {
|
||||
t.Fatalf("http.server module has wrong id: %s", moduleInstance.Id())
|
||||
}
|
||||
|
||||
if moduleInstance.Type() != "http.server" {
|
||||
t.Fatalf("http.server module has wrong type: %s", moduleInstance.Type())
|
||||
}
|
||||
}
|
||||
35
internal/module/test/midi-input_test.go
Normal file
35
internal/module/test/midi-input_test.go
Normal file
@@ -0,0 +1,35 @@
|
||||
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{
|
||||
Id: "test",
|
||||
Type: "midi.input",
|
||||
Params: map[string]any{
|
||||
"port": "test",
|
||||
},
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
t.Fatalf("failed to create midi.input module: %s", err)
|
||||
}
|
||||
|
||||
if moduleInstance.Id() != "test" {
|
||||
t.Fatalf("midi.input module has wrong id: %s", moduleInstance.Id())
|
||||
}
|
||||
|
||||
if moduleInstance.Type() != "midi.input" {
|
||||
t.Fatalf("midi.input module has wrong type: %s", moduleInstance.Type())
|
||||
}
|
||||
}
|
||||
35
internal/module/test/midi-output_test.go
Normal file
35
internal/module/test/midi-output_test.go
Normal file
@@ -0,0 +1,35 @@
|
||||
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{
|
||||
Id: "test",
|
||||
Type: "midi.output",
|
||||
Params: map[string]any{
|
||||
"port": "test",
|
||||
},
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
t.Fatalf("failed to create midi.output module: %s", err)
|
||||
}
|
||||
|
||||
if moduleInstance.Id() != "test" {
|
||||
t.Fatalf("midi.output module has wrong id: %s", moduleInstance.Id())
|
||||
}
|
||||
|
||||
if moduleInstance.Type() != "midi.output" {
|
||||
t.Fatalf("midi.output module has wrong type: %s", moduleInstance.Type())
|
||||
}
|
||||
}
|
||||
37
internal/module/test/mqtt-client_test.go
Normal file
37
internal/module/test/mqtt-client_test.go
Normal file
@@ -0,0 +1,37 @@
|
||||
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{
|
||||
Id: "test",
|
||||
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.Id() != "test" {
|
||||
t.Fatalf("mqtt.client module has wrong id: %s", moduleInstance.Id())
|
||||
}
|
||||
|
||||
if moduleInstance.Type() != "mqtt.client" {
|
||||
t.Fatalf("mqtt.client module has wrong type: %s", moduleInstance.Type())
|
||||
}
|
||||
}
|
||||
36
internal/module/test/nats-client_test.go
Normal file
36
internal/module/test/nats-client_test.go
Normal file
@@ -0,0 +1,36 @@
|
||||
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{
|
||||
Id: "test",
|
||||
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.Id() != "test" {
|
||||
t.Fatalf("nats.client module has wrong id: %s", moduleInstance.Id())
|
||||
}
|
||||
|
||||
if moduleInstance.Type() != "nats.client" {
|
||||
t.Fatalf("nats.client module has wrong type: %s", moduleInstance.Type())
|
||||
}
|
||||
}
|
||||
32
internal/module/test/psn-client_test.go
Normal file
32
internal/module/test/psn-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 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{
|
||||
Id: "test",
|
||||
Type: "psn.client",
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
t.Fatalf("failed to create psn.client module: %s", err)
|
||||
}
|
||||
|
||||
if moduleInstance.Id() != "test" {
|
||||
t.Fatalf("psn.client module has wrong id: %s", moduleInstance.Id())
|
||||
}
|
||||
|
||||
if moduleInstance.Type() != "psn.client" {
|
||||
t.Fatalf("psn.client module has wrong type: %s", moduleInstance.Type())
|
||||
}
|
||||
}
|
||||
37
internal/module/test/serial-client_test.go
Normal file
37
internal/module/test/serial-client_test.go
Normal file
@@ -0,0 +1,37 @@
|
||||
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{
|
||||
Id: "test",
|
||||
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.Id() != "test" {
|
||||
t.Fatalf("serial.client module has wrong id: %s", moduleInstance.Id())
|
||||
}
|
||||
|
||||
if moduleInstance.Type() != "serial.client" {
|
||||
t.Fatalf("serial.client module has wrong type: %s", moduleInstance.Type())
|
||||
}
|
||||
}
|
||||
32
internal/module/test/sip-call-server_test.go
Normal file
32
internal/module/test/sip-call-server_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 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{
|
||||
Id: "test",
|
||||
Type: "sip.call.server",
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
t.Fatalf("failed to create sip.call.server module: %s", err)
|
||||
}
|
||||
|
||||
if moduleInstance.Id() != "test" {
|
||||
t.Fatalf("sip.call.server module has wrong id: %s", moduleInstance.Id())
|
||||
}
|
||||
|
||||
if moduleInstance.Type() != "sip.call.server" {
|
||||
t.Fatalf("sip.call.server module has wrong type: %s", moduleInstance.Type())
|
||||
}
|
||||
}
|
||||
35
internal/module/test/sip-dtmf-server_test.go
Normal file
35
internal/module/test/sip-dtmf-server_test.go
Normal file
@@ -0,0 +1,35 @@
|
||||
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{
|
||||
Id: "test",
|
||||
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.Id() != "test" {
|
||||
t.Fatalf("sip.dtmf.server module has wrong id: %s", moduleInstance.Id())
|
||||
}
|
||||
|
||||
if moduleInstance.Type() != "sip.dtmf.server" {
|
||||
t.Fatalf("sip.dtmf.server module has wrong type: %s", moduleInstance.Type())
|
||||
}
|
||||
}
|
||||
37
internal/module/test/tcp-client_test.go
Normal file
37
internal/module/test/tcp-client_test.go
Normal file
@@ -0,0 +1,37 @@
|
||||
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{
|
||||
Id: "test",
|
||||
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.Id() != "test" {
|
||||
t.Fatalf("net.tcp.client module has wrong id: %s", moduleInstance.Id())
|
||||
}
|
||||
|
||||
if moduleInstance.Type() != "net.tcp.client" {
|
||||
t.Fatalf("net.tcp.client module has wrong type: %s", moduleInstance.Type())
|
||||
}
|
||||
}
|
||||
36
internal/module/test/tcp-server_test.go
Normal file
36
internal/module/test/tcp-server_test.go
Normal file
@@ -0,0 +1,36 @@
|
||||
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{
|
||||
Id: "test",
|
||||
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.Id() != "test" {
|
||||
t.Fatalf("net.tcp.server module has wrong id: %s", moduleInstance.Id())
|
||||
}
|
||||
|
||||
if moduleInstance.Type() != "net.tcp.server" {
|
||||
t.Fatalf("net.tcp.server module has wrong type: %s", moduleInstance.Type())
|
||||
}
|
||||
}
|
||||
35
internal/module/test/time-interval_test.go
Normal file
35
internal/module/test/time-interval_test.go
Normal file
@@ -0,0 +1,35 @@
|
||||
package module_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/jwetzell/showbridge-go/internal/config"
|
||||
"github.com/jwetzell/showbridge-go/internal/module"
|
||||
)
|
||||
|
||||
func TestTimeIntervalFromRegistry(t *testing.T) {
|
||||
registration, ok := module.ModuleRegistry["time.interval"]
|
||||
if !ok {
|
||||
t.Fatalf("time.interval module not registered")
|
||||
}
|
||||
|
||||
moduleInstance, err := registration.New(config.ModuleConfig{
|
||||
Id: "test",
|
||||
Type: "time.interval",
|
||||
Params: map[string]any{
|
||||
"duration": 1000.0,
|
||||
},
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
t.Fatalf("failed to create time.interval module: %s", err)
|
||||
}
|
||||
|
||||
if moduleInstance.Id() != "test" {
|
||||
t.Fatalf("time.interval module has wrong id: %s", moduleInstance.Id())
|
||||
}
|
||||
|
||||
if moduleInstance.Type() != "time.interval" {
|
||||
t.Fatalf("time.interval module has wrong type: %s", moduleInstance.Type())
|
||||
}
|
||||
}
|
||||
35
internal/module/test/time-timer_test.go
Normal file
35
internal/module/test/time-timer_test.go
Normal file
@@ -0,0 +1,35 @@
|
||||
package module_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/jwetzell/showbridge-go/internal/config"
|
||||
"github.com/jwetzell/showbridge-go/internal/module"
|
||||
)
|
||||
|
||||
func TestTimeTimerFromRegistry(t *testing.T) {
|
||||
registration, ok := module.ModuleRegistry["time.timer"]
|
||||
if !ok {
|
||||
t.Fatalf("time.timer module not registered")
|
||||
}
|
||||
|
||||
moduleInstance, err := registration.New(config.ModuleConfig{
|
||||
Id: "test",
|
||||
Type: "time.timer",
|
||||
Params: map[string]any{
|
||||
"duration": 1000.0,
|
||||
},
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
t.Fatalf("failed to create time.timer module: %s", err)
|
||||
}
|
||||
|
||||
if moduleInstance.Id() != "test" {
|
||||
t.Fatalf("time.timer module has wrong id: %s", moduleInstance.Id())
|
||||
}
|
||||
|
||||
if moduleInstance.Type() != "time.timer" {
|
||||
t.Fatalf("time.timer module has wrong type: %s", moduleInstance.Type())
|
||||
}
|
||||
}
|
||||
37
internal/module/test/udp-client_test.go
Normal file
37
internal/module/test/udp-client_test.go
Normal file
@@ -0,0 +1,37 @@
|
||||
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{
|
||||
Id: "test",
|
||||
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.Id() != "test" {
|
||||
t.Fatalf("net.udp.client module has wrong id: %s", moduleInstance.Id())
|
||||
}
|
||||
|
||||
if moduleInstance.Type() != "net.udp.client" {
|
||||
t.Fatalf("net.udp.client module has wrong type: %s", moduleInstance.Type())
|
||||
}
|
||||
}
|
||||
36
internal/module/test/udp-multicast_test.go
Normal file
36
internal/module/test/udp-multicast_test.go
Normal file
@@ -0,0 +1,36 @@
|
||||
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{
|
||||
Id: "test",
|
||||
Type: "net.udp.multicast",
|
||||
Params: map[string]any{
|
||||
"ip": "236.10.10.10",
|
||||
"port": 56565.0,
|
||||
},
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
t.Fatalf("failed to create net.udp.multicast module: %s", err)
|
||||
}
|
||||
|
||||
if moduleInstance.Id() != "test" {
|
||||
t.Fatalf("net.udp.multicast module has wrong id: %s", moduleInstance.Id())
|
||||
}
|
||||
|
||||
if moduleInstance.Type() != "net.udp.multicast" {
|
||||
t.Fatalf("net.udp.multicast module has wrong type: %s", moduleInstance.Type())
|
||||
}
|
||||
}
|
||||
35
internal/module/test/udp-server_test.go
Normal file
35
internal/module/test/udp-server_test.go
Normal file
@@ -0,0 +1,35 @@
|
||||
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{
|
||||
Id: "test",
|
||||
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.Id() != "test" {
|
||||
t.Fatalf("udp.server module has wrong id: %s", moduleInstance.Id())
|
||||
}
|
||||
|
||||
if moduleInstance.Type() != "net.udp.server" {
|
||||
t.Fatalf("net.udp.server module has wrong type: %s", moduleInstance.Type())
|
||||
}
|
||||
}
|
||||
@@ -78,7 +78,7 @@ func (us *UDPServer) Id() string {
|
||||
}
|
||||
|
||||
func (us *UDPServer) Type() string {
|
||||
return us.config.Id
|
||||
return us.config.Type
|
||||
}
|
||||
|
||||
func (us *UDPServer) Start(ctx context.Context) error {
|
||||
|
||||
@@ -72,6 +72,18 @@ func init() {
|
||||
functionString = specificFunctionString
|
||||
}
|
||||
|
||||
enableWasiBool := false
|
||||
|
||||
enableWasi, ok := params["enableWasi"]
|
||||
|
||||
if ok {
|
||||
specificEnableWasi, ok := enableWasi.(bool)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("script.wasm enableWasi must be a boolean")
|
||||
}
|
||||
enableWasiBool = specificEnableWasi
|
||||
}
|
||||
|
||||
manifest := extism.Manifest{
|
||||
Wasm: []extism.Wasm{
|
||||
extism.WasmFile{
|
||||
@@ -80,7 +92,9 @@ func init() {
|
||||
},
|
||||
}
|
||||
|
||||
program, err := extism.NewCompiledPlugin(context.Background(), manifest, extism.PluginConfig{}, []extism.HostFunction{})
|
||||
program, err := extism.NewCompiledPlugin(context.Background(), manifest, extism.PluginConfig{
|
||||
EnableWasi: enableWasiBool,
|
||||
}, []extism.HostFunction{})
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
27
internal/processor/test/artnet-packet-decode_test.go
Normal file
27
internal/processor/test/artnet-packet-decode_test.go
Normal file
@@ -0,0 +1,27 @@
|
||||
package processor_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/jwetzell/showbridge-go/internal/config"
|
||||
"github.com/jwetzell/showbridge-go/internal/processor"
|
||||
)
|
||||
|
||||
func TestArtnetPacketCreateFromRegistry(t *testing.T) {
|
||||
registration, ok := processor.ProcessorRegistry["artnet.packet.decode"]
|
||||
if !ok {
|
||||
t.Fatalf("artnet.packet.decode processor not registered")
|
||||
}
|
||||
|
||||
processorInstance, err := registration.New(config.ProcessorConfig{
|
||||
Type: "artnet.packet.decode",
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
t.Fatalf("failed to create artnet.packet.decode processor: %s", err)
|
||||
}
|
||||
|
||||
if processorInstance.Type() != "artnet.packet.decode" {
|
||||
t.Fatalf("artnet.packet.decode processor has wrong type: %s", processorInstance.Type())
|
||||
}
|
||||
}
|
||||
27
internal/processor/test/artnet-packet-encode_test.go
Normal file
27
internal/processor/test/artnet-packet-encode_test.go
Normal file
@@ -0,0 +1,27 @@
|
||||
package processor_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/jwetzell/showbridge-go/internal/config"
|
||||
"github.com/jwetzell/showbridge-go/internal/processor"
|
||||
)
|
||||
|
||||
func TestArtnetPacketEncodeFromRegistry(t *testing.T) {
|
||||
registration, ok := processor.ProcessorRegistry["artnet.packet.encode"]
|
||||
if !ok {
|
||||
t.Fatalf("artnet.packet.encode processor not registered")
|
||||
}
|
||||
|
||||
processorInstance, err := registration.New(config.ProcessorConfig{
|
||||
Type: "artnet.packet.encode",
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
t.Fatalf("failed to create artnet.packet.encode processor: %s", err)
|
||||
}
|
||||
|
||||
if processorInstance.Type() != "artnet.packet.encode" {
|
||||
t.Fatalf("artnet.packet.encode processor has wrong type: %s", processorInstance.Type())
|
||||
}
|
||||
}
|
||||
38
internal/processor/test/free-d-create_test.go
Normal file
38
internal/processor/test/free-d-create_test.go
Normal file
@@ -0,0 +1,38 @@
|
||||
package processor_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/jwetzell/showbridge-go/internal/config"
|
||||
"github.com/jwetzell/showbridge-go/internal/processor"
|
||||
)
|
||||
|
||||
func TestFreeDCreateFromRegistry(t *testing.T) {
|
||||
registration, ok := processor.ProcessorRegistry["freed.create"]
|
||||
if !ok {
|
||||
t.Fatalf("freed.create processor not registered")
|
||||
}
|
||||
|
||||
processorInstance, err := registration.New(config.ProcessorConfig{
|
||||
Type: "freed.create",
|
||||
Params: map[string]any{
|
||||
"id": "0",
|
||||
"pan": "0",
|
||||
"tilt": "0",
|
||||
"roll": "0",
|
||||
"posX": "0",
|
||||
"posY": "0",
|
||||
"posZ": "0",
|
||||
"zoom": "0",
|
||||
"focus": "0",
|
||||
},
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
t.Fatalf("failed to create freed.create processor: %s", err)
|
||||
}
|
||||
|
||||
if processorInstance.Type() != "freed.create" {
|
||||
t.Fatalf("freed.create processor has wrong type: %s", processorInstance.Type())
|
||||
}
|
||||
}
|
||||
27
internal/processor/test/free-d-decode_test.go
Normal file
27
internal/processor/test/free-d-decode_test.go
Normal file
@@ -0,0 +1,27 @@
|
||||
package processor_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/jwetzell/showbridge-go/internal/config"
|
||||
"github.com/jwetzell/showbridge-go/internal/processor"
|
||||
)
|
||||
|
||||
func TestFreeDDecodeFromRegistry(t *testing.T) {
|
||||
registration, ok := processor.ProcessorRegistry["freed.decode"]
|
||||
if !ok {
|
||||
t.Fatalf("freed.decode processor not registered")
|
||||
}
|
||||
|
||||
processorInstance, err := registration.New(config.ProcessorConfig{
|
||||
Type: "freed.decode",
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
t.Fatalf("failed to create freed.decode processor: %s", err)
|
||||
}
|
||||
|
||||
if processorInstance.Type() != "freed.decode" {
|
||||
t.Fatalf("freed.decode processor has wrong type: %s", processorInstance.Type())
|
||||
}
|
||||
}
|
||||
27
internal/processor/test/free-d-encode_test.go
Normal file
27
internal/processor/test/free-d-encode_test.go
Normal file
@@ -0,0 +1,27 @@
|
||||
package processor_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/jwetzell/showbridge-go/internal/config"
|
||||
"github.com/jwetzell/showbridge-go/internal/processor"
|
||||
)
|
||||
|
||||
func TestFreeDEncodeFromRegistry(t *testing.T) {
|
||||
registration, ok := processor.ProcessorRegistry["freed.encode"]
|
||||
if !ok {
|
||||
t.Fatalf("freed.encode processor not registered")
|
||||
}
|
||||
|
||||
processorInstance, err := registration.New(config.ProcessorConfig{
|
||||
Type: "freed.encode",
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
t.Fatalf("failed to create freed.encode processor: %s", err)
|
||||
}
|
||||
|
||||
if processorInstance.Type() != "freed.encode" {
|
||||
t.Fatalf("freed.encode processor has wrong type: %s", processorInstance.Type())
|
||||
}
|
||||
}
|
||||
BIN
internal/processor/test/good.wasm
Executable file
BIN
internal/processor/test/good.wasm
Executable file
Binary file not shown.
31
internal/processor/test/http-request-create_test.go
Normal file
31
internal/processor/test/http-request-create_test.go
Normal file
@@ -0,0 +1,31 @@
|
||||
package processor_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/jwetzell/showbridge-go/internal/config"
|
||||
"github.com/jwetzell/showbridge-go/internal/processor"
|
||||
)
|
||||
|
||||
func TestHTTPRequestCreateFromRegistry(t *testing.T) {
|
||||
registration, ok := processor.ProcessorRegistry["http.request.create"]
|
||||
if !ok {
|
||||
t.Fatalf("http.request.create processor not registered")
|
||||
}
|
||||
|
||||
processorInstance, err := registration.New(config.ProcessorConfig{
|
||||
Type: "http.request.create",
|
||||
Params: map[string]any{
|
||||
"method": "GET",
|
||||
"url": "http://example.com",
|
||||
},
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
t.Fatalf("failed to create http.request.create processor: %s", err)
|
||||
}
|
||||
|
||||
if processorInstance.Type() != "http.request.create" {
|
||||
t.Fatalf("http.request.create processor has wrong type: %s", processorInstance.Type())
|
||||
}
|
||||
}
|
||||
27
internal/processor/test/http-request-encode_test.go
Normal file
27
internal/processor/test/http-request-encode_test.go
Normal file
@@ -0,0 +1,27 @@
|
||||
package processor_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/jwetzell/showbridge-go/internal/config"
|
||||
"github.com/jwetzell/showbridge-go/internal/processor"
|
||||
)
|
||||
|
||||
func TestHTTPRequestEncodeFromRegistry(t *testing.T) {
|
||||
registration, ok := processor.ProcessorRegistry["http.request.encode"]
|
||||
if !ok {
|
||||
t.Fatalf("http.request.encode processor not registered")
|
||||
}
|
||||
|
||||
processorInstance, err := registration.New(config.ProcessorConfig{
|
||||
Type: "http.request.encode",
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
t.Fatalf("failed to create http.request.encode processor: %s", err)
|
||||
}
|
||||
|
||||
if processorInstance.Type() != "http.request.encode" {
|
||||
t.Fatalf("http.request.encode processor has wrong type: %s", processorInstance.Type())
|
||||
}
|
||||
}
|
||||
31
internal/processor/test/http-request-filter_test.go
Normal file
31
internal/processor/test/http-request-filter_test.go
Normal file
@@ -0,0 +1,31 @@
|
||||
package processor_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/jwetzell/showbridge-go/internal/config"
|
||||
"github.com/jwetzell/showbridge-go/internal/processor"
|
||||
)
|
||||
|
||||
func TestHTTPRequestFilterFromRegistry(t *testing.T) {
|
||||
registration, ok := processor.ProcessorRegistry["http.request.filter"]
|
||||
if !ok {
|
||||
t.Fatalf("http.request.filter processor not registered")
|
||||
}
|
||||
|
||||
processorInstance, err := registration.New(config.ProcessorConfig{
|
||||
Type: "http.request.filter",
|
||||
Params: map[string]any{
|
||||
"method": "GET",
|
||||
"path": "/test",
|
||||
},
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
t.Fatalf("failed to create http.request.filter processor: %s", err)
|
||||
}
|
||||
|
||||
if processorInstance.Type() != "http.request.filter" {
|
||||
t.Fatalf("http.request.filter processor has wrong type: %s", processorInstance.Type())
|
||||
}
|
||||
}
|
||||
31
internal/processor/test/http-response-create_test.go
Normal file
31
internal/processor/test/http-response-create_test.go
Normal file
@@ -0,0 +1,31 @@
|
||||
package processor_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/jwetzell/showbridge-go/internal/config"
|
||||
"github.com/jwetzell/showbridge-go/internal/processor"
|
||||
)
|
||||
|
||||
func TestHTTPResponseCreateFromRegistry(t *testing.T) {
|
||||
registration, ok := processor.ProcessorRegistry["http.response.create"]
|
||||
if !ok {
|
||||
t.Fatalf("http.response.create processor not registered")
|
||||
}
|
||||
|
||||
processorInstance, err := registration.New(config.ProcessorConfig{
|
||||
Type: "http.response.create",
|
||||
Params: map[string]any{
|
||||
"status": 200.0,
|
||||
"bodyTemplate": "Hello, World!",
|
||||
},
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
t.Fatalf("failed to create http.response.create processor: %s", err)
|
||||
}
|
||||
|
||||
if processorInstance.Type() != "http.response.create" {
|
||||
t.Fatalf("http.response.create processor has wrong type: %s", processorInstance.Type())
|
||||
}
|
||||
}
|
||||
27
internal/processor/test/http-response-encode_test.go
Normal file
27
internal/processor/test/http-response-encode_test.go
Normal file
@@ -0,0 +1,27 @@
|
||||
package processor_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/jwetzell/showbridge-go/internal/config"
|
||||
"github.com/jwetzell/showbridge-go/internal/processor"
|
||||
)
|
||||
|
||||
func TestHTTPResponseEncodeFromRegistry(t *testing.T) {
|
||||
registration, ok := processor.ProcessorRegistry["http.response.encode"]
|
||||
if !ok {
|
||||
t.Fatalf("http.response.encode processor not registered")
|
||||
}
|
||||
|
||||
processorInstance, err := registration.New(config.ProcessorConfig{
|
||||
Type: "http.response.encode",
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
t.Fatalf("failed to create http.response.encode processor: %s", err)
|
||||
}
|
||||
|
||||
if processorInstance.Type() != "http.response.encode" {
|
||||
t.Fatalf("http.response.encode processor has wrong type: %s", processorInstance.Type())
|
||||
}
|
||||
}
|
||||
33
internal/processor/test/midi-message-create_test.go
Normal file
33
internal/processor/test/midi-message-create_test.go
Normal file
@@ -0,0 +1,33 @@
|
||||
package processor_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/jwetzell/showbridge-go/internal/config"
|
||||
"github.com/jwetzell/showbridge-go/internal/processor"
|
||||
)
|
||||
|
||||
func TestMIDIMessageCreateFromRegistry(t *testing.T) {
|
||||
registration, ok := processor.ProcessorRegistry["midi.message.create"]
|
||||
if !ok {
|
||||
t.Fatalf("midi.message.create processor not registered")
|
||||
}
|
||||
|
||||
processorInstance, err := registration.New(config.ProcessorConfig{
|
||||
Type: "midi.message.create",
|
||||
Params: map[string]any{
|
||||
"type": "note_on",
|
||||
"channel": "1",
|
||||
"note": "60",
|
||||
"velocity": "100",
|
||||
},
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
t.Fatalf("failed to create midi.message.create processor: %s", err)
|
||||
}
|
||||
|
||||
if processorInstance.Type() != "midi.message.create" {
|
||||
t.Fatalf("midi.message.create processor has wrong type: %s", processorInstance.Type())
|
||||
}
|
||||
}
|
||||
27
internal/processor/test/midi-message-decode_test.go
Normal file
27
internal/processor/test/midi-message-decode_test.go
Normal file
@@ -0,0 +1,27 @@
|
||||
package processor_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/jwetzell/showbridge-go/internal/config"
|
||||
"github.com/jwetzell/showbridge-go/internal/processor"
|
||||
)
|
||||
|
||||
func TestMIDIMessageDecodeFromRegistry(t *testing.T) {
|
||||
registration, ok := processor.ProcessorRegistry["midi.message.decode"]
|
||||
if !ok {
|
||||
t.Fatalf("midi.message.decode processor not registered")
|
||||
}
|
||||
|
||||
processorInstance, err := registration.New(config.ProcessorConfig{
|
||||
Type: "midi.message.decode",
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
t.Fatalf("failed to create midi.message.decode processor: %s", err)
|
||||
}
|
||||
|
||||
if processorInstance.Type() != "midi.message.decode" {
|
||||
t.Fatalf("midi.message.decode processor has wrong type: %s", processorInstance.Type())
|
||||
}
|
||||
}
|
||||
27
internal/processor/test/midi-message-encode_test.go
Normal file
27
internal/processor/test/midi-message-encode_test.go
Normal file
@@ -0,0 +1,27 @@
|
||||
package processor_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/jwetzell/showbridge-go/internal/config"
|
||||
"github.com/jwetzell/showbridge-go/internal/processor"
|
||||
)
|
||||
|
||||
func TestMIDIMessageEncodeFromRegistry(t *testing.T) {
|
||||
registration, ok := processor.ProcessorRegistry["midi.message.encode"]
|
||||
if !ok {
|
||||
t.Fatalf("midi.message.encode processor not registered")
|
||||
}
|
||||
|
||||
processorInstance, err := registration.New(config.ProcessorConfig{
|
||||
Type: "midi.message.encode",
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
t.Fatalf("failed to create midi.message.encode processor: %s", err)
|
||||
}
|
||||
|
||||
if processorInstance.Type() != "midi.message.encode" {
|
||||
t.Fatalf("midi.message.encode processor has wrong type: %s", processorInstance.Type())
|
||||
}
|
||||
}
|
||||
30
internal/processor/test/midi-message-filter_test.go
Normal file
30
internal/processor/test/midi-message-filter_test.go
Normal file
@@ -0,0 +1,30 @@
|
||||
package processor_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/jwetzell/showbridge-go/internal/config"
|
||||
"github.com/jwetzell/showbridge-go/internal/processor"
|
||||
)
|
||||
|
||||
func TestMIDIMessageFilterFromRegistry(t *testing.T) {
|
||||
registration, ok := processor.ProcessorRegistry["midi.message.filter"]
|
||||
if !ok {
|
||||
t.Fatalf("midi.message.filter processor not registered")
|
||||
}
|
||||
|
||||
processorInstance, err := registration.New(config.ProcessorConfig{
|
||||
Type: "midi.message.filter",
|
||||
Params: map[string]any{
|
||||
"type": "NoteOn",
|
||||
},
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
t.Fatalf("failed to create midi.message.filter processor: %s", err)
|
||||
}
|
||||
|
||||
if processorInstance.Type() != "midi.message.filter" {
|
||||
t.Fatalf("midi.message.filter processor has wrong type: %s", processorInstance.Type())
|
||||
}
|
||||
}
|
||||
27
internal/processor/test/midi-message-unpack_test.go
Normal file
27
internal/processor/test/midi-message-unpack_test.go
Normal file
@@ -0,0 +1,27 @@
|
||||
package processor_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/jwetzell/showbridge-go/internal/config"
|
||||
"github.com/jwetzell/showbridge-go/internal/processor"
|
||||
)
|
||||
|
||||
func TestMIDIMessageUnpackFromRegistry(t *testing.T) {
|
||||
registration, ok := processor.ProcessorRegistry["midi.message.unpack"]
|
||||
if !ok {
|
||||
t.Fatalf("midi.message.unpack processor not registered")
|
||||
}
|
||||
|
||||
processorInstance, err := registration.New(config.ProcessorConfig{
|
||||
Type: "midi.message.unpack",
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
t.Fatalf("failed to create midi.message.unpack processor: %s", err)
|
||||
}
|
||||
|
||||
if processorInstance.Type() != "midi.message.unpack" {
|
||||
t.Fatalf("midi.message.unpack processor has wrong type: %s", processorInstance.Type())
|
||||
}
|
||||
}
|
||||
33
internal/processor/test/mqtt-message-create_test.go
Normal file
33
internal/processor/test/mqtt-message-create_test.go
Normal file
@@ -0,0 +1,33 @@
|
||||
package processor_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/jwetzell/showbridge-go/internal/config"
|
||||
"github.com/jwetzell/showbridge-go/internal/processor"
|
||||
)
|
||||
|
||||
func TestMQTTMessageCreateFromRegistry(t *testing.T) {
|
||||
registration, ok := processor.ProcessorRegistry["mqtt.message.create"]
|
||||
if !ok {
|
||||
t.Fatalf("mqtt.message.create processor not registered")
|
||||
}
|
||||
|
||||
processorInstance, err := registration.New(config.ProcessorConfig{
|
||||
Type: "mqtt.message.create",
|
||||
Params: map[string]any{
|
||||
"topic": "test/topic",
|
||||
"payload": "Hello, World!",
|
||||
"qos": 1.0,
|
||||
"retained": true,
|
||||
},
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
t.Fatalf("failed to create mqtt.message.create processor: %s", err)
|
||||
}
|
||||
|
||||
if processorInstance.Type() != "mqtt.message.create" {
|
||||
t.Fatalf("mqtt.message.create processor has wrong type: %s", processorInstance.Type())
|
||||
}
|
||||
}
|
||||
27
internal/processor/test/mqtt-message-encode_test.go
Normal file
27
internal/processor/test/mqtt-message-encode_test.go
Normal file
@@ -0,0 +1,27 @@
|
||||
package processor_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/jwetzell/showbridge-go/internal/config"
|
||||
"github.com/jwetzell/showbridge-go/internal/processor"
|
||||
)
|
||||
|
||||
func TestMQTTMessageEncodeFromRegistry(t *testing.T) {
|
||||
registration, ok := processor.ProcessorRegistry["mqtt.message.encode"]
|
||||
if !ok {
|
||||
t.Fatalf("mqtt.message.encode processor not registered")
|
||||
}
|
||||
|
||||
processorInstance, err := registration.New(config.ProcessorConfig{
|
||||
Type: "mqtt.message.encode",
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
t.Fatalf("failed to create mqtt.message.encode processor: %s", err)
|
||||
}
|
||||
|
||||
if processorInstance.Type() != "mqtt.message.encode" {
|
||||
t.Fatalf("mqtt.message.encode processor has wrong type: %s", processorInstance.Type())
|
||||
}
|
||||
}
|
||||
31
internal/processor/test/nats-message-create_test.go
Normal file
31
internal/processor/test/nats-message-create_test.go
Normal file
@@ -0,0 +1,31 @@
|
||||
package processor_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/jwetzell/showbridge-go/internal/config"
|
||||
"github.com/jwetzell/showbridge-go/internal/processor"
|
||||
)
|
||||
|
||||
func TestNATSMessageCreateFromRegistry(t *testing.T) {
|
||||
registration, ok := processor.ProcessorRegistry["nats.message.create"]
|
||||
if !ok {
|
||||
t.Fatalf("nats.message.create processor not registered")
|
||||
}
|
||||
|
||||
processorInstance, err := registration.New(config.ProcessorConfig{
|
||||
Type: "nats.message.create",
|
||||
Params: map[string]any{
|
||||
"subject": "test",
|
||||
"payload": "Hello, World!",
|
||||
},
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
t.Fatalf("failed to create nats.message.create processor: %s", err)
|
||||
}
|
||||
|
||||
if processorInstance.Type() != "nats.message.create" {
|
||||
t.Fatalf("nats.message.create processor has wrong type: %s", processorInstance.Type())
|
||||
}
|
||||
}
|
||||
27
internal/processor/test/nats-message-encode_test.go
Normal file
27
internal/processor/test/nats-message-encode_test.go
Normal file
@@ -0,0 +1,27 @@
|
||||
package processor_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/jwetzell/showbridge-go/internal/config"
|
||||
"github.com/jwetzell/showbridge-go/internal/processor"
|
||||
)
|
||||
|
||||
func TestNATSMessageEncodeFromRegistry(t *testing.T) {
|
||||
registration, ok := processor.ProcessorRegistry["nats.message.encode"]
|
||||
if !ok {
|
||||
t.Fatalf("nats.message.encode processor not registered")
|
||||
}
|
||||
|
||||
processorInstance, err := registration.New(config.ProcessorConfig{
|
||||
Type: "nats.message.encode",
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
t.Fatalf("failed to create nats.message.encode processor: %s", err)
|
||||
}
|
||||
|
||||
if processorInstance.Type() != "nats.message.encode" {
|
||||
t.Fatalf("nats.message.encode processor has wrong type: %s", processorInstance.Type())
|
||||
}
|
||||
}
|
||||
30
internal/processor/test/osc-message-create_test.go
Normal file
30
internal/processor/test/osc-message-create_test.go
Normal file
@@ -0,0 +1,30 @@
|
||||
package processor_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/jwetzell/showbridge-go/internal/config"
|
||||
"github.com/jwetzell/showbridge-go/internal/processor"
|
||||
)
|
||||
|
||||
func TestOSCMessageCreateFromRegistry(t *testing.T) {
|
||||
registration, ok := processor.ProcessorRegistry["osc.message.create"]
|
||||
if !ok {
|
||||
t.Fatalf("osc.message.create processor not registered")
|
||||
}
|
||||
|
||||
processorInstance, err := registration.New(config.ProcessorConfig{
|
||||
Type: "osc.message.create",
|
||||
Params: map[string]any{
|
||||
"address": "/test",
|
||||
},
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
t.Fatalf("failed to create osc.message.create processor: %s", err)
|
||||
}
|
||||
|
||||
if processorInstance.Type() != "osc.message.create" {
|
||||
t.Fatalf("osc.message.create processor has wrong type: %s", processorInstance.Type())
|
||||
}
|
||||
}
|
||||
27
internal/processor/test/osc-message-decode_test.go
Normal file
27
internal/processor/test/osc-message-decode_test.go
Normal file
@@ -0,0 +1,27 @@
|
||||
package processor_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/jwetzell/showbridge-go/internal/config"
|
||||
"github.com/jwetzell/showbridge-go/internal/processor"
|
||||
)
|
||||
|
||||
func TestOSCMessageDecodeFromRegistry(t *testing.T) {
|
||||
registration, ok := processor.ProcessorRegistry["osc.message.decode"]
|
||||
if !ok {
|
||||
t.Fatalf("osc.message.decode processor not registered")
|
||||
}
|
||||
|
||||
processorInstance, err := registration.New(config.ProcessorConfig{
|
||||
Type: "osc.message.decode",
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
t.Fatalf("failed to create osc.message.decode processor: %s", err)
|
||||
}
|
||||
|
||||
if processorInstance.Type() != "osc.message.decode" {
|
||||
t.Fatalf("osc.message.decode processor has wrong type: %s", processorInstance.Type())
|
||||
}
|
||||
}
|
||||
27
internal/processor/test/osc-message-encode_test.go
Normal file
27
internal/processor/test/osc-message-encode_test.go
Normal file
@@ -0,0 +1,27 @@
|
||||
package processor_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/jwetzell/showbridge-go/internal/config"
|
||||
"github.com/jwetzell/showbridge-go/internal/processor"
|
||||
)
|
||||
|
||||
func TestOSCMessageEncodeFromRegistry(t *testing.T) {
|
||||
registration, ok := processor.ProcessorRegistry["osc.message.encode"]
|
||||
if !ok {
|
||||
t.Fatalf("osc.message.encode processor not registered")
|
||||
}
|
||||
|
||||
processorInstance, err := registration.New(config.ProcessorConfig{
|
||||
Type: "osc.message.encode",
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
t.Fatalf("failed to create osc.message.encode processor: %s", err)
|
||||
}
|
||||
|
||||
if processorInstance.Type() != "osc.message.encode" {
|
||||
t.Fatalf("osc.message.encode processor has wrong type: %s", processorInstance.Type())
|
||||
}
|
||||
}
|
||||
30
internal/processor/test/osc-message-filter_test.go
Normal file
30
internal/processor/test/osc-message-filter_test.go
Normal file
@@ -0,0 +1,30 @@
|
||||
package processor_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/jwetzell/showbridge-go/internal/config"
|
||||
"github.com/jwetzell/showbridge-go/internal/processor"
|
||||
)
|
||||
|
||||
func TestOSCMessageFilterFromRegistry(t *testing.T) {
|
||||
registration, ok := processor.ProcessorRegistry["osc.message.filter"]
|
||||
if !ok {
|
||||
t.Fatalf("osc.message.filter processor not registered")
|
||||
}
|
||||
|
||||
processorInstance, err := registration.New(config.ProcessorConfig{
|
||||
Type: "osc.message.filter",
|
||||
Params: map[string]any{
|
||||
"address": "/test*",
|
||||
},
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
t.Fatalf("failed to filter osc.message.filter processor: %s", err)
|
||||
}
|
||||
|
||||
if processorInstance.Type() != "osc.message.filter" {
|
||||
t.Fatalf("osc.message.filter processor has wrong type: %s", processorInstance.Type())
|
||||
}
|
||||
}
|
||||
127
internal/processor/test/script-wasm_test.go
Normal file
127
internal/processor/test/script-wasm_test.go
Normal file
@@ -0,0 +1,127 @@
|
||||
package processor_test
|
||||
|
||||
import (
|
||||
"slices"
|
||||
"testing"
|
||||
|
||||
"github.com/jwetzell/showbridge-go/internal/config"
|
||||
"github.com/jwetzell/showbridge-go/internal/processor"
|
||||
)
|
||||
|
||||
func TestScriptWASMFromRegistry(t *testing.T) {
|
||||
registration, ok := processor.ProcessorRegistry["script.wasm"]
|
||||
if !ok {
|
||||
t.Fatalf("script.wasm processor not registered")
|
||||
}
|
||||
|
||||
processorInstance, err := registration.New(config.ProcessorConfig{
|
||||
Type: "script.wasm",
|
||||
Params: map[string]any{
|
||||
"path": "good.wasm",
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("failed to create script.wasm processor: %s", err)
|
||||
}
|
||||
|
||||
if processorInstance.Type() != "script.wasm" {
|
||||
t.Fatalf("script.wasm processor has wrong type: %s", processorInstance.Type())
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func TestScriptWASMNoPath(t *testing.T) {
|
||||
registration, ok := processor.ProcessorRegistry["script.wasm"]
|
||||
if !ok {
|
||||
t.Fatalf("script.wasm processor not registered")
|
||||
}
|
||||
|
||||
_, err := registration.New(config.ProcessorConfig{
|
||||
Type: "script.wasm",
|
||||
Params: map[string]any{},
|
||||
})
|
||||
|
||||
if err == nil {
|
||||
t.Fatalf("script.wasm processor should have thrown an error when creating")
|
||||
}
|
||||
}
|
||||
|
||||
func TestScriptWASMBadConfigWrongPathType(t *testing.T) {
|
||||
registration, ok := processor.ProcessorRegistry["script.wasm"]
|
||||
if !ok {
|
||||
t.Fatalf("script.wasm processor not registered")
|
||||
}
|
||||
|
||||
_, err := registration.New(config.ProcessorConfig{
|
||||
Type: "script.wasm",
|
||||
Params: map[string]any{
|
||||
"path": 12345,
|
||||
},
|
||||
})
|
||||
|
||||
if err == nil {
|
||||
t.Fatalf("script.wasm processor should have thrown an error when creating with non-string path")
|
||||
}
|
||||
}
|
||||
|
||||
func TestGoodScriptWASM(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
payload []byte
|
||||
params map[string]any
|
||||
expected []byte
|
||||
}{
|
||||
{
|
||||
name: "number",
|
||||
params: map[string]any{
|
||||
"path": "good.wasm",
|
||||
"enableWasi": true,
|
||||
},
|
||||
payload: []byte("hello"),
|
||||
expected: []byte("Processed: hello"),
|
||||
},
|
||||
{
|
||||
name: "number",
|
||||
params: map[string]any{
|
||||
"path": "good.wasm",
|
||||
"enableWasi": true,
|
||||
"function": "greet",
|
||||
},
|
||||
payload: []byte("world"),
|
||||
expected: []byte("Hello, world"),
|
||||
},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
registration, ok := processor.ProcessorRegistry["script.wasm"]
|
||||
if !ok {
|
||||
t.Fatalf("script.wasm processor not registered")
|
||||
}
|
||||
|
||||
processorInstance, err := registration.New(config.ProcessorConfig{
|
||||
Type: "script.wasm",
|
||||
Params: test.params,
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
t.Fatalf("script.wasm failed to create processor: %s", err)
|
||||
}
|
||||
|
||||
got, err := processorInstance.Process(t.Context(), test.payload)
|
||||
|
||||
if err != nil {
|
||||
t.Fatalf("script.wasm process failed: %s", err)
|
||||
}
|
||||
|
||||
gotBytes, ok := got.([]byte)
|
||||
if !ok {
|
||||
t.Fatalf("script.wasm returned a %T payload: %s", got, got)
|
||||
}
|
||||
|
||||
if !slices.Equal(gotBytes, test.expected) {
|
||||
t.Fatalf("script.wasm got %+v, expected %+v", gotBytes, test.expected)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
32
internal/processor/test/sip-response-audio-create_test.go
Normal file
32
internal/processor/test/sip-response-audio-create_test.go
Normal file
@@ -0,0 +1,32 @@
|
||||
package processor_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/jwetzell/showbridge-go/internal/config"
|
||||
"github.com/jwetzell/showbridge-go/internal/processor"
|
||||
)
|
||||
|
||||
func TestSipResponseAudioCreateFromRegistry(t *testing.T) {
|
||||
registration, ok := processor.ProcessorRegistry["sip.response.audio.create"]
|
||||
if !ok {
|
||||
t.Fatalf("sip.response.audio.create processor not registered")
|
||||
}
|
||||
|
||||
processorInstance, err := registration.New(config.ProcessorConfig{
|
||||
Type: "sip.response.audio.create",
|
||||
Params: map[string]any{
|
||||
"preWait": 0.0,
|
||||
"audioFile": "good.wav",
|
||||
"postWait": 0.0,
|
||||
},
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
t.Fatalf("failed to filter sip.response.audio.create processor: %s", err)
|
||||
}
|
||||
|
||||
if processorInstance.Type() != "sip.response.audio.create" {
|
||||
t.Fatalf("sip.response.audio.create processor has wrong type: %s", processorInstance.Type())
|
||||
}
|
||||
}
|
||||
32
internal/processor/test/sip-response-dtmf-create_test.go
Normal file
32
internal/processor/test/sip-response-dtmf-create_test.go
Normal file
@@ -0,0 +1,32 @@
|
||||
package processor_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/jwetzell/showbridge-go/internal/config"
|
||||
"github.com/jwetzell/showbridge-go/internal/processor"
|
||||
)
|
||||
|
||||
func TestSipResponseDTMFCreateFromRegistry(t *testing.T) {
|
||||
registration, ok := processor.ProcessorRegistry["sip.response.dtmf.create"]
|
||||
if !ok {
|
||||
t.Fatalf("sip.response.dtmf.create processor not registered")
|
||||
}
|
||||
|
||||
processorInstance, err := registration.New(config.ProcessorConfig{
|
||||
Type: "sip.response.dtmf.create",
|
||||
Params: map[string]any{
|
||||
"preWait": 0.0,
|
||||
"digits": "good.wav",
|
||||
"postWait": 0.0,
|
||||
},
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
t.Fatalf("failed to filter sip.response.dtmf.create processor: %s", err)
|
||||
}
|
||||
|
||||
if processorInstance.Type() != "sip.response.dtmf.create" {
|
||||
t.Fatalf("sip.response.dtmf.create processor has wrong type: %s", processorInstance.Type())
|
||||
}
|
||||
}
|
||||
@@ -654,6 +654,10 @@
|
||||
"function": {
|
||||
"type": "string",
|
||||
"default": "process"
|
||||
},
|
||||
"enableWasi": {
|
||||
"type": "boolean",
|
||||
"default": false
|
||||
}
|
||||
},
|
||||
"required": ["path"],
|
||||
|
||||
Reference in New Issue
Block a user