Compare commits

...

44 Commits

Author SHA1 Message Date
Joel Wetzell 419bcf7ad4 fix extension on windows builds 2026-05-17 13:13:41 -05:00
Joel Wetzell c52c4299e9 add release creation and artificat upload 2026-05-17 13:06:36 -05:00
Joel Wetzell 8bfcbea992 remove zig setup from macos jobs 2026-05-17 12:53:46 -05:00
Joel Wetzell b31442b794 split macos and build natively 2026-05-17 12:53:05 -05:00
Joel Wetzell 6a324a41b5 add job to setup release properties 2026-05-17 12:43:15 -05:00
Joel Wetzell 49227f9a82 add macos build job 2026-05-17 12:32:57 -05:00
Joel Wetzell 2ba309636f set CGO enabled for native go builds 2026-05-17 12:19:33 -05:00
Joel Wetzell 1d8756508d split linux build into two 2026-05-17 12:17:19 -05:00
Joel Wetzell 69e839efb2 add step to install alsa 2026-05-17 11:44:38 -05:00
Joel Wetzell dd28c40b19 only docker build and push on tag 2026-05-17 11:40:03 -05:00
Joel Wetzell 410c2c4e1f start working on getting rid of gorelease and full cross platform builds 2026-05-17 11:39:00 -05:00
Joel Wetzell e9d5688852 Merge pull request #155 from jwetzell/config-file-permission-bits
tighten up permission bits on config file writes
2026-05-17 10:09:24 -05:00
Joel Wetzell df532d7677 Merge pull request #154 from jwetzell/fix/http-server-read-header-timeout
add read header timeout to http servers
2026-05-17 10:08:00 -05:00
Joel Wetzell 727d63cc32 tighten up permission bits on config file writes 2026-05-17 10:05:27 -05:00
Joel Wetzell 9125b323ff add read header timeout to http servers 2026-05-17 10:03:48 -05:00
Joel Wetzell ad4aa91e08 minor linting things 2026-05-17 09:50:08 -05:00
Joel Wetzell 4bdfe0b00a add error return to database module 2026-05-17 09:50:01 -05:00
Joel Wetzell 2fdf6d1a61 rearrange error return 2026-05-17 09:49:36 -05:00
Joel Wetzell b4d4ef3421 cleanup some error handling lint issues 2026-05-17 09:48:49 -05:00
Joel Wetzell 8752b35ea4 Merge pull request #153 from jwetzell/fix/serial-client-closing
close serial client more reliably
2026-05-17 09:06:36 -05:00
Joel Wetzell e5c8e01bf0 close serial client more reliably 2026-05-17 08:37:11 -05:00
Joel Wetzell 91063f50da better port error message for serial.client 2026-05-17 08:35:59 -05:00
Joel Wetzell 08941ceaa0 Merge pull request #152 from jwetzell/fix/serial-client-schema
fix params schema for serial.client
2026-05-17 07:54:59 -05:00
Joel Wetzell acb834405e fix params schema for serial.client 2026-05-17 07:53:20 -05:00
Joel Wetzell ac2930b91b take reference to module for future process calls 2026-05-14 22:35:31 -05:00
Joel Wetzell d16e247a3a update artnet-go 2026-05-14 20:50:40 -05:00
Joel Wetzell a134a8929f update free-d-go 2026-05-14 19:50:38 -05:00
Joel Wetzell ad91be50c4 pre-intialize and instance of the WASM script to use in process 2026-05-14 19:50:38 -05:00
Joel Wetzell d4abe7ed2d todo's 2026-05-14 19:50:38 -05:00
Joel Wetzell 0912949f31 add return early option for slice casting 2026-05-14 19:50:38 -05:00
Joel Wetzell b4b5e17265 Merge pull request #151 from jwetzell/benchmarks
add basic benchmark for most processors
2026-05-14 19:48:31 -05:00
Joel Wetzell 9eb05c8360 add basic benchmark for most processors 2026-05-14 19:44:19 -05:00
Joel Wetzell fa4997ba78 fix websocket connection disconnect and auto reconnect 2026-05-13 19:59:30 -05:00
Joel Wetzell dc0479c713 Merge pull request #149 from jwetzell/dependabot/go_modules/modernc.org/sqlite-1.50.1
Bump modernc.org/sqlite from 1.50.0 to 1.50.1
2026-05-13 19:24:53 -05:00
Joel Wetzell 4636ec0d44 Merge pull request #150 from jwetzell/websocket-client
add websocket.client module
2026-05-13 19:21:40 -05:00
Joel Wetzell 5d8df7ed2a replace sqlite version query 2026-05-13 19:21:22 -05:00
Joel Wetzell b58beb5568 Merge pull request #148 from jwetzell/dependabot/go_modules/github.com/urfave/cli/v3-3.9.0
Bump github.com/urfave/cli/v3 from 3.8.0 to 3.9.0
2026-05-13 19:18:21 -05:00
Joel Wetzell 58ffc6a12b add websocket.client module 2026-05-13 19:11:48 -05:00
dependabot[bot] 526e3afa5f Bump modernc.org/sqlite from 1.50.0 to 1.50.1
Bumps [modernc.org/sqlite](https://gitlab.com/cznic/sqlite) from 1.50.0 to 1.50.1.
- [Changelog](https://gitlab.com/cznic/sqlite/blob/master/CHANGELOG.md)
- [Commits](https://gitlab.com/cznic/sqlite/compare/v1.50.0...v1.50.1)

---
updated-dependencies:
- dependency-name: modernc.org/sqlite
  dependency-version: 1.50.1
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2026-05-12 22:17:30 +00:00
dependabot[bot] ea977f4634 Bump github.com/urfave/cli/v3 from 3.8.0 to 3.9.0
Bumps [github.com/urfave/cli/v3](https://github.com/urfave/cli) from 3.8.0 to 3.9.0.
- [Release notes](https://github.com/urfave/cli/releases)
- [Changelog](https://github.com/urfave/cli/blob/main/docs/CHANGELOG.md)
- [Commits](https://github.com/urfave/cli/compare/v3.8.0...v3.9.0)

---
updated-dependencies:
- dependency-name: github.com/urfave/cli/v3
  dependency-version: 3.9.0
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2026-05-12 22:17:19 +00:00
Joel Wetzell 9d22f9fc47 chore: updates 2026-05-09 13:49:48 -05:00
Joel Wetzell 7367f55fa9 chore: go fix 2026-05-09 13:37:02 -05:00
Joel Wetzell 1ac93ebe21 Merge pull request #147 from jwetzell/limit-context-values
pull all non-request scoped values out of context
2026-05-06 21:34:55 -05:00
Joel Wetzell 833bd529d6 pull all non-request scoped values out of context 2026-05-06 21:33:16 -05:00
120 changed files with 2196 additions and 807 deletions
+191 -10
View File
@@ -4,13 +4,45 @@ on:
push: push:
tags: tags:
- "v*" - "v*"
workflow_dispatch:
permissions: permissions:
contents: write contents: write
jobs: jobs:
goreleaser: setup_release:
runs-on: ubuntu-latest runs-on: ubuntu-latest
outputs:
version: ${{ steps.set_version.outputs.version }}
short_commit: ${{ steps.set_commit.outputs.short_commit }}
steps:
- name: checkout
uses: actions/checkout@v6
with:
fetch-depth: 0
- name: set environment variables
run: echo "SHOWBRIDGE_VERSION=${GITHUB_REF_NAME}" >> $GITHUB_ENV
- name: clean tag
if: startsWith(github.ref, 'refs/tags/v')
run: echo "SHOWBRIDGE_VERSION=${SHOWBRIDGE_VERSION#v}" >> $GITHUB_ENV
- name: set version
id: set_version
run: echo "version=${SHOWBRIDGE_VERSION}" >> $GITHUB_OUTPUT
- name: set commit
id: set_commit
run: echo "short_commit=${GITHUB_SHA::7}" >> $GITHUB_OUTPUT
- name: create release
uses: softprops/action-gh-release@v3
if: github.ref_type == 'tag' && github.event_name != 'workflow_dispatch' && startsWith(github.ref, 'refs/tags/v')
with:
draft: true
generate_release_notes: true
linux_amd64:
runs-on: ubuntu-24.04
needs: setup_release
env:
SHOWBRIDGE_VERSION: ${{ needs.setup_release.outputs.version }}
SHORT_COMMIT: ${{ needs.setup_release.outputs.short_commit }}
steps: steps:
- name: checkout - name: checkout
uses: actions/checkout@v6 uses: actions/checkout@v6
@@ -20,18 +52,166 @@ jobs:
uses: actions/setup-go@v6 uses: actions/setup-go@v6
with: with:
go-version-file: "go.mod" go-version-file: "go.mod"
- name: release - name: install alsa lib
uses: goreleaser/goreleaser-action@v7 run: sudo apt-get install -y libasound2-dev
- name: build
run: |
CGO_ENABLED=1 go build -o showbridge -ldflags="-s -w -X main.version=${SHOWBRIDGE_VERSION}-${SHORT_COMMIT}" ./cmd/showbridge
tar -czf showbridge_${SHOWBRIDGE_VERSION}_linux-amd64.tar.gz showbridge
- name: upload linux artifacts
uses: actions/upload-artifact@v7
if: github.event_name == 'workflow_dispatch'
with: with:
workdir: cmd/showbridge name: showbridge-linux-amd64
distribution: goreleaser path: |
version: "v2.13.0" showbridge_*.tar.gz
args: release --clean - name: upload artifacts to release
env: uses: softprops/action-gh-release@v3
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} if: github.ref_type == 'tag' && github.event_name != 'workflow_dispatch' && startsWith(github.ref, 'refs/tags/v')
with:
draft: true
files: showbridge_*.tar.gz
linux_arm64:
runs-on: ubuntu-24.04-arm
needs: setup_release
env:
SHOWBRIDGE_VERSION: ${{ needs.setup_release.outputs.version }}
SHORT_COMMIT: ${{ needs.setup_release.outputs.short_commit }}
steps:
- name: checkout
uses: actions/checkout@v6
with:
fetch-depth: 0
- name: setup go
uses: actions/setup-go@v6
with:
go-version-file: "go.mod"
- name: install alsa lib
run: sudo apt-get install -y libasound2-dev
- name: build
run: |
CGO_ENABLED=1 go build -o showbridge -ldflags="-s -w -X main.version=${SHOWBRIDGE_VERSION}-${SHORT_COMMIT}" ./cmd/showbridge
tar -czf showbridge_${SHOWBRIDGE_VERSION}_linux-arm64.tar.gz showbridge
- name: upload linux artifacts
uses: actions/upload-artifact@v7
if: github.event_name == 'workflow_dispatch'
with:
name: showbridge-linux-arm64
path: |
showbridge_*.tar.gz
- name: upload artifacts to release
uses: softprops/action-gh-release@v3
if: github.ref_type == 'tag' && github.event_name != 'workflow_dispatch' && startsWith(github.ref, 'refs/tags/v')
with:
draft: true
files: showbridge_*.tar.gz
windows:
runs-on: ubuntu-latest
needs: setup_release
env:
SHOWBRIDGE_VERSION: ${{ needs.setup_release.outputs.version }}
SHORT_COMMIT: ${{ needs.setup_release.outputs.short_commit }}
steps:
- name: checkout
uses: actions/checkout@v6
with:
fetch-depth: 0
- name: setup go
uses: actions/setup-go@v6
with:
go-version-file: "go.mod"
- name: setup zig
uses: mlugg/setup-zig@v2
with:
version: 0.16.0
- name: build amd64
run: |
CGO_ENABLED=1 GOOS=windows GOARCH=amd64 CC="zig cc -target x86_64-windows-gnu" CXX="zig c++ -target x86_64-windows-gnu" go build -o showbridge.exe -ldflags="-s -w -X main.version=${SHOWBRIDGE_VERSION}-${SHORT_COMMIT}" ./cmd/showbridge
zip showbridge_${SHOWBRIDGE_VERSION}_windows-amd64.zip showbridge.exe
- name: build arm64
run: |
CGO_ENABLED=1 GOOS=windows GOARCH=arm64 CC="zig cc -target aarch64-windows-gnu" CXX="zig c++ -target aarch64-windows-gnu" go build -o showbridge.exe -ldflags="-s -w -X main.version=${SHOWBRIDGE_VERSION}-${SHORT_COMMIT}" ./cmd/showbridge
zip showbridge_${SHOWBRIDGE_VERSION}_windows-arm64.zip showbridge.exe
- name: upload windows artifacts
uses: actions/upload-artifact@v7
if: github.event_name == 'workflow_dispatch'
with:
name: showbridge-windows
path: |
showbridge_*.zip
- name: upload artifacts to release
uses: softprops/action-gh-release@v3
if: github.ref_type == 'tag' && github.event_name != 'workflow_dispatch' && startsWith(github.ref, 'refs/tags/v')
with:
draft: true
files: showbridge_*.zip
macos_arm64:
runs-on: macos-26
needs: setup_release
env:
SHOWBRIDGE_VERSION: ${{ needs.setup_release.outputs.version }}
SHORT_COMMIT: ${{ needs.setup_release.outputs.short_commit }}
steps:
- name: checkout
uses: actions/checkout@v6
with:
fetch-depth: 0
- name: setup go
uses: actions/setup-go@v6
with:
go-version-file: "go.mod"
- name: build
run: |
CGO_ENABLED=1 GOOS=darwin GOARCH=arm64 go build -o showbridge -ldflags="-s -w -X main.version=${SHOWBRIDGE_VERSION}-${SHORT_COMMIT}" ./cmd/showbridge
tar -czf showbridge_${SHOWBRIDGE_VERSION}_macOS-arm64.tar.gz showbridge
- name: upload macos artifacts
uses: actions/upload-artifact@v7
if: github.event_name == 'workflow_dispatch'
with:
name: showbridge-macos-arm64
path: |
showbridge_*.tar.gz
- name: upload artifacts to release
uses: softprops/action-gh-release@v3
if: github.ref_type == 'tag' && github.event_name != 'workflow_dispatch' && startsWith(github.ref, 'refs/tags/v')
with:
draft: true
files: showbridge_*.tar.gz
macos_amd64:
runs-on: macos-26-intel
needs: setup_release
env:
SHOWBRIDGE_VERSION: ${{ needs.setup_release.outputs.version }}
SHORT_COMMIT: ${{ needs.setup_release.outputs.short_commit }}
steps:
- name: checkout
uses: actions/checkout@v6
with:
fetch-depth: 0
- name: setup go
uses: actions/setup-go@v6
with:
go-version-file: "go.mod"
- name: build
run: |
CGO_ENABLED=1 GOOS=darwin GOARCH=amd64 go build -o showbridge -ldflags="-s -w -X main.version=${SHOWBRIDGE_VERSION}-${SHORT_COMMIT}" ./cmd/showbridge
tar -czf showbridge_${SHOWBRIDGE_VERSION}_macOS-amd64.tar.gz showbridge
- name: upload macos artifacts
uses: actions/upload-artifact@v7
if: github.event_name == 'workflow_dispatch'
with:
name: showbridge-macos-amd64
path: |
showbridge_*.tar.gz
- name: upload artifacts to release
uses: softprops/action-gh-release@v3
if: github.ref_type == 'tag' && github.event_name != 'workflow_dispatch' && startsWith(github.ref, 'refs/tags/v')
with:
draft: true
files: showbridge_*.tar.gz
docker: docker:
runs-on: ubuntu-latest runs-on: ubuntu-latest
needs: goreleaser needs: linux_amd64
steps: steps:
- name: Check out repository - name: Check out repository
uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0 uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0
@@ -57,6 +237,7 @@ jobs:
- name: Build and push - name: Build and push
uses: docker/build-push-action@bcafcacb16a39f128d818304e6c9c0c18556b85f # v7.1.0 uses: docker/build-push-action@bcafcacb16a39f128d818304e6c9c0c18556b85f # v7.1.0
if: github.ref_type == 'tag'
with: with:
push: true push: true
context: ./ context: ./
+1 -1
View File
@@ -1,4 +1,4 @@
ARG GO_VERSION=1.26.2 ARG GO_VERSION=1.26.3
FROM golang:${GO_VERSION}-alpine AS build FROM golang:${GO_VERSION}-alpine AS build
RUN apk --no-cache add ca-certificates tzdata git RUN apk --no-cache add ca-certificates tzdata git
WORKDIR /build WORKDIR /build
+6 -3
View File
@@ -127,6 +127,9 @@ func readConfig(configPath string) (config.Config, error) {
} }
validatedConfigBytes, err := json.Marshal(yamlMap) validatedConfigBytes, err := json.Marshal(yamlMap)
if err != nil {
return config.Config{}, err
}
err = json.Unmarshal(validatedConfigBytes, &cfg) err = json.Unmarshal(validatedConfigBytes, &cfg)
if err != nil { if err != nil {
@@ -142,7 +145,7 @@ func writeConfig(configPath string, newConfig config.Config) error {
return err return err
} }
err = os.WriteFile(configPath, configBytes, 0644) err = os.WriteFile(configPath, configBytes, 0600)
if err != nil { if err != nil {
return err return err
} }
@@ -156,7 +159,7 @@ func run(ctx context.Context, c *cli.Command) error {
return errors.New("config path cannot be empty") return errors.New("config path cannot be empty")
} }
logLevel := slog.LevelInfo var logLevel slog.Level
logLevelFromFlag := c.String("log-level") logLevelFromFlag := c.String("log-level")
@@ -260,7 +263,7 @@ func (app *showbridgeApp) handleChannels() {
app.routerMutex.Unlock() app.routerMutex.Unlock()
continue continue
} }
err, moduleErrors, routeErrors := app.router.UpdateConfig(config, false) moduleErrors, routeErrors, err := app.router.UpdateConfig(config, false)
if err != nil { if err != nil {
app.logger.Error("failed to update router config", "error", err) app.logger.Error("failed to update router config", "error", err)
app.routerMutex.Unlock() app.routerMutex.Unlock()
+3 -3
View File
@@ -15,9 +15,9 @@ func (r *Router) GetRunningConfig() config.Config {
return r.runningConfig return r.runningConfig
} }
func (r *Router) UpdateConfig(newConfig config.Config, triggerChangeChan bool) (error, []config.ModuleError, []config.RouteError) { func (r *Router) UpdateConfig(newConfig config.Config, triggerChangeChan bool) ([]config.ModuleError, []config.RouteError, error) {
if !r.runningConfigMu.TryLock() { if !r.runningConfigMu.TryLock() {
return errors.New("config update in progress"), nil, nil return nil, nil, errors.New("config update in progress")
} }
defer r.runningConfigMu.Unlock() defer r.runningConfigMu.Unlock()
oldConfig := r.runningConfig oldConfig := r.runningConfig
@@ -81,5 +81,5 @@ func (r *Router) UpdateConfig(newConfig config.Config, triggerChangeChan bool) (
r.ConfigChange <- newConfig r.ConfigChange <- newConfig
} }
return nil, moduleErrors, routeErrors return moduleErrors, routeErrors, nil
} }
+21 -22
View File
@@ -1,6 +1,6 @@
module github.com/jwetzell/showbridge-go module github.com/jwetzell/showbridge-go
go 1.26.2 go 1.26.3
require ( require (
github.com/eclipse/paho.mqtt.golang v1.5.1 github.com/eclipse/paho.mqtt.golang v1.5.1
@@ -10,14 +10,14 @@ require (
github.com/extism/go-sdk v1.7.1 github.com/extism/go-sdk v1.7.1
github.com/google/jsonschema-go v0.4.3 github.com/google/jsonschema-go v0.4.3
github.com/gorilla/websocket v1.5.3 github.com/gorilla/websocket v1.5.3
github.com/jwetzell/artnet-go v0.2.1 github.com/jwetzell/artnet-go v0.2.2
github.com/jwetzell/free-d-go v0.1.0 github.com/jwetzell/free-d-go v0.1.1
github.com/jwetzell/osc-go v0.3.0 github.com/jwetzell/osc-go v0.3.0
github.com/jwetzell/psn-go v0.3.0 github.com/jwetzell/psn-go v0.3.0
github.com/nats-io/nats-server/v2 v2.14.0 github.com/nats-io/nats-server/v2 v2.14.0
github.com/nats-io/nats.go v1.51.0 github.com/nats-io/nats.go v1.52.0
github.com/redis/go-redis/v9 v9.19.0 github.com/redis/go-redis/v9 v9.19.0
github.com/urfave/cli/v3 v3.8.0 github.com/urfave/cli/v3 v3.9.0
gitlab.com/gomidi/midi/v2 v2.3.23 gitlab.com/gomidi/midi/v2 v2.3.23
go.bug.st/serial v1.6.4 go.bug.st/serial v1.6.4
go.opentelemetry.io/otel v1.43.0 go.opentelemetry.io/otel v1.43.0
@@ -25,17 +25,17 @@ require (
go.opentelemetry.io/otel/sdk v1.43.0 go.opentelemetry.io/otel/sdk v1.43.0
go.opentelemetry.io/otel/trace v1.43.0 go.opentelemetry.io/otel/trace v1.43.0
modernc.org/quickjs v0.18.1 modernc.org/quickjs v0.18.1
modernc.org/sqlite v1.50.0 modernc.org/sqlite v1.50.1
sigs.k8s.io/yaml v1.6.0 sigs.k8s.io/yaml v1.6.0
) )
require ( require (
github.com/antithesishq/antithesis-sdk-go v0.7.0-default-no-op // indirect github.com/antithesishq/antithesis-sdk-go v0.7.0 // indirect
github.com/cenkalti/backoff/v5 v5.0.3 // indirect github.com/cenkalti/backoff/v5 v5.0.3 // indirect
github.com/cespare/xxhash/v2 v2.3.0 // indirect github.com/cespare/xxhash/v2 v2.3.0 // indirect
github.com/creack/goselect v0.1.2 // indirect github.com/creack/goselect v0.1.3 // indirect
github.com/dustin/go-humanize v1.0.1 // indirect github.com/dustin/go-humanize v1.0.1 // indirect
github.com/dylibso/observe-sdk/go v0.0.0-20240819160327-2d926c5d788a // indirect github.com/dylibso/observe-sdk/go v0.0.0-20240828172851-9145d8ad07e1 // indirect
github.com/emiago/dtls/v3 v3.0.0-20260122183559-8b8d23e359c0 // indirect github.com/emiago/dtls/v3 v3.0.0-20260122183559-8b8d23e359c0 // indirect
github.com/go-audio/riff v1.0.0 // indirect github.com/go-audio/riff v1.0.0 // indirect
github.com/go-logr/logr v1.4.3 // indirect github.com/go-logr/logr v1.4.3 // indirect
@@ -47,10 +47,10 @@ require (
github.com/google/go-tpm v0.9.8 // indirect github.com/google/go-tpm v0.9.8 // indirect
github.com/google/uuid v1.6.0 // indirect github.com/google/uuid v1.6.0 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.28.0 // indirect github.com/grpc-ecosystem/grpc-gateway/v2 v2.28.0 // indirect
github.com/ianlancetaylor/demangle v0.0.0-20240805132620-81f5be970eca // indirect github.com/ianlancetaylor/demangle v0.0.0-20260505044615-1ff4bf46051f // indirect
github.com/icholy/digest v1.1.0 // indirect github.com/icholy/digest v1.1.0 // indirect
github.com/klauspost/compress v1.18.5 // indirect github.com/klauspost/compress v1.18.6 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect github.com/mattn/go-isatty v0.0.22 // indirect
github.com/minio/highwayhash v1.0.4 // indirect github.com/minio/highwayhash v1.0.4 // indirect
github.com/nats-io/jwt/v2 v2.8.1 // indirect github.com/nats-io/jwt/v2 v2.8.1 // indirect
github.com/nats-io/nkeys v0.4.15 // indirect github.com/nats-io/nkeys v0.4.15 // indirect
@@ -59,13 +59,12 @@ require (
github.com/pion/logging v0.2.4 // indirect github.com/pion/logging v0.2.4 // indirect
github.com/pion/randutil v0.1.0 // indirect github.com/pion/randutil v0.1.0 // indirect
github.com/pion/rtcp v1.2.16 // indirect github.com/pion/rtcp v1.2.16 // indirect
github.com/pion/rtp v1.8.26 // indirect github.com/pion/rtp v1.10.2 // indirect
github.com/pion/srtp/v3 v3.0.9 // indirect github.com/pion/srtp/v3 v3.0.10 // indirect
github.com/pion/transport/v3 v3.1.1 // indirect
github.com/pion/transport/v4 v4.0.1 // indirect github.com/pion/transport/v4 v4.0.1 // indirect
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect
github.com/tetratelabs/wabin v0.0.0-20230304001439-f6f874872834 // indirect github.com/tetratelabs/wabin v0.0.0-20230304001439-f6f874872834 // indirect
github.com/tetratelabs/wazero v1.9.0 // indirect github.com/tetratelabs/wazero v1.11.0 // indirect
github.com/zaf/g711 v1.4.0 // indirect github.com/zaf/g711 v1.4.0 // indirect
go.opentelemetry.io/auto/sdk v1.2.1 // indirect go.opentelemetry.io/auto/sdk v1.2.1 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.43.0 // indirect go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.43.0 // indirect
@@ -73,19 +72,19 @@ require (
go.opentelemetry.io/proto/otlp v1.10.0 // indirect go.opentelemetry.io/proto/otlp v1.10.0 // indirect
go.uber.org/atomic v1.11.0 // indirect go.uber.org/atomic v1.11.0 // indirect
go.yaml.in/yaml/v2 v2.4.2 // indirect go.yaml.in/yaml/v2 v2.4.2 // indirect
golang.org/x/crypto v0.50.0 // indirect golang.org/x/crypto v0.51.0 // indirect
golang.org/x/net v0.52.0 // indirect golang.org/x/net v0.54.0 // indirect
golang.org/x/sync v0.20.0 // indirect golang.org/x/sync v0.20.0 // indirect
golang.org/x/sys v0.43.0 // indirect golang.org/x/sys v0.44.0 // indirect
golang.org/x/text v0.36.0 // indirect golang.org/x/text v0.37.0 // indirect
golang.org/x/time v0.15.0 // indirect golang.org/x/time v0.15.0 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20260401024825-9d38bb4040a9 // indirect google.golang.org/genproto/googleapis/api v0.0.0-20260401024825-9d38bb4040a9 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20260401024825-9d38bb4040a9 // indirect google.golang.org/genproto/googleapis/rpc v0.0.0-20260401024825-9d38bb4040a9 // indirect
google.golang.org/grpc v1.80.0 // indirect google.golang.org/grpc v1.80.0 // indirect
google.golang.org/protobuf v1.36.11 // indirect google.golang.org/protobuf v1.36.11 // indirect
gopkg.in/hraban/opus.v2 v2.0.0-20230925203106-0188a62cb302 // indirect gopkg.in/hraban/opus.v2 v2.0.0-20230925203106-0188a62cb302 // indirect
modernc.org/libc v1.72.1 // indirect modernc.org/libc v1.72.3 // indirect
modernc.org/libquickjs v0.12.6 // indirect modernc.org/libquickjs v0.12.7 // indirect
modernc.org/mathutil v1.7.1 // indirect modernc.org/mathutil v1.7.1 // indirect
modernc.org/memory v1.11.0 // indirect modernc.org/memory v1.11.0 // indirect
) )
+46 -48
View File
@@ -1,5 +1,5 @@
github.com/antithesishq/antithesis-sdk-go v0.7.0-default-no-op h1:Z/MZK75wC/NSrkgqeNIa7jexam9uWzhLmFTSCPI/kn0= github.com/antithesishq/antithesis-sdk-go v0.7.0 h1:uWDG8BqLD1lI2ps38WDz2vXflrTX2+vLX0SvZtztJtE=
github.com/antithesishq/antithesis-sdk-go v0.7.0-default-no-op/go.mod h1:FQyySiasQQM8735Ddel3MRojmy4dA1IqCeyJ5jmPMbI= github.com/antithesishq/antithesis-sdk-go v0.7.0/go.mod h1:FQyySiasQQM8735Ddel3MRojmy4dA1IqCeyJ5jmPMbI=
github.com/bsm/ginkgo/v2 v2.12.0 h1:Ny8MWAHyOepLGlLKYmXG4IEkioBysk6GpaRTLC8zwWs= github.com/bsm/ginkgo/v2 v2.12.0 h1:Ny8MWAHyOepLGlLKYmXG4IEkioBysk6GpaRTLC8zwWs=
github.com/bsm/ginkgo/v2 v2.12.0/go.mod h1:SwYbGRRDovPVboqFv0tPTcG1sN61LM1Z4ARdbAV9g4c= github.com/bsm/ginkgo/v2 v2.12.0/go.mod h1:SwYbGRRDovPVboqFv0tPTcG1sN61LM1Z4ARdbAV9g4c=
github.com/bsm/gomega v1.27.10 h1:yeMWxP2pV2fG3FgAODIY8EiRE3dy0aeFYt4l7wh6yKA= github.com/bsm/gomega v1.27.10 h1:yeMWxP2pV2fG3FgAODIY8EiRE3dy0aeFYt4l7wh6yKA=
@@ -8,14 +8,14 @@ github.com/cenkalti/backoff/v5 v5.0.3 h1:ZN+IMa753KfX5hd8vVaMixjnqRZ3y8CuJKRKj1x
github.com/cenkalti/backoff/v5 v5.0.3/go.mod h1:rkhZdG3JZukswDf7f0cwqPNk4K0sa+F97BxZthm/crw= github.com/cenkalti/backoff/v5 v5.0.3/go.mod h1:rkhZdG3JZukswDf7f0cwqPNk4K0sa+F97BxZthm/crw=
github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs= github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs=
github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
github.com/creack/goselect v0.1.2 h1:2DNy14+JPjRBgPzAd1thbQp4BSIihxcBf0IXhQXDRa0= github.com/creack/goselect v0.1.3 h1:MaGNMclRo7P2Jl21hBpR1Cn33ITSbKP6E49RtfblLKc=
github.com/creack/goselect v0.1.2/go.mod h1:a/NhLweNvqIYMuxcMOuWY516Cimucms3DglDzQP3hKY= github.com/creack/goselect v0.1.3/go.mod h1:a/NhLweNvqIYMuxcMOuWY516Cimucms3DglDzQP3hKY=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY= github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY=
github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto= github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto=
github.com/dylibso/observe-sdk/go v0.0.0-20240819160327-2d926c5d788a h1:UwSIFv5g5lIvbGgtf3tVwC7Ky9rmMFBp0RMs+6f6YqE= github.com/dylibso/observe-sdk/go v0.0.0-20240828172851-9145d8ad07e1 h1:idfl8M8rPW93NehFw5H1qqH8yG158t5POr+LX9avbJY=
github.com/dylibso/observe-sdk/go v0.0.0-20240819160327-2d926c5d788a/go.mod h1:C8DzXehI4zAbrdlbtOByKX6pfivJTBiV9Jjqv56Yd9Q= github.com/dylibso/observe-sdk/go v0.0.0-20240828172851-9145d8ad07e1/go.mod h1:C8DzXehI4zAbrdlbtOByKX6pfivJTBiV9Jjqv56Yd9Q=
github.com/eclipse/paho.mqtt.golang v1.5.1 h1:/VSOv3oDLlpqR2Epjn1Q7b2bSTplJIeV2ISgCl2W7nE= github.com/eclipse/paho.mqtt.golang v1.5.1 h1:/VSOv3oDLlpqR2Epjn1Q7b2bSTplJIeV2ISgCl2W7nE=
github.com/eclipse/paho.mqtt.golang v1.5.1/go.mod h1:1/yJCneuyOoCOzKSsOTUc0AJfpsItBGWvYpBLimhArU= github.com/eclipse/paho.mqtt.golang v1.5.1/go.mod h1:1/yJCneuyOoCOzKSsOTUc0AJfpsItBGWvYpBLimhArU=
github.com/emiago/diago v0.28.0 h1:VCiimhFYLoBTsxH6WrufLSt6tKWG8Fv7LfCkZHqct2E= github.com/emiago/diago v0.28.0 h1:VCiimhFYLoBTsxH6WrufLSt6tKWG8Fv7LfCkZHqct2E=
@@ -61,36 +61,36 @@ github.com/grpc-ecosystem/grpc-gateway/v2 v2.28.0 h1:HWRh5R2+9EifMyIHV7ZV+MIZqgz
github.com/grpc-ecosystem/grpc-gateway/v2 v2.28.0/go.mod h1:JfhWUomR1baixubs02l85lZYYOm7LV6om4ceouMv45c= github.com/grpc-ecosystem/grpc-gateway/v2 v2.28.0/go.mod h1:JfhWUomR1baixubs02l85lZYYOm7LV6om4ceouMv45c=
github.com/hashicorp/golang-lru/v2 v2.0.7 h1:a+bsQ5rvGLjzHuww6tVxozPZFVghXaHOwFs4luLUK2k= github.com/hashicorp/golang-lru/v2 v2.0.7 h1:a+bsQ5rvGLjzHuww6tVxozPZFVghXaHOwFs4luLUK2k=
github.com/hashicorp/golang-lru/v2 v2.0.7/go.mod h1:QeFd9opnmA6QUJc5vARoKUSoFhyfM2/ZepoAG6RGpeM= github.com/hashicorp/golang-lru/v2 v2.0.7/go.mod h1:QeFd9opnmA6QUJc5vARoKUSoFhyfM2/ZepoAG6RGpeM=
github.com/ianlancetaylor/demangle v0.0.0-20240805132620-81f5be970eca h1:T54Ema1DU8ngI+aef9ZhAhNGQhcRTrWxVeG07F+c/Rw= github.com/ianlancetaylor/demangle v0.0.0-20260505044615-1ff4bf46051f h1:NW3E2QSchEk63/fjeEvWOa2cE02FSv9ox//VE/N4c8g=
github.com/ianlancetaylor/demangle v0.0.0-20240805132620-81f5be970eca/go.mod h1:gx7rwoVhcfuVKG5uya9Hs3Sxj7EIvldVofAWIUtGouw= github.com/ianlancetaylor/demangle v0.0.0-20260505044615-1ff4bf46051f/go.mod h1:gx7rwoVhcfuVKG5uya9Hs3Sxj7EIvldVofAWIUtGouw=
github.com/icholy/digest v1.1.0 h1:HfGg9Irj7i+IX1o1QAmPfIBNu/Q5A5Tu3n/MED9k9H4= github.com/icholy/digest v1.1.0 h1:HfGg9Irj7i+IX1o1QAmPfIBNu/Q5A5Tu3n/MED9k9H4=
github.com/icholy/digest v1.1.0/go.mod h1:QNrsSGQ5v7v9cReDI0+eyjsXGUoRSUZQHeQ5C4XLa0Y= github.com/icholy/digest v1.1.0/go.mod h1:QNrsSGQ5v7v9cReDI0+eyjsXGUoRSUZQHeQ5C4XLa0Y=
github.com/jwetzell/artnet-go v0.2.1 h1:iYTKWcwYrF5kBkYfkw2UbWvoueeA23iKEn7fR27mWZE= github.com/jwetzell/artnet-go v0.2.2 h1:vaXSmRrSlEdETPZ/gvw6aAmVqzQm0i+gfAwyIQkVsB0=
github.com/jwetzell/artnet-go v0.2.1/go.mod h1:gli97Z32a0kMkZ6taoTiK7/lqHcF/dhiGjGJdx/PxqA= github.com/jwetzell/artnet-go v0.2.2/go.mod h1:gli97Z32a0kMkZ6taoTiK7/lqHcF/dhiGjGJdx/PxqA=
github.com/jwetzell/free-d-go v0.1.0 h1:xHt6dvyit98X+OC3jVzV0aLidxbyzi3vI9QiYkteEtA= github.com/jwetzell/free-d-go v0.1.1 h1:pzY2c4qRxKFBZ2jO3z512ysvUI0BUmgd4mSlWPiFVRM=
github.com/jwetzell/free-d-go v0.1.0/go.mod h1:KmrkooRARRaxJTBSPvwt/6IMAIaHH1R8bSA8cwbbELw= github.com/jwetzell/free-d-go v0.1.1/go.mod h1:KmrkooRARRaxJTBSPvwt/6IMAIaHH1R8bSA8cwbbELw=
github.com/jwetzell/osc-go v0.3.0 h1:z75TxuQSEmdcmZ56OAepkDa3m88SdZh//3m4nBb/XZI= github.com/jwetzell/osc-go v0.3.0 h1:z75TxuQSEmdcmZ56OAepkDa3m88SdZh//3m4nBb/XZI=
github.com/jwetzell/osc-go v0.3.0/go.mod h1:kCs329JxY6Qjga08tRQ/Gl0PqhgQzLIMpOhm6uszvIc= github.com/jwetzell/osc-go v0.3.0/go.mod h1:kCs329JxY6Qjga08tRQ/Gl0PqhgQzLIMpOhm6uszvIc=
github.com/jwetzell/psn-go v0.3.0 h1:WVpCEmExYE8a+I5hQak5jNJJp2x35VdGX/VuMUKPmhY= github.com/jwetzell/psn-go v0.3.0 h1:WVpCEmExYE8a+I5hQak5jNJJp2x35VdGX/VuMUKPmhY=
github.com/jwetzell/psn-go v0.3.0/go.mod h1:bcEAeti4sQM375buujb3mIfmUstD4Aby18gq3ENb6+o= github.com/jwetzell/psn-go v0.3.0/go.mod h1:bcEAeti4sQM375buujb3mIfmUstD4Aby18gq3ENb6+o=
github.com/klauspost/compress v1.18.5 h1:/h1gH5Ce+VWNLSWqPzOVn6XBO+vJbCNGvjoaGBFW2IE= github.com/klauspost/compress v1.18.6 h1:2jupLlAwFm95+YDR+NwD2MEfFO9d4z4Prjl1XXDjuao=
github.com/klauspost/compress v1.18.5/go.mod h1:cwPg85FWrGar70rWktvGQj8/hthj3wpl0PGDogxkrSQ= github.com/klauspost/compress v1.18.6/go.mod h1:cwPg85FWrGar70rWktvGQj8/hthj3wpl0PGDogxkrSQ=
github.com/klauspost/cpuid/v2 v2.2.10 h1:tBs3QSyvjDyFTq3uoc/9xFpCuOsJQFNPiAhYdw2skhE= github.com/klauspost/cpuid/v2 v2.2.10 h1:tBs3QSyvjDyFTq3uoc/9xFpCuOsJQFNPiAhYdw2skhE=
github.com/klauspost/cpuid/v2 v2.2.10/go.mod h1:hqwkgyIinND0mEev00jJYCxPNVRVXFQeu1XKlok6oO0= github.com/klauspost/cpuid/v2 v2.2.10/go.mod h1:hqwkgyIinND0mEev00jJYCxPNVRVXFQeu1XKlok6oO0=
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk= github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY= github.com/mattn/go-isatty v0.0.22 h1:j8l17JJ9i6VGPUFUYoTUKPSgKe/83EYU2zBC7YNKMw4=
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= github.com/mattn/go-isatty v0.0.22/go.mod h1:ZXfXG4SQHsB/w3ZeOYbR0PrPwLy+n6xiMrJlRFqopa4=
github.com/minio/highwayhash v1.0.4 h1:asJizugGgchQod2ja9NJlGOWq4s7KsAWr5XUc9Clgl4= github.com/minio/highwayhash v1.0.4 h1:asJizugGgchQod2ja9NJlGOWq4s7KsAWr5XUc9Clgl4=
github.com/minio/highwayhash v1.0.4/go.mod h1:GGYsuwP/fPD6Y9hMiXuapVvlIUEhFhMTh0rxU3ik1LQ= github.com/minio/highwayhash v1.0.4/go.mod h1:GGYsuwP/fPD6Y9hMiXuapVvlIUEhFhMTh0rxU3ik1LQ=
github.com/nats-io/jwt/v2 v2.8.1 h1:V0xpGuD/N8Mi+fQNDynXohVvp7ZztevW5io8CUWlPmU= github.com/nats-io/jwt/v2 v2.8.1 h1:V0xpGuD/N8Mi+fQNDynXohVvp7ZztevW5io8CUWlPmU=
github.com/nats-io/jwt/v2 v2.8.1/go.mod h1:nWnOEEiVMiKHQpnAy4eXlizVEtSfzacZ1Q43LIRavZg= github.com/nats-io/jwt/v2 v2.8.1/go.mod h1:nWnOEEiVMiKHQpnAy4eXlizVEtSfzacZ1Q43LIRavZg=
github.com/nats-io/nats-server/v2 v2.14.0 h1:+8q0HrDFotwLLcGH/legOEOnowunhK+aZ4GYBIWpQlM= github.com/nats-io/nats-server/v2 v2.14.0 h1:+8q0HrDFotwLLcGH/legOEOnowunhK+aZ4GYBIWpQlM=
github.com/nats-io/nats-server/v2 v2.14.0/go.mod h1:ImVUUDvfClJbb6cuJQRc1VmgDCXKM5ds0OoiG9MVOKo= github.com/nats-io/nats-server/v2 v2.14.0/go.mod h1:ImVUUDvfClJbb6cuJQRc1VmgDCXKM5ds0OoiG9MVOKo=
github.com/nats-io/nats.go v1.51.0 h1:ByW84XTz6W03GSSsygsZcA+xgKK8vPGaa/FCAAEHnAI= github.com/nats-io/nats.go v1.52.0 h1:n3avV4VBsCgsdwh71TppsTwtv+QdPs7ntSKM8qJLGsc=
github.com/nats-io/nats.go v1.51.0/go.mod h1:26HypzazeOkyO3/mqd1zZd53STJN0EjCYF9Uy2ZOBno= github.com/nats-io/nats.go v1.52.0/go.mod h1:26HypzazeOkyO3/mqd1zZd53STJN0EjCYF9Uy2ZOBno=
github.com/nats-io/nkeys v0.4.15 h1:JACV5jRVO9V856KOapQ7x+EY8Jo3qw1vJt/9Jpwzkk4= github.com/nats-io/nkeys v0.4.15 h1:JACV5jRVO9V856KOapQ7x+EY8Jo3qw1vJt/9Jpwzkk4=
github.com/nats-io/nkeys v0.4.15/go.mod h1:CpMchTXC9fxA5zrMo4KpySxNjiDVvr8ANOSZdiNfUrs= github.com/nats-io/nkeys v0.4.15/go.mod h1:CpMchTXC9fxA5zrMo4KpySxNjiDVvr8ANOSZdiNfUrs=
github.com/nats-io/nuid v1.0.1 h1:5iA8DT8V7q8WK2EScv2padNa/rTESc1KdnPw4TC2paw= github.com/nats-io/nuid v1.0.1 h1:5iA8DT8V7q8WK2EScv2padNa/rTESc1KdnPw4TC2paw=
@@ -103,12 +103,10 @@ github.com/pion/randutil v0.1.0 h1:CFG1UdESneORglEsnimhUjf33Rwjubwj6xfiOXBa3mA=
github.com/pion/randutil v0.1.0/go.mod h1:XcJrSMMbbMRhASFVOlj/5hQial/Y8oH/HVo7TBZq+j8= github.com/pion/randutil v0.1.0/go.mod h1:XcJrSMMbbMRhASFVOlj/5hQial/Y8oH/HVo7TBZq+j8=
github.com/pion/rtcp v1.2.16 h1:fk1B1dNW4hsI78XUCljZJlC4kZOPk67mNRuQ0fcEkSo= github.com/pion/rtcp v1.2.16 h1:fk1B1dNW4hsI78XUCljZJlC4kZOPk67mNRuQ0fcEkSo=
github.com/pion/rtcp v1.2.16/go.mod h1:/as7VKfYbs5NIb4h6muQ35kQF/J0ZVNz2Z3xKoCBYOo= github.com/pion/rtcp v1.2.16/go.mod h1:/as7VKfYbs5NIb4h6muQ35kQF/J0ZVNz2Z3xKoCBYOo=
github.com/pion/rtp v1.8.26 h1:VB+ESQFQhBXFytD+Gk8cxB6dXeVf2WQzg4aORvAvAAc= github.com/pion/rtp v1.10.2 h1:l+f6tTDcAH6xwepaAoW791ddhuYsJlqRATOzirO04Mo=
github.com/pion/rtp v1.8.26/go.mod h1:rF5nS1GqbR7H/TCpKwylzeq6yDM+MM6k+On5EgeThEM= github.com/pion/rtp v1.10.2/go.mod h1:Au8fc6cEByy8RLTwKTQTEeQqDB/SJDxwL4mZuxYA5Pk=
github.com/pion/srtp/v3 v3.0.9 h1:lRGF4G61xxj+m/YluB3ZnBpiALSri2lTzba0kGZMrQY= github.com/pion/srtp/v3 v3.0.10 h1:tFirkpBb3XccP5VEXLi50GqXhv5SKPxqrdlhDCJlZrQ=
github.com/pion/srtp/v3 v3.0.9/go.mod h1:E+AuWd7Ug2Fp5u38MKnhduvpVkveXJX6J4Lq4rxUYt8= github.com/pion/srtp/v3 v3.0.10/go.mod h1:3mOTIB0cq9qlbn59V4ozvv9ClW/BSEbRp4cY0VtaR7M=
github.com/pion/transport/v3 v3.1.1 h1:Tr684+fnnKlhPceU+ICdrw6KKkTms+5qHMgw6bIkYOM=
github.com/pion/transport/v3 v3.1.1/go.mod h1:+c2eewC5WJQHiAA46fkMMzoYZSuGzA/7E2FPrOYHctQ=
github.com/pion/transport/v4 v4.0.1 h1:sdROELU6BZ63Ab7FrOLn13M6YdJLY20wldXW2Cu2k8o= github.com/pion/transport/v4 v4.0.1 h1:sdROELU6BZ63Ab7FrOLn13M6YdJLY20wldXW2Cu2k8o=
github.com/pion/transport/v4 v4.0.1/go.mod h1:nEuEA4AD5lPdcIegQDpVLgNoDGreqM/YqmEx3ovP4jM= github.com/pion/transport/v4 v4.0.1/go.mod h1:nEuEA4AD5lPdcIegQDpVLgNoDGreqM/YqmEx3ovP4jM=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
@@ -123,10 +121,10 @@ github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu
github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U= github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U=
github.com/tetratelabs/wabin v0.0.0-20230304001439-f6f874872834 h1:ZF+QBjOI+tILZjBaFj3HgFonKXUcwgJ4djLb6i42S3Q= github.com/tetratelabs/wabin v0.0.0-20230304001439-f6f874872834 h1:ZF+QBjOI+tILZjBaFj3HgFonKXUcwgJ4djLb6i42S3Q=
github.com/tetratelabs/wabin v0.0.0-20230304001439-f6f874872834/go.mod h1:m9ymHTgNSEjuxvw8E7WWe4Pl4hZQHXONY8wE6dMLaRk= github.com/tetratelabs/wabin v0.0.0-20230304001439-f6f874872834/go.mod h1:m9ymHTgNSEjuxvw8E7WWe4Pl4hZQHXONY8wE6dMLaRk=
github.com/tetratelabs/wazero v1.9.0 h1:IcZ56OuxrtaEz8UYNRHBrUa9bYeX9oVY93KspZZBf/I= github.com/tetratelabs/wazero v1.11.0 h1:+gKemEuKCTevU4d7ZTzlsvgd1uaToIDtlQlmNbwqYhA=
github.com/tetratelabs/wazero v1.9.0/go.mod h1:TSbcXCfFP0L2FGkRPxHphadXPjo1T6W+CseNNY7EkjM= github.com/tetratelabs/wazero v1.11.0/go.mod h1:eV28rsN8Q+xwjogd7f4/Pp4xFxO7uOGbLcD/LzB1wiU=
github.com/urfave/cli/v3 v3.8.0 h1:XqKPrm0q4P0q5JpoclYoCAv0/MIvH/jZ2umzuf8pNTI= github.com/urfave/cli/v3 v3.9.0 h1:AV9lIiPv3ukYnxunaCUsHnEozptYmDN2F0+yWqLMn/c=
github.com/urfave/cli/v3 v3.8.0/go.mod h1:ysVLtOEmg2tOy6PknnYVhDoouyC/6N42TMeoMzskhso= github.com/urfave/cli/v3 v3.9.0/go.mod h1:ysVLtOEmg2tOy6PknnYVhDoouyC/6N42TMeoMzskhso=
github.com/zaf/g711 v1.4.0 h1:XZYkjjiAg9QTBnHqEg37m2I9q3IIDv5JRYXs2N8ma7c= github.com/zaf/g711 v1.4.0 h1:XZYkjjiAg9QTBnHqEg37m2I9q3IIDv5JRYXs2N8ma7c=
github.com/zaf/g711 v1.4.0/go.mod h1:eCDXt3dSp/kYYAoooba7ukD/Q75jvAaS4WOMr0l1Roo= github.com/zaf/g711 v1.4.0/go.mod h1:eCDXt3dSp/kYYAoooba7ukD/Q75jvAaS4WOMr0l1Roo=
github.com/zeebo/xxh3 v1.1.0 h1:s7DLGDK45Dyfg7++yxI0khrfwq9661w9EN78eP/UZVs= github.com/zeebo/xxh3 v1.1.0 h1:s7DLGDK45Dyfg7++yxI0khrfwq9661w9EN78eP/UZVs=
@@ -161,24 +159,24 @@ go.yaml.in/yaml/v2 v2.4.2 h1:DzmwEr2rDGHl7lsFgAHxmNz/1NlQ7xLIrlN2h5d1eGI=
go.yaml.in/yaml/v2 v2.4.2/go.mod h1:081UH+NErpNdqlCXm3TtEran0rJZGxAYx9hb/ELlsPU= go.yaml.in/yaml/v2 v2.4.2/go.mod h1:081UH+NErpNdqlCXm3TtEran0rJZGxAYx9hb/ELlsPU=
go.yaml.in/yaml/v3 v3.0.4 h1:tfq32ie2Jv2UxXFdLJdh3jXuOzWiL1fo0bu/FbuKpbc= go.yaml.in/yaml/v3 v3.0.4 h1:tfq32ie2Jv2UxXFdLJdh3jXuOzWiL1fo0bu/FbuKpbc=
go.yaml.in/yaml/v3 v3.0.4/go.mod h1:DhzuOOF2ATzADvBadXxruRBLzYTpT36CKvDb3+aBEFg= go.yaml.in/yaml/v3 v3.0.4/go.mod h1:DhzuOOF2ATzADvBadXxruRBLzYTpT36CKvDb3+aBEFg=
golang.org/x/crypto v0.50.0 h1:zO47/JPrL6vsNkINmLoo/PH1gcxpls50DNogFvB5ZGI= golang.org/x/crypto v0.51.0 h1:IBPXwPfKxY7cWQZ38ZCIRPI50YLeevDLlLnyC5wRGTI=
golang.org/x/crypto v0.50.0/go.mod h1:3muZ7vA7PBCE6xgPX7nkzzjiUq87kRItoJQM1Yo8S+Q= golang.org/x/crypto v0.51.0/go.mod h1:8AdwkbraGNABw2kOX6YFPs3WM22XqI4EXEd8g+x7Oc8=
golang.org/x/mod v0.34.0 h1:xIHgNUUnW6sYkcM5Jleh05DvLOtwc6RitGHbDk4akRI= golang.org/x/mod v0.35.0 h1:Ww1D637e6Pg+Zb2KrWfHQUnH2dQRLBQyAtpr/haaJeM=
golang.org/x/mod v0.34.0/go.mod h1:ykgH52iCZe79kzLLMhyCUzhMci+nQj+0XkbXpNYtVjY= golang.org/x/mod v0.35.0/go.mod h1:+GwiRhIInF8wPm+4AoT6L0FA1QWAad3OMdTRx4tFYlU=
golang.org/x/net v0.52.0 h1:He/TN1l0e4mmR3QqHMT2Xab3Aj3L9qjbhRm78/6jrW0= golang.org/x/net v0.54.0 h1:2zJIZAxAHV/OHCDTCOHAYehQzLfSXuf/5SoL/Dv6w/w=
golang.org/x/net v0.52.0/go.mod h1:R1MAz7uMZxVMualyPXb+VaqGSa3LIaUqk0eEt3w36Sw= golang.org/x/net v0.54.0/go.mod h1:Sj4oj8jK6XmHpBZU/zWHw3BV3abl4Kvi+Ut7cQcY+cQ=
golang.org/x/sync v0.20.0 h1:e0PTpb7pjO8GAtTs2dQ6jYa5BWYlMuX047Dco/pItO4= golang.org/x/sync v0.20.0 h1:e0PTpb7pjO8GAtTs2dQ6jYa5BWYlMuX047Dco/pItO4=
golang.org/x/sync v0.20.0/go.mod h1:9xrNwdLfx4jkKbNva9FpL6vEN7evnE43NNNJQ2LF3+0= golang.org/x/sync v0.20.0/go.mod h1:9xrNwdLfx4jkKbNva9FpL6vEN7evnE43NNNJQ2LF3+0=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.21.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/sys v0.21.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.43.0 h1:Rlag2XtaFTxp19wS8MXlJwTvoh8ArU6ezoyFsMyCTNI= golang.org/x/sys v0.44.0 h1:ildZl3J4uzeKP07r2F++Op7E9B29JRUy+a27EibtBTQ=
golang.org/x/sys v0.43.0/go.mod h1:4GL1E5IUh+htKOUEOaiffhrAeqysfVGipDYzABqnCmw= golang.org/x/sys v0.44.0/go.mod h1:4GL1E5IUh+htKOUEOaiffhrAeqysfVGipDYzABqnCmw=
golang.org/x/text v0.36.0 h1:JfKh3XmcRPqZPKevfXVpI1wXPTqbkE5f7JA92a55Yxg= golang.org/x/text v0.37.0 h1:Cqjiwd9eSg8e0QAkyCaQTNHFIIzWtidPahFWR83rTrc=
golang.org/x/text v0.36.0/go.mod h1:NIdBknypM8iqVmPiuco0Dh6P5Jcdk8lJL0CUebqK164= golang.org/x/text v0.37.0/go.mod h1:a5sjxXGs9hsn/AJVwuElvCAo9v8QYLzvavO5z2PiM38=
golang.org/x/time v0.15.0 h1:bbrp8t3bGUeFOx08pvsMYRTCVSMk89u4tKbNOZbp88U= golang.org/x/time v0.15.0 h1:bbrp8t3bGUeFOx08pvsMYRTCVSMk89u4tKbNOZbp88U=
golang.org/x/time v0.15.0/go.mod h1:Y4YMaQmXwGQZoFaVFk4YpCt4FLQMYKZe9oeV/f4MSno= golang.org/x/time v0.15.0/go.mod h1:Y4YMaQmXwGQZoFaVFk4YpCt4FLQMYKZe9oeV/f4MSno=
golang.org/x/tools v0.43.0 h1:12BdW9CeB3Z+J/I/wj34VMl8X+fEXBxVR90JeMX5E7s= golang.org/x/tools v0.44.0 h1:UP4ajHPIcuMjT1GqzDWRlalUEoY+uzoZKnhOjbIPD2c=
golang.org/x/tools v0.43.0/go.mod h1:uHkMso649BX2cZK6+RpuIPXS3ho2hZo4FVwfoy1vIk0= golang.org/x/tools v0.44.0/go.mod h1:KA0AfVErSdxRZIsOVipbv3rQhVXTnlU6UhKxHd1seDI=
gonum.org/v1/gonum v0.17.0 h1:VbpOemQlsSMrYmn7T2OUvQ4dqxQXU+ouZFQsZOx50z4= gonum.org/v1/gonum v0.17.0 h1:VbpOemQlsSMrYmn7T2OUvQ4dqxQXU+ouZFQsZOx50z4=
gonum.org/v1/gonum v0.17.0/go.mod h1:El3tOrEuMpv2UdMrbNlKEh9vd86bmQ6vqIcDwxEOc1E= gonum.org/v1/gonum v0.17.0/go.mod h1:El3tOrEuMpv2UdMrbNlKEh9vd86bmQ6vqIcDwxEOc1E=
google.golang.org/genproto/googleapis/api v0.0.0-20260401024825-9d38bb4040a9 h1:VPWxll4HlMw1Vs/qXtN7BvhZqsS9cdAittCNvVENElA= google.golang.org/genproto/googleapis/api v0.0.0-20260401024825-9d38bb4040a9 h1:VPWxll4HlMw1Vs/qXtN7BvhZqsS9cdAittCNvVENElA=
@@ -198,8 +196,8 @@ gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gotest.tools/v3 v3.5.2 h1:7koQfIKdy+I8UTetycgUqXWSDwpgv193Ka+qRsmBY8Q= gotest.tools/v3 v3.5.2 h1:7koQfIKdy+I8UTetycgUqXWSDwpgv193Ka+qRsmBY8Q=
gotest.tools/v3 v3.5.2/go.mod h1:LtdLGcnqToBH83WByAAi/wiwSFCArdFIUV/xxN4pcjA= gotest.tools/v3 v3.5.2/go.mod h1:LtdLGcnqToBH83WByAAi/wiwSFCArdFIUV/xxN4pcjA=
modernc.org/cc/v4 v4.28.1 h1:XpLbkYVQ24E8tX5u8+yWGvaxerxkR/S4zqxI8ZoSBuc= modernc.org/cc/v4 v4.28.2 h1:3tQ0lf2ADtoby2EtSP+J7IE2SHwEJdP8ioR59wx7XpY=
modernc.org/cc/v4 v4.28.1/go.mod h1:OnovgIhbbMXMu1aISnJ0wvVD1KnW+cAUJkIrAWh+kVI= modernc.org/cc/v4 v4.28.2/go.mod h1:OnovgIhbbMXMu1aISnJ0wvVD1KnW+cAUJkIrAWh+kVI=
modernc.org/ccgo/v4 v4.34.0 h1:yRLPFZieg532OT4rp4JFNIVcquwalMX26G95WQDqwCQ= modernc.org/ccgo/v4 v4.34.0 h1:yRLPFZieg532OT4rp4JFNIVcquwalMX26G95WQDqwCQ=
modernc.org/ccgo/v4 v4.34.0/go.mod h1:AS5WYMyBakQ+fhsHhtP8mWB82KTGPkNNJDGfGQCe0/A= modernc.org/ccgo/v4 v4.34.0/go.mod h1:AS5WYMyBakQ+fhsHhtP8mWB82KTGPkNNJDGfGQCe0/A=
modernc.org/fileutil v1.4.0 h1:j6ZzNTftVS054gi281TyLjHPp6CPHr2KCxEXjEbD6SM= modernc.org/fileutil v1.4.0 h1:j6ZzNTftVS054gi281TyLjHPp6CPHr2KCxEXjEbD6SM=
@@ -210,10 +208,10 @@ modernc.org/gc/v3 v3.1.2 h1:ZtDCnhonXSZexk/AYsegNRV1lJGgaNZJuKjJSWKyEqo=
modernc.org/gc/v3 v3.1.2/go.mod h1:HFK/6AGESC7Ex+EZJhJ2Gni6cTaYpSMmU/cT9RmlfYY= modernc.org/gc/v3 v3.1.2/go.mod h1:HFK/6AGESC7Ex+EZJhJ2Gni6cTaYpSMmU/cT9RmlfYY=
modernc.org/goabi0 v0.2.0 h1:HvEowk7LxcPd0eq6mVOAEMai46V+i7Jrj13t4AzuNks= modernc.org/goabi0 v0.2.0 h1:HvEowk7LxcPd0eq6mVOAEMai46V+i7Jrj13t4AzuNks=
modernc.org/goabi0 v0.2.0/go.mod h1:CEFRnnJhKvWT1c1JTI3Avm+tgOWbkOu5oPA8eH8LnMI= modernc.org/goabi0 v0.2.0/go.mod h1:CEFRnnJhKvWT1c1JTI3Avm+tgOWbkOu5oPA8eH8LnMI=
modernc.org/libc v1.72.1 h1:db1xwJ6u1kE3KHTFTTbe2GCrczHPKzlURP0aDC4NGD0= modernc.org/libc v1.72.3 h1:ZnDF4tXn4NBXFutMMQC4vtbTFSXhhKzR73fv0beZEAU=
modernc.org/libc v1.72.1/go.mod h1:HRMiC/PhPGLIPM7GzAFCbI+oSgE3dhZ8FWftmRrHVlY= modernc.org/libc v1.72.3/go.mod h1:dn0dZNnnn1clLyvRxLxYExxiKRZIRENOfqQ8XEeg4Qs=
modernc.org/libquickjs v0.12.6 h1:TlABTRLKOFLeY3NxkoHZeLzGBTreA2a3DhmReVON23s= modernc.org/libquickjs v0.12.7 h1:jSU4+KWDnA6ILat9SAy5zMBSU3Cxtco1NzSJ7DZgCKc=
modernc.org/libquickjs v0.12.6/go.mod h1:ajFW8dWHtF8ggFWGbU2BBEM6FI0vemVWrd8nEHAPZpE= modernc.org/libquickjs v0.12.7/go.mod h1:ajFW8dWHtF8ggFWGbU2BBEM6FI0vemVWrd8nEHAPZpE=
modernc.org/mathutil v1.7.1 h1:GCZVGXdaN8gTqB1Mf/usp1Y/hSqgI2vAGGP4jZMCxOU= modernc.org/mathutil v1.7.1 h1:GCZVGXdaN8gTqB1Mf/usp1Y/hSqgI2vAGGP4jZMCxOU=
modernc.org/mathutil v1.7.1/go.mod h1:4p5IwJITfppl0G4sUEDtCr4DthTaT47/N3aT6MhfgJg= modernc.org/mathutil v1.7.1/go.mod h1:4p5IwJITfppl0G4sUEDtCr4DthTaT47/N3aT6MhfgJg=
modernc.org/memory v1.11.0 h1:o4QC8aMQzmcwCK3t3Ux/ZHmwFPzE6hf2Y5LbkRs+hbI= modernc.org/memory v1.11.0 h1:o4QC8aMQzmcwCK3t3Ux/ZHmwFPzE6hf2Y5LbkRs+hbI=
@@ -224,8 +222,8 @@ modernc.org/quickjs v0.18.1 h1:exrw1Bp1smLUVXiZ4M9yfUP24EeU1C2wCKD1IHN2JFk=
modernc.org/quickjs v0.18.1/go.mod h1:wMyqS7/VurEMUms6XwVQoX7UhJakAr9EMc8aPSL5Xjc= modernc.org/quickjs v0.18.1/go.mod h1:wMyqS7/VurEMUms6XwVQoX7UhJakAr9EMc8aPSL5Xjc=
modernc.org/sortutil v1.2.1 h1:+xyoGf15mM3NMlPDnFqrteY07klSFxLElE2PVuWIJ7w= modernc.org/sortutil v1.2.1 h1:+xyoGf15mM3NMlPDnFqrteY07klSFxLElE2PVuWIJ7w=
modernc.org/sortutil v1.2.1/go.mod h1:7ZI3a3REbai7gzCLcotuw9AC4VZVpYMjDzETGsSMqJE= modernc.org/sortutil v1.2.1/go.mod h1:7ZI3a3REbai7gzCLcotuw9AC4VZVpYMjDzETGsSMqJE=
modernc.org/sqlite v1.50.0 h1:eMowQSWLK0MeiQTdmz3lqoF5dqclujdlIKeJA11+7oM= modernc.org/sqlite v1.50.1 h1:l+cQvn0sd0zJJtfygGHuQJ5AjlrwXmWPw4KP3ZMwr9w=
modernc.org/sqlite v1.50.0/go.mod h1:m0w8xhwYUVY3H6pSDwc3gkJ/irZT/0YEXwBlhaxQEew= modernc.org/sqlite v1.50.1/go.mod h1:tcNzv5p84E0skkmJn038y+hWJbLQXQqEnQfeh5r2JLM=
modernc.org/strutil v1.2.1 h1:UneZBkQA+DX2Rp35KcM69cSsNES9ly8mQWD71HKlOA0= modernc.org/strutil v1.2.1 h1:UneZBkQA+DX2Rp35KcM69cSsNES9ly8mQWD71HKlOA0=
modernc.org/strutil v1.2.1/go.mod h1:EHkiggD70koQxjVdSBM3JKM7k6L0FbGE5eymy9i3B9A= modernc.org/strutil v1.2.1/go.mod h1:EHkiggD70koQxjVdSBM3JKM7k6L0FbGE5eymy9i3B9A=
modernc.org/token v1.1.0 h1:Xl7Ap9dKaEs5kLoOQeQmPWevfnk/DM5qcLcYlA8ys6Y= modernc.org/token v1.1.0 h1:Xl7Ap9dKaEs5kLoOQeQmPWevfnk/DM5qcLcYlA8ys6Y=
+8 -4
View File
@@ -53,12 +53,16 @@ func (as *ApiServer) Start(config config.ApiConfig) {
as.serverMu.Lock() as.serverMu.Lock()
defer as.serverMu.Unlock() defer as.serverMu.Unlock()
as.server = &http.Server{ as.server = &http.Server{
Addr: fmt.Sprintf(":%d", as.config.Port), Addr: fmt.Sprintf(":%d", as.config.Port),
Handler: mux, ReadHeaderTimeout: 5 * time.Second,
Handler: mux,
} }
go func() { go func() {
as.server.ListenAndServe() err := as.server.ListenAndServe()
if err != nil && err != http.ErrServerClosed {
as.logger.Error("server error", "error", err)
}
as.shutdown() as.shutdown()
}() }()
} }
@@ -148,7 +152,7 @@ func (as *ApiServer) handleConfigHTTP(w http.ResponseWriter, req *http.Request)
http.Error(w, "Bad request", http.StatusBadRequest) http.Error(w, "Bad request", http.StatusBadRequest)
return return
} }
err, moduleErrors, routeErrors := as.configurableRouter.UpdateConfig(newConfig, true) moduleErrors, routeErrors, err := as.configurableRouter.UpdateConfig(newConfig, true)
if err != nil { if err != nil {
http.Error(w, err.Error(), http.StatusConflict) http.Error(w, err.Error(), http.StatusConflict)
return return
+16
View File
@@ -81,11 +81,19 @@ func GetAnyAsByte(value any) (byte, bool) {
} }
func GetAnyAsByteSlice(value any) ([]byte, bool) { func GetAnyAsByteSlice(value any) ([]byte, bool) {
// already a []byte
byteSlice, ok := value.([]byte)
if ok {
return byteSlice, true
}
// check for a slice
v := reflect.ValueOf(value) v := reflect.ValueOf(value)
if v.Kind() != reflect.Slice { if v.Kind() != reflect.Slice {
return nil, false return nil, false
} }
// try to convert each element to a byte
result := make([]byte, v.Len()) result := make([]byte, v.Len())
for i := 0; i < v.Len(); i++ { for i := 0; i < v.Len(); i++ {
elem := v.Index(i).Interface() elem := v.Index(i).Interface()
@@ -99,6 +107,14 @@ func GetAnyAsByteSlice(value any) ([]byte, bool) {
} }
func GetAnyAsIntSlice(value any) ([]int, bool) { func GetAnyAsIntSlice(value any) ([]int, bool) {
// already a []byte
intSlice, ok := value.([]int)
if ok {
return intSlice, true
}
// check for a slice
v := reflect.ValueOf(value) v := reflect.ValueOf(value)
if v.Kind() != reflect.Slice { if v.Kind() != reflect.Slice {
return nil, false return nil, false
-8
View File
@@ -1,8 +0,0 @@
package common
type contextKey string
const RouterContextKey contextKey = contextKey("router")
const SourceContextKey contextKey = contextKey("source")
const ModulesContextKey contextKey = contextKey("modules")
const SenderContextKey contextKey = contextKey("sender")
+2 -2
View File
@@ -8,7 +8,7 @@ import (
type Module interface { type Module interface {
Id() string Id() string
Type() string Type() string
Start(context.Context) error Start(context.Context, RouteIO) error
Stop() Stop()
} }
@@ -22,5 +22,5 @@ type KeyValueModule interface {
} }
type DatabaseModule interface { type DatabaseModule interface {
Database() *sql.DB Database() (*sql.DB, error)
} }
+1 -32
View File
@@ -1,40 +1,9 @@
package common package common
import (
"context"
)
type WrappedPayload struct { type WrappedPayload struct {
Payload any Payload any
Router RouteIO
Modules map[string]Module Modules map[string]Module
Sender any
Source string Source string
End bool End bool
} }
func GetWrappedPayload(ctx context.Context, payload any) WrappedPayload {
wrappedPayload := WrappedPayload{
Payload: payload,
End: false,
}
modules := ctx.Value(ModulesContextKey)
if modules != nil {
moduleMap, ok := modules.(map[string]Module)
if ok {
wrappedPayload.Modules = moduleMap
} else {
wrappedPayload.Modules = make(map[string]Module)
}
}
sender := ctx.Value(SenderContextKey)
if sender != nil {
wrappedPayload.Sender = sender
}
source := ctx.Value(SourceContextKey)
if source != nil {
wrappedPayload.Source = source.(string)
}
return wrappedPayload
}
-82
View File
@@ -1,82 +0,0 @@
package common_test
import (
"context"
"reflect"
"testing"
"github.com/jwetzell/showbridge-go/internal/common"
"github.com/jwetzell/showbridge-go/internal/test"
)
func TestGoodGetWrappedPayload(t *testing.T) {
testCases := []struct {
name string
ctx context.Context
payload any
expected common.WrappedPayload
}{
{
name: "basic",
ctx: t.Context(),
payload: "test",
expected: common.WrappedPayload{
Payload: "test",
},
},
{
name: "with modules in context",
ctx: test.GetContextWithModules(t.Context(), map[string]common.Module{}),
payload: "test",
expected: common.WrappedPayload{
Payload: "test",
Modules: map[string]common.Module{},
},
},
{
name: "with sender in context",
ctx: test.GetContextWithSender(t.Context(), "sender"),
payload: "test",
expected: common.WrappedPayload{
Payload: "test",
Sender: "sender",
},
},
{
name: "with source in context",
ctx: test.GetContextWithSource(t.Context(), "source"),
payload: "test",
expected: common.WrappedPayload{
Payload: "test",
Source: "source",
},
},
{
name: "with all fields in context",
ctx: test.GetContextWithSource(
test.GetContextWithSender(
test.GetContextWithModules(t.Context(), map[string]common.Module{}),
"sender",
),
"source",
),
payload: "test",
expected: common.WrappedPayload{
Payload: "test",
Modules: map[string]common.Module{},
Sender: "sender",
Source: "source",
},
},
}
for _, testCase := range testCases {
t.Run(testCase.name, func(t *testing.T) {
wrappedPayload := common.GetWrappedPayload(testCase.ctx, testCase.payload)
if !reflect.DeepEqual(wrappedPayload, testCase.expected) {
t.Fatalf("GetWrappedPayload expected got %+v, expected %+v", wrappedPayload, testCase.expected)
}
})
}
}
+1 -1
View File
@@ -7,6 +7,6 @@ type Config struct {
} }
type Configurable interface { type Configurable interface {
UpdateConfig(newConfig Config, triggerChangeChannel bool) (error, []ModuleError, []RouteError) UpdateConfig(newConfig Config, triggerChangeChannel bool) ([]ModuleError, []RouteError, error)
GetRunningConfig() Config GetRunningConfig() Config
} }
+3 -2
View File
@@ -25,9 +25,10 @@ func (sf *SlipFramer) Decode(data []byte) [][]byte {
} }
if escapeNext { if escapeNext {
if packetByte == ESC_END { switch packetByte {
case ESC_END:
sf.buffer = append(sf.buffer, END) sf.buffer = append(sf.buffer, END)
} else if packetByte == ESC_ESC { case ESC_ESC:
sf.buffer = append(sf.buffer, ESC) sf.buffer = append(sf.buffer, ESC)
} }
escapeNext = false escapeNext = false
+7 -10
View File
@@ -3,7 +3,6 @@ package module
import ( import (
"context" "context"
"database/sql" "database/sql"
"errors"
"fmt" "fmt"
"log/slog" "log/slog"
@@ -32,7 +31,7 @@ func init() {
Properties: map[string]*jsonschema.Schema{ Properties: map[string]*jsonschema.Schema{
"dsn": { "dsn": {
Type: "string", Type: "string",
MinLength: jsonschema.Ptr(1), MinLength: new(1),
}, },
}, },
Required: []string{"dsn"}, Required: []string{"dsn"},
@@ -59,13 +58,8 @@ func (t *DbSqlite) Type() string {
return t.config.Type return t.config.Type
} }
func (t *DbSqlite) Start(ctx context.Context) error { func (t *DbSqlite) Start(ctx context.Context, router common.RouteIO) error {
t.logger.Debug("running") t.logger.Debug("running")
router, ok := ctx.Value(common.RouterContextKey).(common.RouteIO)
if !ok {
return errors.New("db.sqlite unable to get router from context")
}
t.router = router t.router = router
t.ctx = ctx t.ctx = ctx
@@ -85,6 +79,9 @@ func (t *DbSqlite) Stop() {
} }
} }
func (t *DbSqlite) Database() *sql.DB { func (t *DbSqlite) Database() (*sql.DB, error) {
return t.db if t.db == nil {
return nil, fmt.Errorf("database not initialized")
}
return t.db, nil
} }
+5 -13
View File
@@ -6,8 +6,8 @@ import (
"errors" "errors"
"fmt" "fmt"
"log/slog" "log/slog"
"net"
"net/http" "net/http"
"time"
"github.com/google/jsonschema-go/jsonschema" "github.com/google/jsonschema-go/jsonschema"
"github.com/jwetzell/showbridge-go/internal/common" "github.com/jwetzell/showbridge-go/internal/common"
@@ -99,10 +99,6 @@ func (hs *HTTPServer) ServeHTTP(w http.ResponseWriter, r *http.Request) {
} }
if hs.router != nil { if hs.router != nil {
inputContext := context.WithValue(hs.ctx, httpServerContextKey("responseWriter"), &responseWriter) inputContext := context.WithValue(hs.ctx, httpServerContextKey("responseWriter"), &responseWriter)
senderAddr, err := net.ResolveTCPAddr("tcp", r.RemoteAddr)
if err == nil {
inputContext = context.WithValue(inputContext, common.SenderContextKey, senderAddr)
}
aRouteFound, routingErrors := hs.router.HandleInput(inputContext, hs.Id(), r) aRouteFound, routingErrors := hs.router.HandleInput(inputContext, hs.Id(), r)
if !responseWriter.done { if !responseWriter.done {
if aRouteFound { if aRouteFound {
@@ -160,21 +156,17 @@ func (hs *HTTPServer) ServeHTTP(w http.ResponseWriter, r *http.Request) {
} }
} }
func (hs *HTTPServer) Start(ctx context.Context) error { func (hs *HTTPServer) Start(ctx context.Context, router common.RouteIO) error {
hs.logger.Debug("running") hs.logger.Debug("running")
router, ok := ctx.Value(common.RouterContextKey).(common.RouteIO)
if !ok {
return errors.New("http.server unable to get router from context")
}
hs.router = router hs.router = router
moduleContext, cancel := context.WithCancel(ctx) moduleContext, cancel := context.WithCancel(ctx)
hs.ctx = moduleContext hs.ctx = moduleContext
hs.cancel = cancel hs.cancel = cancel
httpServer := &http.Server{ httpServer := &http.Server{
Addr: fmt.Sprintf(":%d", hs.Port), Addr: fmt.Sprintf(":%d", hs.Port),
Handler: hs, ReadHeaderTimeout: 5 * time.Second,
Handler: hs,
} }
go func() { go func() {
+1 -7
View File
@@ -4,7 +4,6 @@ package module
import ( import (
"context" "context"
"errors"
"fmt" "fmt"
"log/slog" "log/slog"
@@ -60,14 +59,9 @@ func (mi *MIDIInput) Type() string {
return mi.config.Type return mi.config.Type
} }
func (mi *MIDIInput) Start(ctx context.Context) error { func (mi *MIDIInput) Start(ctx context.Context, router common.RouteIO) error {
mi.logger.Debug("running") mi.logger.Debug("running")
defer midi.CloseDriver() defer midi.CloseDriver()
router, ok := ctx.Value(common.RouterContextKey).(common.RouteIO)
if !ok {
return errors.New("midi.input unable to get router from context")
}
mi.router = router mi.router = router
moduleContext, cancel := context.WithCancel(ctx) moduleContext, cancel := context.WithCancel(ctx)
mi.ctx = moduleContext mi.ctx = moduleContext
+1 -6
View File
@@ -61,14 +61,9 @@ func (mo *MIDIOutput) Type() string {
return mo.config.Type return mo.config.Type
} }
func (mo *MIDIOutput) Start(ctx context.Context) error { func (mo *MIDIOutput) Start(ctx context.Context, router common.RouteIO) error {
mo.logger.Debug("running") mo.logger.Debug("running")
defer midi.CloseDriver() defer midi.CloseDriver()
router, ok := ctx.Value(common.RouterContextKey).(common.RouteIO)
if !ok {
return errors.New("midi.output unable to get router from context")
}
mo.router = router mo.router = router
moduleContext, cancel := context.WithCancel(ctx) moduleContext, cancel := context.WithCancel(ctx)
mo.ctx = moduleContext mo.ctx = moduleContext
+1 -6
View File
@@ -80,13 +80,8 @@ func (mc *MQTTClient) Type() string {
return mc.config.Type return mc.config.Type
} }
func (mc *MQTTClient) Start(ctx context.Context) error { func (mc *MQTTClient) Start(ctx context.Context, router common.RouteIO) error {
mc.logger.Debug("running") mc.logger.Debug("running")
router, ok := ctx.Value(common.RouterContextKey).(common.RouteIO)
if !ok {
return errors.New("mqtt.client unable to get router from context")
}
mc.router = router mc.router = router
moduleContext, cancel := context.WithCancel(ctx) moduleContext, cancel := context.WithCancel(ctx)
mc.ctx = moduleContext mc.ctx = moduleContext
+1 -7
View File
@@ -68,14 +68,8 @@ func (nc *NATSClient) Type() string {
return nc.config.Type return nc.config.Type
} }
func (nc *NATSClient) Start(ctx context.Context) error { func (nc *NATSClient) Start(ctx context.Context, router common.RouteIO) error {
nc.logger.Debug("running") nc.logger.Debug("running")
router, ok := ctx.Value(common.RouterContextKey).(common.RouteIO)
if !ok {
return errors.New("nats.client unable to get router from context")
}
nc.router = router nc.router = router
moduleContext, cancel := context.WithCancel(ctx) moduleContext, cancel := context.WithCancel(ctx)
nc.ctx = moduleContext nc.ctx = moduleContext
+1 -7
View File
@@ -86,14 +86,8 @@ func (ns *NATSServer) Type() string {
return ns.config.Type return ns.config.Type
} }
func (ns *NATSServer) Start(ctx context.Context) error { func (ns *NATSServer) Start(ctx context.Context, router common.RouteIO) error {
ns.logger.Debug("running") ns.logger.Debug("running")
router, ok := ctx.Value(common.RouterContextKey).(common.RouteIO)
if !ok {
return errors.New("nats.server unable to get router from context")
}
ns.router = router ns.router = router
moduleContext, cancel := context.WithCancel(ctx) moduleContext, cancel := context.WithCancel(ctx)
ns.ctx = moduleContext ns.ctx = moduleContext
+1 -7
View File
@@ -2,7 +2,6 @@ package module
import ( import (
"context" "context"
"errors"
"log/slog" "log/slog"
"net" "net"
"time" "time"
@@ -40,13 +39,8 @@ func (pc *PSNClient) Type() string {
return pc.config.Type return pc.config.Type
} }
func (pc *PSNClient) Start(ctx context.Context) error { func (pc *PSNClient) Start(ctx context.Context, router common.RouteIO) error {
pc.logger.Debug("running") pc.logger.Debug("running")
router, ok := ctx.Value(common.RouterContextKey).(common.RouteIO)
if !ok {
return errors.New("psn.client unable to get router from context")
}
pc.router = router pc.router = router
moduleContext, cancel := context.WithCancel(ctx) moduleContext, cancel := context.WithCancel(ctx)
pc.ctx = moduleContext pc.ctx = moduleContext
+2 -8
View File
@@ -68,20 +68,14 @@ func (rc *RedisClient) Type() string {
return rc.config.Type return rc.config.Type
} }
func (rc *RedisClient) Printf(ctx context.Context, format string, v ...interface{}) { func (rc *RedisClient) Printf(ctx context.Context, format string, v ...any) {
msg := fmt.Sprintf(format, v...) msg := fmt.Sprintf(format, v...)
rc.logger.Debug(msg) rc.logger.Debug(msg)
} }
func (rc *RedisClient) Start(ctx context.Context) error { func (rc *RedisClient) Start(ctx context.Context, router common.RouteIO) error {
redis.SetLogger(rc) redis.SetLogger(rc)
rc.logger.Debug("running") rc.logger.Debug("running")
router, ok := ctx.Value(common.RouterContextKey).(common.RouteIO)
if !ok {
return errors.New("redis.client unable to get router from context")
}
rc.router = router rc.router = router
moduleContext, cancel := context.WithCancel(ctx) moduleContext, cancel := context.WithCancel(ctx)
rc.ctx = moduleContext rc.ctx = moduleContext
+15 -10
View File
@@ -43,8 +43,13 @@ func init() {
Title: "Baud Rate", Title: "Baud Rate",
Type: "integer", Type: "integer",
}, },
"framing": {
Title: "Framing Method",
Type: "string",
Enum: []any{"LF", "CR", "CRLF", "SLIP", "RAW"},
},
}, },
Required: []string{"port", "baudRate"}, Required: []string{"port", "baudRate", "framing"},
AdditionalProperties: &jsonschema.Schema{Not: &jsonschema.Schema{}}, AdditionalProperties: &jsonschema.Schema{Not: &jsonschema.Schema{}},
}, },
New: func(config config.ModuleConfig) (common.Module, error) { New: func(config config.ModuleConfig) (common.Module, error) {
@@ -91,7 +96,7 @@ func (sc *SerialClient) SetupPort() error {
port, err := serial.Open(sc.Port, sc.Mode) port, err := serial.Open(sc.Port, sc.Mode)
if err != nil { if err != nil {
return fmt.Errorf("serial.client can't open input port: %s", sc.Port) return err
} }
sc.port = port sc.port = port
@@ -99,14 +104,8 @@ func (sc *SerialClient) SetupPort() error {
return nil return nil
} }
func (sc *SerialClient) Start(ctx context.Context) error { func (sc *SerialClient) Start(ctx context.Context, router common.RouteIO) error {
sc.logger.Debug("running") sc.logger.Debug("running")
router, ok := ctx.Value(common.RouterContextKey).(common.RouteIO)
if !ok {
return errors.New("serial.client unable to get router from context")
}
sc.router = router sc.router = router
moduleContext, cancel := context.WithCancel(ctx) moduleContext, cancel := context.WithCancel(ctx)
sc.ctx = moduleContext sc.ctx = moduleContext
@@ -126,9 +125,12 @@ func (sc *SerialClient) Start(ctx context.Context) error {
if err != nil { if err != nil {
if sc.ctx.Err() != nil { if sc.ctx.Err() != nil {
sc.logger.Debug("done") sc.logger.Debug("done")
if sc.port != nil {
sc.port.Close()
}
return nil return nil
} }
sc.logger.Error("port setup error", "error", err.Error()) sc.logger.Error("port setup error", "port", sc.Port, "error", err.Error())
time.Sleep(time.Second * 2) time.Sleep(time.Second * 2)
continue continue
} }
@@ -137,6 +139,9 @@ func (sc *SerialClient) Start(ctx context.Context) error {
select { select {
case <-sc.ctx.Done(): case <-sc.ctx.Done():
sc.logger.Debug("done") sc.logger.Debug("done")
if sc.port != nil {
sc.port.Close()
}
return nil return nil
default: default:
READ: READ:
+1 -6
View File
@@ -131,13 +131,8 @@ func (scs *SIPCallServer) Type() string {
return scs.config.Type return scs.config.Type
} }
func (scs *SIPCallServer) Start(ctx context.Context) error { func (scs *SIPCallServer) Start(ctx context.Context, router common.RouteIO) error {
scs.logger.Debug("running") scs.logger.Debug("running")
router, ok := ctx.Value(common.RouterContextKey).(common.RouteIO)
if !ok {
return errors.New("sip.call.server unable to get router from context")
}
scs.router = router scs.router = router
moduleContext, cancel := context.WithCancel(ctx) moduleContext, cancel := context.WithCancel(ctx)
scs.ctx = moduleContext scs.ctx = moduleContext
+3 -8
View File
@@ -78,8 +78,8 @@ func init() {
"separator": { "separator": {
Title: "DTMF Separator", Title: "DTMF Separator",
Type: "string", Type: "string",
MinLength: jsonschema.Ptr(1), MinLength: new(1),
MaxLength: jsonschema.Ptr(1), MaxLength: new(1),
}, },
}, },
Required: []string{"separator"}, Required: []string{"separator"},
@@ -150,13 +150,8 @@ func (sds *SIPDTMFServer) Type() string {
return sds.config.Type return sds.config.Type
} }
func (sds *SIPDTMFServer) Start(ctx context.Context) error { func (sds *SIPDTMFServer) Start(ctx context.Context, router common.RouteIO) error {
sds.logger.Debug("running") sds.logger.Debug("running")
router, ok := ctx.Value(common.RouterContextKey).(common.RouteIO)
if !ok {
return errors.New("sip.dtmf.server unable to get router from context")
}
sds.router = router sds.router = router
moduleContext, cancel := context.WithCancel(ctx) moduleContext, cancel := context.WithCancel(ctx)
sds.ctx = moduleContext sds.ctx = moduleContext
+1 -6
View File
@@ -91,13 +91,8 @@ func (tc *TCPClient) Type() string {
return tc.config.Type return tc.config.Type
} }
func (tc *TCPClient) Start(ctx context.Context) error { func (tc *TCPClient) Start(ctx context.Context, router common.RouteIO) error {
tc.logger.Debug("running") tc.logger.Debug("running")
router, ok := ctx.Value(common.RouterContextKey).(common.RouteIO)
if !ok {
return errors.New("net.tcp.client unable to get router from context")
}
tc.router = router tc.router = router
moduleContext, cancel := context.WithCancel(ctx) moduleContext, cancel := context.WithCancel(ctx)
tc.ctx = moduleContext tc.ctx = moduleContext
+12 -19
View File
@@ -8,6 +8,7 @@ import (
"log/slog" "log/slog"
"net" "net"
"slices" "slices"
"strings"
"sync" "sync"
"syscall" "syscall"
"time" "time"
@@ -24,7 +25,7 @@ type TCPServer struct {
Framer framer.Framer Framer framer.Framer
ctx context.Context ctx context.Context
router common.RouteIO router common.RouteIO
quit chan interface{} quit chan any
wg sync.WaitGroup wg sync.WaitGroup
connections []*net.TCPConn connections []*net.TCPConn
connectionsMu sync.RWMutex connectionsMu sync.RWMutex
@@ -90,7 +91,7 @@ func init() {
if err != nil { if err != nil {
return nil, err return nil, err
} }
return &TCPServer{Framer: framer, Addr: addr, config: moduleConfig, quit: make(chan interface{}), logger: CreateLogger(moduleConfig)}, nil return &TCPServer{Framer: framer, Addr: addr, config: moduleConfig, quit: make(chan any), logger: CreateLogger(moduleConfig)}, nil
}, },
}) })
} }
@@ -166,10 +167,9 @@ ClientRead:
messages := ts.Framer.Decode(buffer[0:byteCount]) messages := ts.Framer.Decode(buffer[0:byteCount])
for _, message := range messages { for _, message := range messages {
if ts.router != nil { if ts.router != nil {
senderAddr, ok := client.RemoteAddr().(*net.TCPAddr) _, ok := client.RemoteAddr().(*net.TCPAddr)
if ok { if ok {
senderCtx := context.WithValue(ts.ctx, common.SenderContextKey, senderAddr) ts.router.HandleInput(ts.ctx, ts.Id(), message)
ts.router.HandleInput(senderCtx, ts.Id(), message)
} else { } else {
ts.router.HandleInput(ts.ctx, ts.Id(), message) ts.router.HandleInput(ts.ctx, ts.Id(), message)
} }
@@ -183,13 +183,8 @@ ClientRead:
} }
} }
func (ts *TCPServer) Start(ctx context.Context) error { func (ts *TCPServer) Start(ctx context.Context, router common.RouteIO) error {
ts.logger.Debug("running") ts.logger.Debug("running")
router, ok := ctx.Value(common.RouterContextKey).(common.RouteIO)
if !ok {
return errors.New("net.tcp.server unable to get router from context")
}
ts.router = router ts.router = router
moduleContext, cancel := context.WithCancel(ctx) moduleContext, cancel := context.WithCancel(ctx)
ts.ctx = moduleContext ts.ctx = moduleContext
@@ -219,11 +214,9 @@ AcceptLoop:
ts.logger.Debug("problem with listener", "error", err) ts.logger.Debug("problem with listener", "error", err)
} }
} else { } else {
ts.wg.Add(1) ts.wg.Go(func() {
go func() {
ts.handleClient(conn) ts.handleClient(conn)
ts.wg.Done() })
}()
} }
} }
ts.wg.Done() ts.wg.Done()
@@ -238,20 +231,20 @@ func (ts *TCPServer) Output(ctx context.Context, payload any) error {
return errors.New("net.tcp.server is only able to output bytes") return errors.New("net.tcp.server is only able to output bytes")
} }
ts.connectionsMu.Lock() ts.connectionsMu.Lock()
errorString := "" var errorString strings.Builder
for _, connection := range ts.connections { for _, connection := range ts.connections {
_, err := connection.Write(payloadBytes) _, err := connection.Write(payloadBytes)
if err != nil { if err != nil {
errorString += fmt.Sprintf("%s\n", err.Error()) fmt.Fprintf(&errorString, "%s\n", err.Error())
} }
} }
ts.connectionsMu.Unlock() ts.connectionsMu.Unlock()
if errorString == "" { if errorString.String() == "" {
return nil return nil
} }
return fmt.Errorf("net.tcp.server error during output: %s", errorString) return fmt.Errorf("net.tcp.server error during output: %s", errorString.String())
} }
func (ts *TCPServer) Stop() { func (ts *TCPServer) Stop() {
+1 -1
View File
@@ -73,7 +73,7 @@ func TestBadDbSqlite(t *testing.T) {
return return
} }
err = moduleInstance.Start(t.Context()) err = moduleInstance.Start(t.Context(), nil)
if err == nil { if err == nil {
t.Fatalf("db.sqlite expected to fail") t.Fatalf("db.sqlite expected to fail")
+1 -1
View File
@@ -73,7 +73,7 @@ func TestBadHTTPServer(t *testing.T) {
return return
} }
err = moduleInstance.Start(t.Context()) err = moduleInstance.Start(t.Context(), nil)
if err == nil { if err == nil {
t.Fatalf("http.server expected to fail") t.Fatalf("http.server expected to fail")
+1 -1
View File
@@ -73,7 +73,7 @@ func TestBadMIDIInput(t *testing.T) {
return return
} }
err = moduleInstance.Start(t.Context()) err = moduleInstance.Start(t.Context(), nil)
if err == nil { if err == nil {
t.Fatalf("midi.input expected to fail") t.Fatalf("midi.input expected to fail")
+1 -1
View File
@@ -73,7 +73,7 @@ func TestBadMIDIOutput(t *testing.T) {
return return
} }
err = moduleInstance.Start(t.Context()) err = moduleInstance.Start(t.Context(), nil)
if err == nil { if err == nil {
t.Fatalf("midi.output expected to fail") t.Fatalf("midi.output expected to fail")
+1 -1
View File
@@ -116,7 +116,7 @@ func TestBadMQTTClient(t *testing.T) {
return return
} }
err = moduleInstance.Start(t.Context()) err = moduleInstance.Start(t.Context(), nil)
if err == nil { if err == nil {
t.Fatalf("mqtt.client expected to fail") t.Fatalf("mqtt.client expected to fail")
+1 -1
View File
@@ -94,7 +94,7 @@ func TestBadNATSClient(t *testing.T) {
return return
} }
err = moduleInstance.Start(t.Context()) err = moduleInstance.Start(t.Context(), nil)
if err == nil { if err == nil {
t.Fatalf("nats.client expected to fail") t.Fatalf("nats.client expected to fail")
+1 -1
View File
@@ -71,7 +71,7 @@ func TestBadNATSServer(t *testing.T) {
return return
} }
err = moduleInstance.Start(t.Context()) err = moduleInstance.Start(t.Context(), nil)
if err == nil { if err == nil {
t.Fatalf("nats.server expected to fail") t.Fatalf("nats.server expected to fail")
+1 -1
View File
@@ -59,7 +59,7 @@ func TestBadPSNClient(t *testing.T) {
return return
} }
err = moduleInstance.Start(t.Context()) err = moduleInstance.Start(t.Context(), nil)
if err == nil { if err == nil {
t.Fatalf("psn.client expected to fail") t.Fatalf("psn.client expected to fail")
+1 -1
View File
@@ -94,7 +94,7 @@ func TestBadRedisClient(t *testing.T) {
return return
} }
err = moduleInstance.Start(t.Context()) err = moduleInstance.Start(t.Context(), nil)
if err == nil { if err == nil {
t.Fatalf("redis.client expected to fail") t.Fatalf("redis.client expected to fail")
+1 -1
View File
@@ -103,7 +103,7 @@ func TestBadSerialClient(t *testing.T) {
return return
} }
err = moduleInstance.Start(t.Context()) err = moduleInstance.Start(t.Context(), nil)
if err == nil { if err == nil {
t.Fatalf("serial.client expected to fail") t.Fatalf("serial.client expected to fail")
+1 -1
View File
@@ -88,7 +88,7 @@ func TestBadSIPCallServer(t *testing.T) {
return return
} }
err = moduleInstance.Start(t.Context()) err = moduleInstance.Start(t.Context(), nil)
if err == nil { if err == nil {
t.Fatalf("sip.call.server expected to fail") t.Fatalf("sip.call.server expected to fail")
+1 -1
View File
@@ -107,7 +107,7 @@ func TestBadSIPDTMFServer(t *testing.T) {
return return
} }
err = moduleInstance.Start(t.Context()) err = moduleInstance.Start(t.Context(), nil)
if err == nil { if err == nil {
t.Fatalf("sip.dtmf.server expected to fail") t.Fatalf("sip.dtmf.server expected to fail")
+1 -1
View File
@@ -95,7 +95,7 @@ func TestBadTCPClient(t *testing.T) {
return return
} }
err = moduleInstance.Start(t.Context()) err = moduleInstance.Start(t.Context(), nil)
if err == nil { if err == nil {
t.Fatalf("net.tcp.client expected to fail") t.Fatalf("net.tcp.client expected to fail")
+1 -1
View File
@@ -120,7 +120,7 @@ func TestBadTCPServer(t *testing.T) {
return return
} }
err = moduleInstance.Start(t.Context()) err = moduleInstance.Start(t.Context(), nil)
if err == nil { if err == nil {
t.Fatalf("net.tcp.server expected to fail") t.Fatalf("net.tcp.server expected to fail")
+1 -1
View File
@@ -75,7 +75,7 @@ func TestBadTimeInterval(t *testing.T) {
return return
} }
err = moduleInstance.Start(t.Context()) err = moduleInstance.Start(t.Context(), nil)
if err == nil { if err == nil {
t.Fatalf("time.interval expected to fail") t.Fatalf("time.interval expected to fail")
+1 -1
View File
@@ -75,7 +75,7 @@ func TestBadTimeTimer(t *testing.T) {
return return
} }
err = moduleInstance.Start(t.Context()) err = moduleInstance.Start(t.Context(), nil)
if err == nil { if err == nil {
t.Fatalf("time.timer expected to fail") t.Fatalf("time.timer expected to fail")
+1 -1
View File
@@ -95,7 +95,7 @@ func TestBadUDPClient(t *testing.T) {
return return
} }
err = moduleInstance.Start(t.Context()) err = moduleInstance.Start(t.Context(), nil)
if err == nil { if err == nil {
t.Fatalf("net.udp.client expected to fail") t.Fatalf("net.udp.client expected to fail")
+1 -1
View File
@@ -102,7 +102,7 @@ func TestBadUDPMulticast(t *testing.T) {
return return
} }
err = moduleInstance.Start(t.Context()) err = moduleInstance.Start(t.Context(), nil)
if err == nil { if err == nil {
t.Fatalf("net.udp.multicast expected to fail") t.Fatalf("net.udp.multicast expected to fail")
+1 -1
View File
@@ -99,7 +99,7 @@ func TestBadUDPServer(t *testing.T) {
return return
} }
err = moduleInstance.Start(t.Context()) err = moduleInstance.Start(t.Context(), nil)
if err == nil { if err == nil {
t.Fatalf("net.udp.server expected to fail") t.Fatalf("net.udp.server expected to fail")
@@ -0,0 +1,96 @@
package module_test
import (
"testing"
"github.com/jwetzell/showbridge-go/internal/config"
"github.com/jwetzell/showbridge-go/internal/module"
)
func TestWebSocketClientFromRegistry(t *testing.T) {
registration, ok := module.ModuleRegistry["websocket.client"]
if !ok {
t.Fatalf("websocket.client module not registered")
}
moduleInstance, err := registration.New(config.ModuleConfig{
Id: "test",
Type: "websocket.client",
Params: map[string]any{
"url": "ws://localhost",
},
})
if err != nil {
t.Fatalf("failed to create websocket.client module: %s", err)
}
if moduleInstance.Id() != "test" {
t.Fatalf("websocket.client module has wrong id: %s", moduleInstance.Id())
}
if moduleInstance.Type() != "websocket.client" {
t.Fatalf("websocket.client module has wrong type: %s", moduleInstance.Type())
}
}
func TestBadWebSocketClient(t *testing.T) {
tests := []struct {
name string
params map[string]any
errorString string
}{
{
name: "no url param",
params: map[string]any{},
errorString: "websocket.client url error: not found",
},
{
name: "non-string url param",
params: map[string]any{
"url": 123,
},
errorString: "websocket.client url error: not a string",
},
{
name: "invalid url param",
params: map[string]any{
"url": "invalid-url",
},
errorString: "websocket.client url error: scheme must be ws or wss",
},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
registration, ok := module.ModuleRegistry["websocket.client"]
if !ok {
t.Fatalf("websocket.client module not registered")
}
moduleInstance, err := registration.New(config.ModuleConfig{
Id: "test",
Type: "websocket.client",
Params: test.params,
})
if err != nil {
if test.errorString != err.Error() {
t.Fatalf("websocket.client got error '%s', expected '%s'", err.Error(), test.errorString)
}
return
}
err = moduleInstance.Start(t.Context(), nil)
if err == nil {
t.Fatalf("websocket.client expected to fail")
}
if err.Error() != test.errorString {
t.Fatalf("websocket.client got error '%s', expected '%s'", err.Error(), test.errorString)
}
})
}
}
+1 -7
View File
@@ -2,7 +2,6 @@ package module
import ( import (
"context" "context"
"errors"
"fmt" "fmt"
"log/slog" "log/slog"
"time" "time"
@@ -58,13 +57,8 @@ func (i *TimeInterval) Type() string {
return i.config.Type return i.config.Type
} }
func (i *TimeInterval) Start(ctx context.Context) error { func (i *TimeInterval) Start(ctx context.Context, router common.RouteIO) error {
i.logger.Debug("running") i.logger.Debug("running")
router, ok := ctx.Value(common.RouterContextKey).(common.RouteIO)
if !ok {
return errors.New("time.interval unable to get router from context")
}
i.router = router i.router = router
moduleContext, cancel := context.WithCancel(ctx) moduleContext, cancel := context.WithCancel(ctx)
i.ctx = moduleContext i.ctx = moduleContext
+1 -7
View File
@@ -2,7 +2,6 @@ package module
import ( import (
"context" "context"
"errors"
"fmt" "fmt"
"log/slog" "log/slog"
"time" "time"
@@ -59,13 +58,8 @@ func (t *TimeTimer) Type() string {
return t.config.Type return t.config.Type
} }
func (t *TimeTimer) Start(ctx context.Context) error { func (t *TimeTimer) Start(ctx context.Context, router common.RouteIO) error {
t.logger.Debug("running") t.logger.Debug("running")
router, ok := ctx.Value(common.RouterContextKey).(common.RouteIO)
if !ok {
return errors.New("net.tcp.client unable to get router from context")
}
t.router = router t.router = router
moduleContext, cancel := context.WithCancel(ctx) moduleContext, cancel := context.WithCancel(ctx)
t.ctx = moduleContext t.ctx = moduleContext
+1 -6
View File
@@ -79,13 +79,8 @@ func (uc *UDPClient) SetupConn() error {
return err return err
} }
func (uc *UDPClient) Start(ctx context.Context) error { func (uc *UDPClient) Start(ctx context.Context, router common.RouteIO) error {
uc.logger.Debug("running") uc.logger.Debug("running")
router, ok := ctx.Value(common.RouterContextKey).(common.RouteIO)
if !ok {
return errors.New("net.udp.client unable to get router from context")
}
uc.router = router uc.router = router
moduleContext, cancel := context.WithCancel(ctx) moduleContext, cancel := context.WithCancel(ctx)
uc.ctx = moduleContext uc.ctx = moduleContext
+1 -6
View File
@@ -73,13 +73,8 @@ func (um *UDPMulticast) Type() string {
return um.config.Type return um.config.Type
} }
func (um *UDPMulticast) Start(ctx context.Context) error { func (um *UDPMulticast) Start(ctx context.Context, router common.RouteIO) error {
um.logger.Debug("running") um.logger.Debug("running")
router, ok := ctx.Value(common.RouterContextKey).(common.RouteIO)
if !ok {
return errors.New("net.udp.multicast unable to get router from context")
}
um.router = router um.router = router
moduleContext, cancel := context.WithCancel(ctx) moduleContext, cancel := context.WithCancel(ctx)
um.ctx = moduleContext um.ctx = moduleContext
+3 -9
View File
@@ -95,13 +95,8 @@ func (us *UDPServer) Type() string {
return us.config.Type return us.config.Type
} }
func (us *UDPServer) Start(ctx context.Context) error { func (us *UDPServer) Start(ctx context.Context, router common.RouteIO) error {
us.logger.Debug("running") us.logger.Debug("running")
router, ok := ctx.Value(common.RouterContextKey).(common.RouteIO)
if !ok {
return errors.New("net.udp.server unable to get router from context")
}
us.router = router us.router = router
moduleContext, cancel := context.WithCancel(ctx) moduleContext, cancel := context.WithCancel(ctx)
us.ctx = moduleContext us.ctx = moduleContext
@@ -124,7 +119,7 @@ func (us *UDPServer) Start(ctx context.Context) error {
default: default:
listener.SetDeadline(time.Now().Add(time.Millisecond * 200)) listener.SetDeadline(time.Now().Add(time.Millisecond * 200))
numBytes, senderAddr, err := listener.ReadFromUDP(buffer) numBytes, _, err := listener.ReadFromUDP(buffer)
if err != nil { if err != nil {
//NOTE(jwetzell) we hit deadline //NOTE(jwetzell) we hit deadline
if opErr, ok := err.(*net.OpError); ok && opErr.Timeout() { if opErr, ok := err.(*net.OpError); ok && opErr.Timeout() {
@@ -134,8 +129,7 @@ func (us *UDPServer) Start(ctx context.Context) error {
} }
message := buffer[:numBytes] message := buffer[:numBytes]
if us.router != nil { if us.router != nil {
senderCtx := context.WithValue(us.ctx, common.SenderContextKey, senderAddr) us.router.HandleInput(us.ctx, us.Id(), message)
us.router.HandleInput(senderCtx, us.Id(), message)
} else { } else {
us.logger.Error("input received but no router is configured") us.logger.Error("input received but no router is configured")
} }
+173
View File
@@ -0,0 +1,173 @@
package module
import (
"context"
"errors"
"fmt"
"log/slog"
"net/url"
"time"
"github.com/google/jsonschema-go/jsonschema"
"github.com/gorilla/websocket"
"github.com/jwetzell/showbridge-go/internal/common"
"github.com/jwetzell/showbridge-go/internal/config"
)
type WebSocketClient struct {
config config.ModuleConfig
URL url.URL
ctx context.Context
conn *websocket.Conn
router common.RouteIO
logger *slog.Logger
cancel context.CancelFunc
}
func init() {
RegisterModule(ModuleRegistration{
Type: "websocket.client",
Title: "WebSocket Client",
ParamsSchema: &jsonschema.Schema{
Type: "object",
Properties: map[string]*jsonschema.Schema{
"url": {
Title: "URL",
Type: "string",
},
},
Required: []string{"url"},
AdditionalProperties: &jsonschema.Schema{Not: &jsonschema.Schema{}},
},
New: func(config config.ModuleConfig) (common.Module, error) {
params := config.Params
urlString, err := params.GetString("url")
if err != nil {
return nil, fmt.Errorf("websocket.client url error: %w", err)
}
parsedURL, err := url.Parse(urlString)
if err != nil {
return nil, fmt.Errorf("websocket.client url error: %w", err)
}
if parsedURL.Scheme != "ws" && parsedURL.Scheme != "wss" {
return nil, fmt.Errorf("websocket.client url error: scheme must be ws or wss")
}
return &WebSocketClient{URL: *parsedURL, config: config, logger: CreateLogger(config)}, nil
},
})
}
func (wc *WebSocketClient) Id() string {
return wc.config.Id
}
func (wc *WebSocketClient) Type() string {
return wc.config.Type
}
func (wc *WebSocketClient) SetupConn() error {
conn, _, err := websocket.DefaultDialer.Dial(wc.URL.String(), nil)
wc.conn = conn
return err
}
func (wc *WebSocketClient) Start(ctx context.Context, router common.RouteIO) error {
wc.logger.Debug("running")
wc.router = router
moduleContext, cancel := context.WithCancel(ctx)
wc.ctx = moduleContext
wc.cancel = cancel
for wc.ctx.Err() == nil {
err := wc.SetupConn()
if err != nil {
wc.logger.Error("connection error", "error", err)
} else {
// NOTE(jwetzell): enter read loop until an error occurs
wc.readLoop()
}
// NOTE(jwetzell): if connection is lost or read error wait before trying again
time.Sleep(2 * time.Second)
}
<-wc.ctx.Done()
wc.logger.Debug("done")
if wc.conn != nil {
wc.conn.Close()
}
return nil
}
func (wc *WebSocketClient) readLoop() {
for wc.ctx.Err() == nil {
if wc.conn == nil {
wc.logger.Error("websocket connection is not established")
return
}
messageType, message, err := wc.conn.ReadMessage()
if err != nil {
wc.logger.Error("read error", "error", err)
return
}
if wc.router != nil {
switch messageType {
case websocket.TextMessage:
wc.router.HandleInput(wc.ctx, wc.Id(), string(message))
case websocket.BinaryMessage:
wc.router.HandleInput(wc.ctx, wc.Id(), message)
default:
wc.logger.Warn("unsupported message type received", "messageType", messageType)
}
} else {
wc.logger.Error("input received but no router is configured")
continue
}
}
}
func (wc *WebSocketClient) outputBytes(ctx context.Context, payload []byte) error {
if wc.conn == nil {
return errors.New("websocket.client client is not setup")
}
err := wc.conn.WriteMessage(websocket.BinaryMessage, payload)
if err != nil {
return err
}
return nil
}
func (wc *WebSocketClient) outputString(ctx context.Context, payload string) error {
if wc.conn == nil {
return errors.New("websocket.client client is not setup")
}
err := wc.conn.WriteMessage(websocket.TextMessage, []byte(payload))
if err != nil {
return err
}
return nil
}
func (wc *WebSocketClient) Output(ctx context.Context, payload any) error {
payloadBytes, ok := common.GetAnyAsByteSlice(payload)
if ok {
return wc.outputBytes(ctx, payloadBytes)
} else {
payloadString, ok := common.GetAnyAs[string](payload)
if ok {
return wc.outputString(ctx, payloadString)
} else {
return errors.New("websocket.client payload must be string or []byte")
}
}
}
func (wc *WebSocketClient) Stop() {
wc.cancel()
}
+27 -17
View File
@@ -17,34 +17,43 @@ type DbQuery struct {
ModuleId string ModuleId string
Query *template.Template Query *template.Template
logger *slog.Logger logger *slog.Logger
module common.DatabaseModule
} }
func (dq *DbQuery) Process(ctx context.Context, wrappedPayload common.WrappedPayload) (common.WrappedPayload, error) { func (dq *DbQuery) Process(ctx context.Context, wrappedPayload common.WrappedPayload) (common.WrappedPayload, error) {
if wrappedPayload.Modules == nil { if dq.module == nil {
wrappedPayload.End = true if wrappedPayload.Modules == nil {
return wrappedPayload, errors.New("db.query wrapped payload has no modules") wrappedPayload.End = true
return wrappedPayload, errors.New("db.query wrapped payload has no modules")
}
module, ok := wrappedPayload.Modules[dq.ModuleId]
if !ok {
wrappedPayload.End = true
return wrappedPayload, fmt.Errorf("db.query unable to find module with id: %s", dq.ModuleId)
}
dbModule, ok := module.(common.DatabaseModule)
if !ok {
wrappedPayload.End = true
return wrappedPayload, fmt.Errorf("db.query module with id %s is not a DatabaseModule", dq.ModuleId)
}
dq.module = dbModule
} }
module, ok := wrappedPayload.Modules[dq.ModuleId] db, err := dq.module.Database()
if !ok { if err != nil {
wrappedPayload.End = true wrappedPayload.End = true
return wrappedPayload, fmt.Errorf("db.query unable to find module with id: %s", dq.ModuleId) return wrappedPayload, fmt.Errorf("db.query error getting database from module: %w", err)
} }
dbModule, ok := module.(common.DatabaseModule)
if !ok {
wrappedPayload.End = true
return wrappedPayload, fmt.Errorf("db.query module with id %s is not a DatabaseModule", dq.ModuleId)
}
db := dbModule.Database()
if db == nil { if db == nil {
wrappedPayload.End = true wrappedPayload.End = true
return wrappedPayload, fmt.Errorf("db.query module with id %s returned nil database", dq.ModuleId) return wrappedPayload, fmt.Errorf("db.query module with id %s returned nil database", dq.ModuleId)
} }
var queryBuffer bytes.Buffer var queryBuffer bytes.Buffer
err := dq.Query.Execute(&queryBuffer, wrappedPayload) err = dq.Query.Execute(&queryBuffer, wrappedPayload)
if err != nil { if err != nil {
wrappedPayload.End = true wrappedPayload.End = true
@@ -65,13 +74,14 @@ func (dq *DbQuery) Process(ctx context.Context, wrappedPayload common.WrappedPay
return wrappedPayload, fmt.Errorf("db.query error getting columns: %w", err) return wrappedPayload, fmt.Errorf("db.query error getting columns: %w", err)
} }
// TODO(jwetzell): optimize this
results := make([]map[string]any, 0) results := make([]map[string]any, 0)
for rows.Next() { for rows.Next() {
columnValues := make([]interface{}, len(columns)) columnValues := make([]any, len(columns))
for i := range columnValues { for i := range columnValues {
columnValues[i] = new(interface{}) columnValues[i] = new(any)
} }
if err := rows.Scan(columnValues...); err != nil { if err := rows.Scan(columnValues...); err != nil {
@@ -81,7 +91,7 @@ func (dq *DbQuery) Process(ctx context.Context, wrappedPayload common.WrappedPay
rowMap := make(map[string]any) rowMap := make(map[string]any)
for i, colName := range columns { for i, colName := range columns {
value := *columnValues[i].(*interface{}) value := *columnValues[i].(*any)
rowMap[colName] = value rowMap[colName] = value
} }
results = append(results, rowMap) results = append(results, rowMap)
+20 -16
View File
@@ -16,27 +16,31 @@ type KVGet struct {
ModuleId string ModuleId string
Key string Key string
logger *slog.Logger logger *slog.Logger
module common.KeyValueModule
} }
func (kvg *KVGet) Process(ctx context.Context, wrappedPayload common.WrappedPayload) (common.WrappedPayload, error) { func (kvg *KVGet) Process(ctx context.Context, wrappedPayload common.WrappedPayload) (common.WrappedPayload, error) {
if wrappedPayload.Modules == nil { if kvg.module == nil {
wrappedPayload.End = true if wrappedPayload.Modules == nil {
return wrappedPayload, errors.New("kv.get wrapped payload has no modules") wrappedPayload.End = true
return wrappedPayload, errors.New("kv.get wrapped payload has no modules")
}
module, ok := wrappedPayload.Modules[kvg.ModuleId]
if !ok {
wrappedPayload.End = true
return wrappedPayload, fmt.Errorf("kv.get unable to find module with id: %s", kvg.ModuleId)
}
kvModule, ok := module.(common.KeyValueModule)
if !ok {
wrappedPayload.End = true
return wrappedPayload, fmt.Errorf("kv.get module with id %s is not a KeyValueModule", kvg.ModuleId)
}
kvg.module = kvModule
} }
module, ok := wrappedPayload.Modules[kvg.ModuleId] value, err := kvg.module.Get(kvg.Key)
if !ok {
wrappedPayload.End = true
return wrappedPayload, fmt.Errorf("kv.get unable to find module with id: %s", kvg.ModuleId)
}
kvModule, ok := module.(common.KeyValueModule)
if !ok {
wrappedPayload.End = true
return wrappedPayload, fmt.Errorf("kv.get module with id %s is not a KeyValueModule", kvg.ModuleId)
}
value, err := kvModule.Get(kvg.Key)
if err != nil { if err != nil {
wrappedPayload.End = true wrappedPayload.End = true
return wrappedPayload, fmt.Errorf("kv.get error getting key: %w", err) return wrappedPayload, fmt.Errorf("kv.get error getting key: %w", err)
+18 -15
View File
@@ -19,25 +19,28 @@ type KVSet struct {
Key string Key string
Value *template.Template Value *template.Template
logger *slog.Logger logger *slog.Logger
module common.KeyValueModule
} }
func (kvs *KVSet) Process(ctx context.Context, wrappedPayload common.WrappedPayload) (common.WrappedPayload, error) { func (kvs *KVSet) Process(ctx context.Context, wrappedPayload common.WrappedPayload) (common.WrappedPayload, error) {
if kvs.module == nil {
if wrappedPayload.Modules == nil {
wrappedPayload.End = true
return wrappedPayload, errors.New("kv.set wrapped payload has no modules")
}
if wrappedPayload.Modules == nil { module, ok := wrappedPayload.Modules[kvs.ModuleId]
wrappedPayload.End = true if !ok {
return wrappedPayload, errors.New("kv.set wrapped payload has no modules") wrappedPayload.End = true
} return wrappedPayload, fmt.Errorf("kv.set unable to find module with id: %s", kvs.ModuleId)
}
module, ok := wrappedPayload.Modules[kvs.ModuleId] kvModule, ok := module.(common.KeyValueModule)
if !ok { if !ok {
wrappedPayload.End = true wrappedPayload.End = true
return wrappedPayload, fmt.Errorf("kv.set unable to find module with id: %s", kvs.ModuleId) return wrappedPayload, fmt.Errorf("kv.set module with id %s is not a KeyValueModule", kvs.ModuleId)
} }
kvs.module = kvModule
kvModule, ok := module.(common.KeyValueModule)
if !ok {
wrappedPayload.End = true
return wrappedPayload, fmt.Errorf("kv.set module with id %s is not a KeyValueModule", kvs.ModuleId)
} }
var valueBuffer bytes.Buffer var valueBuffer bytes.Buffer
@@ -48,7 +51,7 @@ func (kvs *KVSet) Process(ctx context.Context, wrappedPayload common.WrappedPayl
return wrappedPayload, err return wrappedPayload, err
} }
err = kvModule.Set(kvs.Key, valueBuffer.String()) err = kvs.module.Set(kvs.Key, valueBuffer.String())
if err != nil { if err != nil {
wrappedPayload.End = true wrappedPayload.End = true
return wrappedPayload, fmt.Errorf("kv.set error setting key: %w", err) return wrappedPayload, fmt.Errorf("kv.set error setting key: %w", err)
@@ -35,6 +35,11 @@ func (mccc *MIDIControlChangeCreate) Process(ctx context.Context, wrappedPayload
channelValue, err := strconv.ParseUint(channelBuffer.String(), 10, 8) channelValue, err := strconv.ParseUint(channelBuffer.String(), 10, 8)
if err != nil {
wrappedPayload.End = true
return wrappedPayload, err
}
var controlBuffer bytes.Buffer var controlBuffer bytes.Buffer
err = mccc.Control.Execute(&controlBuffer, templateData) err = mccc.Control.Execute(&controlBuffer, templateData)
@@ -45,6 +50,11 @@ func (mccc *MIDIControlChangeCreate) Process(ctx context.Context, wrappedPayload
controlValue, err := strconv.ParseUint(controlBuffer.String(), 10, 8) controlValue, err := strconv.ParseUint(controlBuffer.String(), 10, 8)
if err != nil {
wrappedPayload.End = true
return wrappedPayload, err
}
var valueBuffer bytes.Buffer var valueBuffer bytes.Buffer
err = mccc.Value.Execute(&valueBuffer, templateData) err = mccc.Value.Execute(&valueBuffer, templateData)
@@ -55,6 +65,11 @@ func (mccc *MIDIControlChangeCreate) Process(ctx context.Context, wrappedPayload
valueValue, err := strconv.ParseUint(valueBuffer.String(), 10, 8) valueValue, err := strconv.ParseUint(valueBuffer.String(), 10, 8)
if err != nil {
wrappedPayload.End = true
return wrappedPayload, err
}
payloadMessage := midi.ControlChange(uint8(channelValue), uint8(controlValue), uint8(valueValue)) payloadMessage := midi.ControlChange(uint8(channelValue), uint8(controlValue), uint8(valueValue))
wrappedPayload.Payload = payloadMessage wrappedPayload.Payload = payloadMessage
return wrappedPayload, nil return wrappedPayload, nil
@@ -35,6 +35,11 @@ func (mnoc *MIDINoteOffCreate) Process(ctx context.Context, wrappedPayload commo
channelValue, err := strconv.ParseUint(channelBuffer.String(), 10, 8) channelValue, err := strconv.ParseUint(channelBuffer.String(), 10, 8)
if err != nil {
wrappedPayload.End = true
return wrappedPayload, err
}
var noteBuffer bytes.Buffer var noteBuffer bytes.Buffer
err = mnoc.Note.Execute(&noteBuffer, templateData) err = mnoc.Note.Execute(&noteBuffer, templateData)
@@ -45,6 +50,11 @@ func (mnoc *MIDINoteOffCreate) Process(ctx context.Context, wrappedPayload commo
noteValue, err := strconv.ParseUint(noteBuffer.String(), 10, 8) noteValue, err := strconv.ParseUint(noteBuffer.String(), 10, 8)
if err != nil {
wrappedPayload.End = true
return wrappedPayload, err
}
var velocityBuffer bytes.Buffer var velocityBuffer bytes.Buffer
err = mnoc.Velocity.Execute(&velocityBuffer, templateData) err = mnoc.Velocity.Execute(&velocityBuffer, templateData)
@@ -54,6 +64,12 @@ func (mnoc *MIDINoteOffCreate) Process(ctx context.Context, wrappedPayload commo
} }
velocityValue, err := strconv.ParseUint(velocityBuffer.String(), 10, 8) velocityValue, err := strconv.ParseUint(velocityBuffer.String(), 10, 8)
if err != nil {
wrappedPayload.End = true
return wrappedPayload, err
}
payloadMessage := midi.NoteOffVelocity(uint8(channelValue), uint8(noteValue), uint8(velocityValue)) payloadMessage := midi.NoteOffVelocity(uint8(channelValue), uint8(noteValue), uint8(velocityValue))
wrappedPayload.Payload = payloadMessage wrappedPayload.Payload = payloadMessage
return wrappedPayload, nil return wrappedPayload, nil
+15
View File
@@ -35,6 +35,11 @@ func (mnoc *MIDINoteOnCreate) Process(ctx context.Context, wrappedPayload common
channelValue, err := strconv.ParseUint(channelBuffer.String(), 10, 8) channelValue, err := strconv.ParseUint(channelBuffer.String(), 10, 8)
if err != nil {
wrappedPayload.End = true
return wrappedPayload, err
}
var noteBuffer bytes.Buffer var noteBuffer bytes.Buffer
err = mnoc.Note.Execute(&noteBuffer, templateData) err = mnoc.Note.Execute(&noteBuffer, templateData)
@@ -45,6 +50,11 @@ func (mnoc *MIDINoteOnCreate) Process(ctx context.Context, wrappedPayload common
noteValue, err := strconv.ParseUint(noteBuffer.String(), 10, 8) noteValue, err := strconv.ParseUint(noteBuffer.String(), 10, 8)
if err != nil {
wrappedPayload.End = true
return wrappedPayload, err
}
var velocityBuffer bytes.Buffer var velocityBuffer bytes.Buffer
err = mnoc.Velocity.Execute(&velocityBuffer, templateData) err = mnoc.Velocity.Execute(&velocityBuffer, templateData)
@@ -54,6 +64,11 @@ func (mnoc *MIDINoteOnCreate) Process(ctx context.Context, wrappedPayload common
} }
velocityValue, err := strconv.ParseUint(velocityBuffer.String(), 10, 8) velocityValue, err := strconv.ParseUint(velocityBuffer.String(), 10, 8)
if err != nil {
wrappedPayload.End = true
return wrappedPayload, err
}
payloadMessage := midi.NoteOn(uint8(channelValue), uint8(noteValue), uint8(velocityValue)) payloadMessage := midi.NoteOn(uint8(channelValue), uint8(noteValue), uint8(velocityValue))
wrappedPayload.Payload = payloadMessage wrappedPayload.Payload = payloadMessage
return wrappedPayload, nil return wrappedPayload, nil
@@ -34,6 +34,11 @@ func (mpcc *MIDIProgramChangeCreate) Process(ctx context.Context, wrappedPayload
channelValue, err := strconv.ParseUint(channelBuffer.String(), 10, 8) channelValue, err := strconv.ParseUint(channelBuffer.String(), 10, 8)
if err != nil {
wrappedPayload.End = true
return wrappedPayload, err
}
var programBuffer bytes.Buffer var programBuffer bytes.Buffer
err = mpcc.Program.Execute(&programBuffer, templateData) err = mpcc.Program.Execute(&programBuffer, templateData)
@@ -44,6 +49,11 @@ func (mpcc *MIDIProgramChangeCreate) Process(ctx context.Context, wrappedPayload
programValue, err := strconv.ParseUint(programBuffer.String(), 10, 8) programValue, err := strconv.ParseUint(programBuffer.String(), 10, 8)
if err != nil {
wrappedPayload.End = true
return wrappedPayload, err
}
payloadMessage := midi.ProgramChange(uint8(channelValue), uint8(programValue)) payloadMessage := midi.ProgramChange(uint8(channelValue), uint8(programValue))
wrappedPayload.Payload = payloadMessage wrappedPayload.Payload = payloadMessage
return wrappedPayload, nil return wrappedPayload, nil
+2 -4
View File
@@ -20,14 +20,12 @@ type RouterInput struct {
func (ro *RouterInput) Process(ctx context.Context, wrappedPayload common.WrappedPayload) (common.WrappedPayload, error) { func (ro *RouterInput) Process(ctx context.Context, wrappedPayload common.WrappedPayload) (common.WrappedPayload, error) {
payload := wrappedPayload.Payload payload := wrappedPayload.Payload
router, ok := ctx.Value(common.RouterContextKey).(common.RouteIO) if wrappedPayload.Router == nil {
if !ok {
wrappedPayload.End = true wrappedPayload.End = true
return wrappedPayload, errors.New("router.input no router found") return wrappedPayload, errors.New("router.input no router found")
} }
_, err := router.HandleInput(ctx, ro.SourceId, payload) _, err := wrappedPayload.Router.HandleInput(ctx, ro.SourceId, payload)
if err != nil { if err != nil {
wrappedPayload.End = true wrappedPayload.End = true
+2 -3
View File
@@ -19,13 +19,12 @@ type RouterOutput struct {
func (ro *RouterOutput) Process(ctx context.Context, wrappedPayload common.WrappedPayload) (common.WrappedPayload, error) { func (ro *RouterOutput) Process(ctx context.Context, wrappedPayload common.WrappedPayload) (common.WrappedPayload, error) {
router, ok := ctx.Value(common.RouterContextKey).(common.RouteIO) if wrappedPayload.Router == nil {
if !ok {
wrappedPayload.End = true wrappedPayload.End = true
return wrappedPayload, errors.New("router.output no router found") return wrappedPayload, errors.New("router.output no router found")
} }
err := router.HandleOutput(ctx, ro.ModuleId, wrappedPayload.Payload) err := wrappedPayload.Router.HandleOutput(ctx, ro.ModuleId, wrappedPayload.Payload)
if err != nil { if err != nil {
wrappedPayload.End = true wrappedPayload.End = true
+8 -6
View File
@@ -32,11 +32,13 @@ func (sj *ScriptJS) Process(ctx context.Context, wrappedPayload common.WrappedPa
} }
} }
sj.vm.SetProperty(sj.vm.GlobalObject(), sj.payloadAtom, wrappedPayload.Payload) err := sj.vm.SetProperty(sj.vm.GlobalObject(), sj.payloadAtom, wrappedPayload.Payload)
if err != nil {
wrappedPayload.End = true
return wrappedPayload, err
}
sj.vm.SetProperty(sj.vm.GlobalObject(), sj.senderAtom, wrappedPayload.Sender) _, err = sj.vm.Eval(sj.Program, quickjs.EvalGlobal)
_, err := sj.vm.Eval(sj.Program, quickjs.EvalGlobal)
if err != nil { if err != nil {
wrappedPayload.End = true wrappedPayload.End = true
@@ -63,12 +65,12 @@ func (sj *ScriptJS) Process(ctx context.Context, wrappedPayload common.WrappedPa
outputObject, ok := output.(*quickjs.Object) outputObject, ok := output.(*quickjs.Object)
if ok { if ok {
var outputSlice []interface{} var outputSlice []any
err = outputObject.Into(&outputSlice) err = outputObject.Into(&outputSlice)
if err != nil { if err != nil {
var outputMap map[string]interface{} var outputMap map[string]any
err = outputObject.Into(&outputMap) err = outputObject.Into(&outputMap)
if err != nil { if err != nil {
wrappedPayload.End = true wrappedPayload.End = true
+9 -10
View File
@@ -14,7 +14,7 @@ import (
type ScriptWASM struct { type ScriptWASM struct {
config config.ProcessorConfig config config.ProcessorConfig
Program *extism.CompiledPlugin Program *extism.Plugin
Function string Function string
} }
@@ -28,14 +28,7 @@ func (sw *ScriptWASM) Process(ctx context.Context, wrappedPayload common.Wrapped
return wrappedPayload, fmt.Errorf("script.wasm can only process a byte array") return wrappedPayload, fmt.Errorf("script.wasm can only process a byte array")
} }
program, err := sw.Program.Instance(ctx, extism.PluginInstanceConfig{}) _, output, err := sw.Program.Call(sw.Function, payloadBytes)
if err != nil {
wrappedPayload.End = true
return wrappedPayload, err
}
_, output, err := program.Call(sw.Function, payloadBytes)
if err != nil { if err != nil {
wrappedPayload.End = true wrappedPayload.End = true
@@ -117,7 +110,13 @@ func init() {
return nil, err return nil, err
} }
return &ScriptWASM{config: processorConfig, Program: program, Function: functionString}, nil programInstance, err := program.Instance(context.Background(), extism.PluginInstanceConfig{})
if err != nil {
return nil, err
}
return &ScriptWASM{config: processorConfig, Program: programInstance, Function: functionString}, nil
}, },
}) })
} }
@@ -41,7 +41,7 @@ func TestGoodArtnetPacketDecode(t *testing.T) {
name: "number", name: "number",
payload: []byte{65, 114, 116, 45, 78, 101, 116, 0, 0, 80, 0, 14, 237, 0, 1, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, payload: []byte{65, 114, 116, 45, 78, 101, 116, 0, 0, 80, 0, 14, 237, 0, 1, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
expected: &artnet.ArtDmx{ expected: &artnet.ArtDmx{
ID: []byte{'A', 'r', 't', '-', 'N', 'e', 't', 0x00}, ID: [8]byte{'A', 'r', 't', '-', 'N', 'e', 't', 0x00},
OpCode: artnet.OpDmx, OpCode: artnet.OpDmx,
ProtVerHi: 0, ProtVerHi: 0,
ProtVerLo: 14, ProtVerLo: 14,
@@ -49,7 +49,6 @@ func TestGoodArtnetPacketDecode(t *testing.T) {
Physical: 0, Physical: 0,
SubUni: 1, SubUni: 1,
Net: 0, Net: 0,
Length: 512,
Data: make([]uint8, 512), Data: make([]uint8, 512),
}, },
}, },
@@ -58,7 +57,7 @@ func TestGoodArtnetPacketDecode(t *testing.T) {
for _, test := range tests { for _, test := range tests {
t.Run(test.name, func(t *testing.T) { t.Run(test.name, func(t *testing.T) {
got, err := packetDecoder.Process(t.Context(), common.GetWrappedPayload(t.Context(), test.payload)) got, err := packetDecoder.Process(t.Context(), common.WrappedPayload{Payload: test.payload})
if err != nil { if err != nil {
t.Fatalf("artnet.packet.decode processing failed: %s", err) t.Fatalf("artnet.packet.decode processing failed: %s", err)
@@ -94,7 +93,7 @@ func TestBadArtnetPacketDecode(t *testing.T) {
for _, test := range tests { for _, test := range tests {
t.Run(test.name, func(t *testing.T) { t.Run(test.name, func(t *testing.T) {
got, err := packetDecoder.Process(t.Context(), common.GetWrappedPayload(t.Context(), test.payload)) got, err := packetDecoder.Process(t.Context(), common.WrappedPayload{Payload: test.payload})
if err == nil { if err == nil {
t.Fatalf("artnet.packet.decode expected to fail but succeeded, got: %v", got) t.Fatalf("artnet.packet.decode expected to fail but succeeded, got: %v", got)
@@ -106,3 +105,15 @@ func TestBadArtnetPacketDecode(t *testing.T) {
}) })
} }
} }
func BenchmarkArtnetPacketDecode(b *testing.B) {
processorInstance := processor.ArtNetPacketDecode{}
payload := []byte{65, 114, 116, 45, 78, 101, 116, 0, 0, 80, 0, 14, 237, 0, 1, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
for b.Loop() {
_, err := processorInstance.Process(b.Context(), common.WrappedPayload{Payload: payload})
if err != nil {
b.Fatalf("artnet.packet.decode processing failed: %s", err)
}
}
}
@@ -41,7 +41,7 @@ func TestGoodArtnetPacketEncode(t *testing.T) {
name: "number", name: "number",
expected: []byte{65, 114, 116, 45, 78, 101, 116, 0, 0, 80, 0, 14, 237, 0, 1, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, expected: []byte{65, 114, 116, 45, 78, 101, 116, 0, 0, 80, 0, 14, 237, 0, 1, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
payload: &artnet.ArtDmx{ payload: &artnet.ArtDmx{
ID: []byte{'A', 'r', 't', '-', 'N', 'e', 't', 0x00}, ID: [8]byte{'A', 'r', 't', '-', 'N', 'e', 't', 0x00},
OpCode: artnet.OpDmx, OpCode: artnet.OpDmx,
ProtVerHi: 0, ProtVerHi: 0,
ProtVerLo: 14, ProtVerLo: 14,
@@ -49,7 +49,6 @@ func TestGoodArtnetPacketEncode(t *testing.T) {
Physical: 0, Physical: 0,
SubUni: 1, SubUni: 1,
Net: 0, Net: 0,
Length: 512,
Data: make([]uint8, 512), Data: make([]uint8, 512),
}, },
}, },
@@ -58,7 +57,7 @@ func TestGoodArtnetPacketEncode(t *testing.T) {
for _, test := range tests { for _, test := range tests {
t.Run(test.name, func(t *testing.T) { t.Run(test.name, func(t *testing.T) {
got, err := packetEncoder.Process(t.Context(), common.GetWrappedPayload(t.Context(), test.payload)) got, err := packetEncoder.Process(t.Context(), common.WrappedPayload{Payload: test.payload})
if err != nil { if err != nil {
t.Fatalf("artnet.packet.encode processing failed: %s", err) t.Fatalf("artnet.packet.encode processing failed: %s", err)
@@ -89,7 +88,7 @@ func TestBadArtnetPacketEncode(t *testing.T) {
for _, test := range tests { for _, test := range tests {
t.Run(test.name, func(t *testing.T) { t.Run(test.name, func(t *testing.T) {
got, err := packetEncoder.Process(t.Context(), common.GetWrappedPayload(t.Context(), test.payload)) got, err := packetEncoder.Process(t.Context(), common.WrappedPayload{Payload: test.payload})
if err == nil { if err == nil {
t.Fatalf("artnet.packet.encode expected to fail but succeeded, got: %v", got) t.Fatalf("artnet.packet.encode expected to fail but succeeded, got: %v", got)
@@ -101,3 +100,25 @@ func TestBadArtnetPacketEncode(t *testing.T) {
}) })
} }
} }
func BenchmarkArtnetPacketEncode(b *testing.B) {
processorInstance := processor.ArtNetPacketEncode{}
payload := &artnet.ArtDmx{
ID: [8]byte{'A', 'r', 't', '-', 'N', 'e', 't', 0x00},
OpCode: artnet.OpDmx,
ProtVerHi: 0,
ProtVerLo: 14,
Sequence: 237,
Physical: 0,
SubUni: 1,
Net: 0,
Data: make([]uint8, 512),
}
for b.Loop() {
_, err := processorInstance.Process(b.Context(), common.WrappedPayload{Payload: payload})
if err != nil {
b.Fatalf("artnet.packet.encode processing failed: %s", err)
}
}
}
+70 -39
View File
@@ -1,7 +1,6 @@
package processor_test package processor_test
import ( import (
"context"
"reflect" "reflect"
"testing" "testing"
@@ -22,7 +21,7 @@ func TestDbQueryFromRegistry(t *testing.T) {
Type: "db.query", Type: "db.query",
Params: map[string]any{ Params: map[string]any{
"module": "test", "module": "test",
"query": "SELECT sqlite_version();", "query": "SELECT 1;",
}, },
}) })
if err != nil { if err != nil {
@@ -34,14 +33,14 @@ func TestDbQueryFromRegistry(t *testing.T) {
} }
payload := "hello" payload := "hello"
expected := map[string]any{"sqlite_version()": "3.53.0"} expected := map[string]any{"1": int64(1)}
got, err := processorInstance.Process(t.Context(), common.GetWrappedPayload(test.GetContextWithModules( got, err := processorInstance.Process(t.Context(), common.WrappedPayload{
t.Context(), Payload: payload,
map[string]common.Module{ Modules: map[string]common.Module{
"test": test.NewTestDBModule("test"), "test": test.NewTestDBModule("test"),
}, },
), payload)) })
if err != nil { if err != nil {
t.Fatalf("db.query processing failed: %s", err) t.Fatalf("db.query processing failed: %s", err)
} }
@@ -115,12 +114,12 @@ func TestGoodDbQuery(t *testing.T) {
t.Fatalf("db.query failed to create processor: %s", err) t.Fatalf("db.query failed to create processor: %s", err)
} }
got, err := processorInstance.Process(t.Context(), common.GetWrappedPayload(test.GetContextWithModules( got, err := processorInstance.Process(t.Context(), common.WrappedPayload{
t.Context(), Modules: map[string]common.Module{
map[string]common.Module{
"test": test.NewTestDBModule("test"), "test": test.NewTestDBModule("test"),
}, },
), testCase.payload)) Payload: testCase.payload,
})
if err != nil { if err != nil {
t.Fatalf("db.query processing failed: %s", err) t.Fatalf("db.query processing failed: %s", err)
@@ -135,11 +134,11 @@ func TestGoodDbQuery(t *testing.T) {
func TestBadDbQuery(t *testing.T) { func TestBadDbQuery(t *testing.T) {
tests := []struct { tests := []struct {
name string name string
params map[string]any params map[string]any
payload any payload any
wrappedPayloadCtx context.Context wrappedPayloadModules map[string]common.Module
errorString string errorString string
}{ }{
{ {
name: "no module param", name: "no module param",
@@ -147,9 +146,9 @@ func TestBadDbQuery(t *testing.T) {
params: map[string]any{ params: map[string]any{
"query": "SELECT sqlite_version();", "query": "SELECT sqlite_version();",
}, },
wrappedPayloadCtx: test.GetContextWithModules(t.Context(), map[string]common.Module{ wrappedPayloadModules: map[string]common.Module{
"test": test.NewTestDBModule("test"), "test": test.NewTestDBModule("test"),
}), },
errorString: "db.query module error: not found", errorString: "db.query module error: not found",
}, },
{ {
@@ -159,9 +158,9 @@ func TestBadDbQuery(t *testing.T) {
"module": 1, "module": 1,
"query": "SELECT sqlite_version();", "query": "SELECT sqlite_version();",
}, },
wrappedPayloadCtx: test.GetContextWithModules(t.Context(), map[string]common.Module{ wrappedPayloadModules: map[string]common.Module{
"test": test.NewTestDBModule("test"), "test": test.NewTestDBModule("test"),
}), },
errorString: "db.query module error: not a string", errorString: "db.query module error: not a string",
}, },
{ {
@@ -170,9 +169,9 @@ func TestBadDbQuery(t *testing.T) {
params: map[string]any{ params: map[string]any{
"module": "test", "module": "test",
}, },
wrappedPayloadCtx: test.GetContextWithModules(t.Context(), map[string]common.Module{ wrappedPayloadModules: map[string]common.Module{
"test": test.NewTestDBModule("test"), "test": test.NewTestDBModule("test"),
}), },
errorString: "db.query query error: not found", errorString: "db.query query error: not found",
}, },
{ {
@@ -182,9 +181,9 @@ func TestBadDbQuery(t *testing.T) {
"module": "test", "module": "test",
"query": 1, "query": 1,
}, },
wrappedPayloadCtx: test.GetContextWithModules(t.Context(), map[string]common.Module{ wrappedPayloadModules: map[string]common.Module{
"test": test.NewTestDBModule("test"), "test": test.NewTestDBModule("test"),
}), },
errorString: "db.query query error: not a string", errorString: "db.query query error: not a string",
}, },
{ {
@@ -194,9 +193,9 @@ func TestBadDbQuery(t *testing.T) {
"module": "test", "module": "test",
"query": "select * from {{", "query": "select * from {{",
}, },
wrappedPayloadCtx: test.GetContextWithModules(t.Context(), map[string]common.Module{ wrappedPayloadModules: map[string]common.Module{
"test": test.NewTestDBModule("test"), "test": test.NewTestDBModule("test"),
}), },
errorString: "template: query:1: unclosed action", errorString: "template: query:1: unclosed action",
}, },
{ {
@@ -206,9 +205,9 @@ func TestBadDbQuery(t *testing.T) {
"module": "test", "module": "test",
"query": "select * from {{.Data}}", "query": "select * from {{.Data}}",
}, },
wrappedPayloadCtx: test.GetContextWithModules(t.Context(), map[string]common.Module{ wrappedPayloadModules: map[string]common.Module{
"test": test.NewTestDBModule("test"), "test": test.NewTestDBModule("test"),
}), },
errorString: "template: query:1:16: executing \"query\" at <.Data>: can't evaluate field Data in type common.WrappedPayload", errorString: "template: query:1:16: executing \"query\" at <.Data>: can't evaluate field Data in type common.WrappedPayload",
}, },
{ {
@@ -218,9 +217,9 @@ func TestBadDbQuery(t *testing.T) {
"module": "test", "module": "test",
"query": "select * from asdf;", "query": "select * from asdf;",
}, },
wrappedPayloadCtx: test.GetContextWithModules(t.Context(), map[string]common.Module{ wrappedPayloadModules: map[string]common.Module{
"test": test.NewTestDBModule("test"), "test": test.NewTestDBModule("test"),
}), },
errorString: "db.query error executing query: SQL logic error: no such table: asdf (1)", errorString: "db.query error executing query: SQL logic error: no such table: asdf (1)",
}, },
{ {
@@ -230,8 +229,8 @@ func TestBadDbQuery(t *testing.T) {
"module": "test", "module": "test",
"query": "select * from test;", "query": "select * from test;",
}, },
wrappedPayloadCtx: t.Context(), wrappedPayloadModules: nil,
errorString: "db.query wrapped payload has no modules", errorString: "db.query wrapped payload has no modules",
}, },
{ {
name: "module not found in context", name: "module not found in context",
@@ -240,8 +239,8 @@ func TestBadDbQuery(t *testing.T) {
"module": "test", "module": "test",
"query": "select * from test;", "query": "select * from test;",
}, },
wrappedPayloadCtx: test.GetContextWithModules(t.Context(), map[string]common.Module{}), wrappedPayloadModules: map[string]common.Module{},
errorString: "db.query unable to find module with id: test", errorString: "db.query unable to find module with id: test",
}, },
{ {
name: "module not found in context", name: "module not found in context",
@@ -250,8 +249,8 @@ func TestBadDbQuery(t *testing.T) {
"module": "test", "module": "test",
"query": "select * from test;", "query": "select * from test;",
}, },
wrappedPayloadCtx: test.GetContextWithModules(t.Context(), map[string]common.Module{}), wrappedPayloadModules: map[string]common.Module{},
errorString: "db.query unable to find module with id: test", errorString: "db.query unable to find module with id: test",
}, },
{ {
name: "module not a DatabseModule", name: "module not a DatabseModule",
@@ -260,9 +259,9 @@ func TestBadDbQuery(t *testing.T) {
"module": "test", "module": "test",
"query": "select * from test;", "query": "select * from test;",
}, },
wrappedPayloadCtx: test.GetContextWithModules(t.Context(), map[string]common.Module{ wrappedPayloadModules: map[string]common.Module{
"test": test.NewTestKVModule("test"), "test": test.NewTestKVModule("test"),
}), },
errorString: "db.query module with id test is not a DatabaseModule", errorString: "db.query module with id test is not a DatabaseModule",
}, },
} }
@@ -287,7 +286,10 @@ func TestBadDbQuery(t *testing.T) {
return return
} }
got, err := processorInstance.Process(t.Context(), common.GetWrappedPayload(test.wrappedPayloadCtx, test.payload)) got, err := processorInstance.Process(t.Context(), common.WrappedPayload{
Payload: test.payload,
Modules: test.wrappedPayloadModules,
})
if err == nil { if err == nil {
t.Fatalf("db.query expected to fail but got payload: %+v", got) t.Fatalf("db.query expected to fail but got payload: %+v", got)
@@ -299,3 +301,32 @@ func TestBadDbQuery(t *testing.T) {
}) })
} }
} }
func BenchmarkDbQuery(b *testing.B) {
registration, ok := processor.ProcessorRegistry["db.query"]
if !ok {
b.Fatalf("db.query processor not registered")
}
processorInstance, err := registration.New(config.ProcessorConfig{
Type: "db.query",
Params: map[string]any{
"module": "test",
"query": "SELECT * FROM test;",
},
})
if err != nil {
b.Fatalf("db.query failed to create processor: %s", err)
}
modules := map[string]common.Module{
"test": test.NewTestDBModule("test"),
}
for b.Loop() {
_, err := processorInstance.Process(b.Context(), common.WrappedPayload{Payload: nil, Modules: modules})
if err != nil {
b.Fatalf("db.query processing failed: %s", err)
}
}
}
+29 -3
View File
@@ -30,7 +30,7 @@ func TestDebugLogFromRegistry(t *testing.T) {
payload := "test" payload := "test"
expected := "test" expected := "test"
got, err := processorInstance.Process(t.Context(), common.GetWrappedPayload(t.Context(), payload)) got, err := processorInstance.Process(t.Context(), common.WrappedPayload{Payload: payload})
if err != nil { if err != nil {
t.Fatalf("debug.log processing failed: %s", err) t.Fatalf("debug.log processing failed: %s", err)
} }
@@ -66,7 +66,7 @@ func TestGoodDebugLog(t *testing.T) {
t.Fatalf("debug.log failed to create processor: %s", err) t.Fatalf("debug.log failed to create processor: %s", err)
} }
got, err := processorInstance.Process(t.Context(), common.GetWrappedPayload(t.Context(), test.payload)) got, err := processorInstance.Process(t.Context(), common.WrappedPayload{Payload: test.payload})
if err != nil { if err != nil {
t.Fatalf("debug.log processing failed: %s", err) t.Fatalf("debug.log processing failed: %s", err)
} }
@@ -106,7 +106,7 @@ func TestBadDebugLog(t *testing.T) {
return return
} }
got, err := processorInstance.Process(t.Context(), common.GetWrappedPayload(t.Context(), test.payload)) got, err := processorInstance.Process(t.Context(), common.WrappedPayload{Payload: test.payload})
if err == nil { if err == nil {
t.Fatalf("debug.log expected to fail but succeeded, got: %v", got) t.Fatalf("debug.log expected to fail but succeeded, got: %v", got)
@@ -118,3 +118,29 @@ func TestBadDebugLog(t *testing.T) {
}) })
} }
} }
func BenchmarkDebugLog(b *testing.B) {
registration, ok := processor.ProcessorRegistry["debug.log"]
if !ok {
b.Fatalf("debug.log processor not registered")
}
processorInstance, err := registration.New(config.ProcessorConfig{
Type: "debug.log",
Params: nil,
})
if err != nil {
b.Fatalf("debug.log failed to create processor: %s", err)
}
modules := map[string]common.Module{}
count := 0
for b.Loop() {
_, err := processorInstance.Process(b.Context(), common.WrappedPayload{Payload: count, Modules: modules})
if err != nil {
b.Fatalf("debug.log processing failed: %s", err)
}
count++
}
}
+31 -3
View File
@@ -29,7 +29,9 @@ func TestFilterChangeFromRegistry(t *testing.T) {
payload := "hello" payload := "hello"
expected := "hello" expected := "hello"
got, err := processorInstance.Process(t.Context(), common.GetWrappedPayload(t.Context(), payload)) got, err := processorInstance.Process(t.Context(), common.WrappedPayload{
Payload: payload,
})
if err != nil { if err != nil {
t.Fatalf("filter.change processing failed: %s", err) t.Fatalf("filter.change processing failed: %s", err)
} }
@@ -70,7 +72,7 @@ func TestGoodFilterChange(t *testing.T) {
t.Fatalf("filter.change failed to create processor: %s", err) t.Fatalf("filter.change failed to create processor: %s", err)
} }
got, err := processorInstance.Process(t.Context(), common.GetWrappedPayload(t.Context(), test.payload)) got, err := processorInstance.Process(t.Context(), common.WrappedPayload{Payload: test.payload})
if err != nil { if err != nil {
t.Fatalf("filter.change processing failed: %s", err) t.Fatalf("filter.change processing failed: %s", err)
@@ -110,7 +112,7 @@ func TestBadFilterChange(t *testing.T) {
return return
} }
got, err := processorInstance.Process(t.Context(), common.GetWrappedPayload(t.Context(), test.payload)) got, err := processorInstance.Process(t.Context(), common.WrappedPayload{Payload: test.payload})
if err == nil { if err == nil {
t.Fatalf("filter.change expected to fail but got payload: %+v", got) t.Fatalf("filter.change expected to fail but got payload: %+v", got)
@@ -122,3 +124,29 @@ func TestBadFilterChange(t *testing.T) {
}) })
} }
} }
func BenchmarkFilterChange(b *testing.B) {
registration, ok := processor.ProcessorRegistry["filter.change"]
if !ok {
b.Fatalf("filter.change processor not registered")
}
processorInstance, err := registration.New(config.ProcessorConfig{
Type: "filter.change",
Params: nil,
})
if err != nil {
b.Fatalf("filter.change failed to create processor: %s", err)
}
modules := map[string]common.Module{}
count := 0
for b.Loop() {
_, err := processorInstance.Process(b.Context(), common.WrappedPayload{Payload: count, Modules: modules})
if err != nil {
b.Fatalf("filter.change processing failed: %s", err)
}
count++
}
}
+29 -2
View File
@@ -85,7 +85,7 @@ func TestGoodFilterExpr(t *testing.T) {
t.Fatalf("filter.expr failed to create processor: %s", err) t.Fatalf("filter.expr failed to create processor: %s", err)
} }
got, err := processorInstance.Process(t.Context(), common.GetWrappedPayload(t.Context(), testCase.payload)) got, err := processorInstance.Process(t.Context(), common.WrappedPayload{Payload: testCase.payload})
if err != nil { if err != nil {
t.Fatalf("filter.expr processing failed: %s", err) t.Fatalf("filter.expr processing failed: %s", err)
@@ -159,7 +159,7 @@ func TestBadFilterExpr(t *testing.T) {
} }
return return
} }
got, err := processorInstance.Process(t.Context(), common.GetWrappedPayload(t.Context(), test.payload)) got, err := processorInstance.Process(t.Context(), common.WrappedPayload{Payload: test.payload})
if err == nil { if err == nil {
t.Fatalf("filter.expr expected to fail but succeeded, got: %v", got) t.Fatalf("filter.expr expected to fail but succeeded, got: %v", got)
@@ -171,3 +171,30 @@ func TestBadFilterExpr(t *testing.T) {
}) })
} }
} }
func BenchmarkFilterExpr(b *testing.B) {
registration, ok := processor.ProcessorRegistry["filter.expr"]
if !ok {
b.Fatalf("filter.expr processor not registered")
}
processorInstance, err := registration.New(config.ProcessorConfig{
Type: "filter.expr",
Params: map[string]any{
"expression": "Payload % 2 == 0",
},
})
if err != nil {
b.Fatalf("filter.expr failed to create processor: %s", err)
}
count := 0
for b.Loop() {
_, err := processorInstance.Process(b.Context(), common.WrappedPayload{Payload: count})
if err != nil {
b.Fatalf("filter.expr processing failed: %s", err)
}
count++
}
}
+31 -3
View File
@@ -1,6 +1,7 @@
package processor_test package processor_test
import ( import (
"fmt"
"testing" "testing"
"github.com/jwetzell/showbridge-go/internal/common" "github.com/jwetzell/showbridge-go/internal/common"
@@ -31,7 +32,7 @@ func TestFilterRegexFromRegistry(t *testing.T) {
payload := "hello" payload := "hello"
expected := "hello" expected := "hello"
got, err := processorInstance.Process(t.Context(), common.GetWrappedPayload(t.Context(), payload)) got, err := processorInstance.Process(t.Context(), common.WrappedPayload{Payload: payload})
if err != nil { if err != nil {
t.Fatalf("filter.regex processing failed: %s", err) t.Fatalf("filter.regex processing failed: %s", err)
} }
@@ -90,7 +91,7 @@ func TestGoodFilterRegex(t *testing.T) {
t.Fatalf("filter.regex failed to create processor: %s", err) t.Fatalf("filter.regex failed to create processor: %s", err)
} }
got, err := processorInstance.Process(t.Context(), common.GetWrappedPayload(t.Context(), test.payload)) got, err := processorInstance.Process(t.Context(), common.WrappedPayload{Payload: test.payload})
if err != nil { if err != nil {
t.Fatalf("filter.regex processing failed: %s", err) t.Fatalf("filter.regex processing failed: %s", err)
@@ -161,7 +162,7 @@ func TestBadFilterRegex(t *testing.T) {
return return
} }
got, err := processorInstance.Process(t.Context(), common.GetWrappedPayload(t.Context(), test.payload)) got, err := processorInstance.Process(t.Context(), common.WrappedPayload{Payload: test.payload})
if err == nil { if err == nil {
t.Fatalf("filter.regex expected to fail but got payload: %+v", got) t.Fatalf("filter.regex expected to fail but got payload: %+v", got)
@@ -173,3 +174,30 @@ func TestBadFilterRegex(t *testing.T) {
}) })
} }
} }
func BenchmarkFilterRegex(b *testing.B) {
registration, ok := processor.ProcessorRegistry["filter.regex"]
if !ok {
b.Fatalf("filter.regex processor not registered")
}
processorInstance, err := registration.New(config.ProcessorConfig{
Type: "filter.regex",
Params: map[string]any{
"pattern": ".*",
},
})
if err != nil {
b.Fatalf("filter.regex failed to create processor: %s", err)
}
count := 0
for b.Loop() {
_, err := processorInstance.Process(b.Context(), common.WrappedPayload{Payload: fmt.Sprintf("%d", count)})
if err != nil {
b.Fatalf("filter.regex processing failed: %s", err)
}
count++
}
}
+28 -2
View File
@@ -1,6 +1,7 @@
package processor_test package processor_test
import ( import (
"fmt"
"testing" "testing"
"github.com/jwetzell/showbridge-go/internal/common" "github.com/jwetzell/showbridge-go/internal/common"
@@ -76,7 +77,7 @@ func TestGoodFloatParse(t *testing.T) {
t.Fatalf("float.parse failed to create processor: %s", err) t.Fatalf("float.parse failed to create processor: %s", err)
} }
got, err := processorInstance.Process(t.Context(), common.GetWrappedPayload(t.Context(), test.payload)) got, err := processorInstance.Process(t.Context(), common.WrappedPayload{Payload: test.payload})
if err != nil { if err != nil {
t.Fatalf("float.parse processing failed: %s", err) t.Fatalf("float.parse processing failed: %s", err)
} }
@@ -152,7 +153,7 @@ func TestBadFloatParse(t *testing.T) {
return return
} }
got, err := processorInstance.Process(t.Context(), common.GetWrappedPayload(t.Context(), test.payload)) got, err := processorInstance.Process(t.Context(), common.WrappedPayload{Payload: test.payload})
if err == nil { if err == nil {
t.Fatalf("float.parse expected to fail but succeeded, got: %v", got) t.Fatalf("float.parse expected to fail but succeeded, got: %v", got)
@@ -164,3 +165,28 @@ func TestBadFloatParse(t *testing.T) {
}) })
} }
} }
func BenchmarkFloatParse(b *testing.B) {
registration, ok := processor.ProcessorRegistry["float.parse"]
if !ok {
b.Fatalf("float.parse processor not registered")
}
processorInstance, err := registration.New(config.ProcessorConfig{
Type: "float.parse",
Params: nil,
})
if err != nil {
b.Fatalf("float.parse failed to create processor: %s", err)
}
count := 0
for b.Loop() {
_, err := processorInstance.Process(b.Context(), common.WrappedPayload{Payload: fmt.Sprintf("%d", count)})
if err != nil {
b.Fatalf("float.parse processing failed: %s", err)
}
count++
}
}
+28 -2
View File
@@ -71,7 +71,7 @@ func TestGoodFloatRandom(t *testing.T) {
t.Fatalf("float.random failed to create processor: %s", err) t.Fatalf("float.random failed to create processor: %s", err)
} }
got, err := processorInstance.Process(t.Context(), common.GetWrappedPayload(t.Context(), test.payload)) got, err := processorInstance.Process(t.Context(), common.WrappedPayload{Payload: test.payload})
if err != nil { if err != nil {
t.Fatalf("float.random processing failed: %s", err) t.Fatalf("float.random processing failed: %s", err)
} }
@@ -172,7 +172,7 @@ func TestBadFloatRandom(t *testing.T) {
return return
} }
got, err := processorInstance.Process(t.Context(), common.GetWrappedPayload(t.Context(), test.payload)) got, err := processorInstance.Process(t.Context(), common.WrappedPayload{Payload: test.payload})
if err == nil { if err == nil {
t.Fatalf("float.random expected to fail but got payload: %+v", got) t.Fatalf("float.random expected to fail but got payload: %+v", got)
@@ -184,3 +184,29 @@ func TestBadFloatRandom(t *testing.T) {
}) })
} }
} }
func BenchmarkFloatRandom(b *testing.B) {
registration, ok := processor.ProcessorRegistry["float.random"]
if !ok {
b.Fatalf("float.random processor not registered")
}
processorInstance, err := registration.New(config.ProcessorConfig{
Type: "float.random",
Params: map[string]any{
"min": 0.0,
"max": 1.0,
},
})
if err != nil {
b.Fatalf("float.random failed to create processor: %s", err)
}
for b.Loop() {
_, err := processorInstance.Process(b.Context(), common.WrappedPayload{Payload: nil})
if err != nil {
b.Fatalf("float.random processing failed: %s", err)
}
}
}
+37 -2
View File
@@ -103,7 +103,7 @@ func TestGoodFreeDCreate(t *testing.T) {
t.Fatalf("freed.create failed to create processor: %s", err) t.Fatalf("freed.create failed to create processor: %s", err)
} }
got, err := processorInstance.Process(t.Context(), common.GetWrappedPayload(t.Context(), test.payload)) got, err := processorInstance.Process(t.Context(), common.WrappedPayload{Payload: test.payload})
if err != nil { if err != nil {
t.Fatalf("freed.create processing failed: %s", err) t.Fatalf("freed.create processing failed: %s", err)
} }
@@ -865,7 +865,7 @@ func TestBadFreeDCreate(t *testing.T) {
return return
} }
got, err := processorInstance.Process(t.Context(), common.GetWrappedPayload(t.Context(), test.payload)) got, err := processorInstance.Process(t.Context(), common.WrappedPayload{Payload: test.payload})
if err == nil { if err == nil {
t.Fatalf("freed.create expected to fail but succeeded, got: %v", got) t.Fatalf("freed.create expected to fail but succeeded, got: %v", got)
@@ -877,3 +877,38 @@ func TestBadFreeDCreate(t *testing.T) {
}) })
} }
} }
func BenchmarkFreeDCreate(b *testing.B) {
registration, ok := processor.ProcessorRegistry["freed.create"]
if !ok {
b.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 {
b.Fatalf("freed.create failed to create processor: %s", err)
}
count := 0
for b.Loop() {
_, err := processorInstance.Process(b.Context(), common.WrappedPayload{Payload: count})
if err != nil {
b.Fatalf("freed.create processing failed: %s", err)
}
count++
}
}
+16 -2
View File
@@ -59,7 +59,7 @@ func TestGoodFreeDDecode(t *testing.T) {
for _, test := range tests { for _, test := range tests {
t.Run(test.name, func(t *testing.T) { t.Run(test.name, func(t *testing.T) {
got, err := packetEncoder.Process(t.Context(), common.GetWrappedPayload(t.Context(), test.payload)) got, err := packetEncoder.Process(t.Context(), common.WrappedPayload{Payload: test.payload})
if err != nil { if err != nil {
t.Fatalf("freed.decode processing failed: %s", err) t.Fatalf("freed.decode processing failed: %s", err)
@@ -90,7 +90,7 @@ func TestBadFreeDDecode(t *testing.T) {
for _, test := range tests { for _, test := range tests {
t.Run(test.name, func(t *testing.T) { t.Run(test.name, func(t *testing.T) {
got, err := packetEncoder.Process(t.Context(), common.GetWrappedPayload(t.Context(), test.payload)) got, err := packetEncoder.Process(t.Context(), common.WrappedPayload{Payload: test.payload})
if err == nil { if err == nil {
t.Fatalf("freed.decode expected to fail but succeeded, got: %v", got) t.Fatalf("freed.decode expected to fail but succeeded, got: %v", got)
@@ -102,3 +102,17 @@ func TestBadFreeDDecode(t *testing.T) {
}) })
} }
} }
func BenchmarkFreeDDecode(b *testing.B) {
processorInstance := processor.FreeDDecode{}
payload := []byte{0xd1, 0x01, 0x5a, 0x00, 0x00, 0x2d, 0x00, 0x00, 0xa6, 0x00, 0x00, 0x7f, 0xff, 0x40, 0x7f, 0xff, 0x80, 0x7f, 0xff,
0xc0, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x00, 0x00, 50,
}
for b.Loop() {
_, err := processorInstance.Process(b.Context(), common.WrappedPayload{Payload: payload})
if err != nil {
b.Fatalf("freed.encode processing failed: %s", err)
}
}
}
+24 -2
View File
@@ -59,7 +59,7 @@ func TestGoodFreeDEncode(t *testing.T) {
for _, test := range tests { for _, test := range tests {
t.Run(test.name, func(t *testing.T) { t.Run(test.name, func(t *testing.T) {
got, err := packetEncoder.Process(t.Context(), common.GetWrappedPayload(t.Context(), test.payload)) got, err := packetEncoder.Process(t.Context(), common.WrappedPayload{Payload: test.payload})
if err != nil { if err != nil {
t.Fatalf("freed.encode processing failed: %s", err) t.Fatalf("freed.encode processing failed: %s", err)
@@ -90,7 +90,7 @@ func TestBadFreeDEncode(t *testing.T) {
for _, test := range tests { for _, test := range tests {
t.Run(test.name, func(t *testing.T) { t.Run(test.name, func(t *testing.T) {
got, err := packetEncoder.Process(t.Context(), common.GetWrappedPayload(t.Context(), test.payload)) got, err := packetEncoder.Process(t.Context(), common.WrappedPayload{Payload: test.payload})
if err == nil { if err == nil {
t.Fatalf("freed.encode expected to fail but succeeded, got: %v", got) t.Fatalf("freed.encode expected to fail but succeeded, got: %v", got)
@@ -102,3 +102,25 @@ func TestBadFreeDEncode(t *testing.T) {
}) })
} }
} }
func BenchmarkFreeDEncode(b *testing.B) {
processorInstance := processor.FreeDEncode{}
payload := freeD.FreeDPosition{
ID: 1,
Pan: 180,
Tilt: 90,
Roll: -180,
PosX: 131069,
PosY: 131070,
PosZ: 131071,
Zoom: 66051,
Focus: 263430,
}
for b.Loop() {
_, err := processorInstance.Process(b.Context(), common.WrappedPayload{Payload: payload})
if err != nil {
b.Fatalf("freed.encode processing failed: %s", err)
}
}
}
@@ -58,7 +58,7 @@ func TestGoodHTTPRequestDo(t *testing.T) {
t.Fatalf("http.request.do failed to create processor: %s", err) t.Fatalf("http.request.do failed to create processor: %s", err)
} }
got, err := processorInstance.Process(t.Context(), common.GetWrappedPayload(t.Context(), test.payload)) got, err := processorInstance.Process(t.Context(), common.WrappedPayload{Payload: test.payload})
if err != nil { if err != nil {
t.Fatalf("http.request.do processing failed: %s", err) t.Fatalf("http.request.do processing failed: %s", err)
} }
@@ -149,7 +149,7 @@ func TestBadHTTPRequestDo(t *testing.T) {
return return
} }
got, err := processorInstance.Process(t.Context(), common.GetWrappedPayload(t.Context(), test.payload)) got, err := processorInstance.Process(t.Context(), common.WrappedPayload{Payload: test.payload})
if err == nil { if err == nil {
t.Fatalf("http.request.do expected to fail but succeeded, got: %v", got) t.Fatalf("http.request.do expected to fail but succeeded, got: %v", got)
@@ -68,7 +68,7 @@ func TestGoodHTTPResponseCreate(t *testing.T) {
t.Fatalf("http.response.create failed to create processor: %s", err) t.Fatalf("http.response.create failed to create processor: %s", err)
} }
got, err := processorInstance.Process(t.Context(), common.GetWrappedPayload(t.Context(), test.payload)) got, err := processorInstance.Process(t.Context(), common.WrappedPayload{Payload: test.payload})
if err != nil { if err != nil {
t.Fatalf("http.response.create processing failed: %s", err) t.Fatalf("http.response.create processing failed: %s", err)
} }
@@ -145,7 +145,7 @@ func TestBadHTTPResponseCreate(t *testing.T) {
return return
} }
got, err := processorInstance.Process(t.Context(), common.GetWrappedPayload(t.Context(), test.payload)) got, err := processorInstance.Process(t.Context(), common.WrappedPayload{Payload: test.payload})
if err == nil { if err == nil {
t.Fatalf("http.response.create expected to fail but succeeded, got: %v", got) t.Fatalf("http.response.create expected to fail but succeeded, got: %v", got)
@@ -157,3 +157,31 @@ func TestBadHTTPResponseCreate(t *testing.T) {
}) })
} }
} }
func BenchmarkHTTPResponseCreate(b *testing.B) {
registration, ok := processor.ProcessorRegistry["http.response.create"]
if !ok {
b.Fatalf("http.response.create processor not registered")
}
processorInstance, err := registration.New(config.ProcessorConfig{
Type: "http.response.create",
Params: map[string]any{
"status": 200,
"bodyTemplate": "Hello, {{.Payload}}!",
},
})
if err != nil {
b.Fatalf("http.response.create failed to create processor: %s", err)
}
count := 0
for b.Loop() {
_, err := processorInstance.Process(b.Context(), common.WrappedPayload{Payload: count})
if err != nil {
b.Fatalf("http.response.create processing failed: %s", err)
}
count++
}
}
+28 -2
View File
@@ -1,6 +1,7 @@
package processor_test package processor_test
import ( import (
"fmt"
"testing" "testing"
"github.com/jwetzell/showbridge-go/internal/common" "github.com/jwetzell/showbridge-go/internal/common"
@@ -97,7 +98,7 @@ func TestGoodIntParse(t *testing.T) {
t.Fatalf("int.parse failed to create processor: %s", err) t.Fatalf("int.parse failed to create processor: %s", err)
} }
got, err := processorInstance.Process(t.Context(), common.GetWrappedPayload(t.Context(), test.payload)) got, err := processorInstance.Process(t.Context(), common.WrappedPayload{Payload: test.payload})
if err != nil { if err != nil {
t.Fatalf("int.parse processing failed: %s", err) t.Fatalf("int.parse processing failed: %s", err)
} }
@@ -186,7 +187,7 @@ func TestBadIntParse(t *testing.T) {
return return
} }
got, err := processorInstance.Process(t.Context(), common.GetWrappedPayload(t.Context(), test.payload)) got, err := processorInstance.Process(t.Context(), common.WrappedPayload{Payload: test.payload})
if err == nil { if err == nil {
t.Fatalf("int.parse expected to fail but succeeded, got: %v", got) t.Fatalf("int.parse expected to fail but succeeded, got: %v", got)
@@ -198,3 +199,28 @@ func TestBadIntParse(t *testing.T) {
}) })
} }
} }
func BenchmarkIntParse(b *testing.B) {
registration, ok := processor.ProcessorRegistry["int.parse"]
if !ok {
b.Fatalf("int.parse processor not registered")
}
processorInstance, err := registration.New(config.ProcessorConfig{
Type: "int.parse",
Params: nil,
})
if err != nil {
b.Fatalf("int.parse failed to create processor: %s", err)
}
count := 0
for b.Loop() {
_, err := processorInstance.Process(b.Context(), common.WrappedPayload{Payload: fmt.Sprintf("%d", count)})
if err != nil {
b.Fatalf("int.parse processing failed: %s", err)
}
count++
}
}
+29 -3
View File
@@ -51,7 +51,7 @@ func TestIntRandomGoodConfig(t *testing.T) {
payload := "12345" payload := "12345"
got, err := processorInstance.Process(t.Context(), common.GetWrappedPayload(t.Context(), payload)) got, err := processorInstance.Process(t.Context(), common.WrappedPayload{Payload: payload})
if err != nil { if err != nil {
t.Fatalf("int.random processing failed: %s", err) t.Fatalf("int.random processing failed: %s", err)
} }
@@ -98,7 +98,7 @@ func TestGoodIntRandom(t *testing.T) {
t.Fatalf("int.random failed to create processor: %s", err) t.Fatalf("int.random failed to create processor: %s", err)
} }
got, err := processorInstance.Process(t.Context(), common.GetWrappedPayload(t.Context(), test.payload)) got, err := processorInstance.Process(t.Context(), common.WrappedPayload{Payload: test.payload})
if err != nil { if err != nil {
t.Fatalf("int.random processing failed: %s", err) t.Fatalf("int.random processing failed: %s", err)
} }
@@ -183,7 +183,7 @@ func TestBadIntRandom(t *testing.T) {
return return
} }
got, err := processorInstance.Process(t.Context(), common.GetWrappedPayload(t.Context(), test.payload)) got, err := processorInstance.Process(t.Context(), common.WrappedPayload{Payload: test.payload})
if err == nil { if err == nil {
t.Fatalf("int.random expected to fail but got payload: %+v", got) t.Fatalf("int.random expected to fail but got payload: %+v", got)
@@ -195,3 +195,29 @@ func TestBadIntRandom(t *testing.T) {
}) })
} }
} }
func BenchmarkIntRandom(b *testing.B) {
registration, ok := processor.ProcessorRegistry["int.random"]
if !ok {
b.Fatalf("int.random processor not registered")
}
processorInstance, err := registration.New(config.ProcessorConfig{
Type: "int.random",
Params: map[string]any{
"min": 0,
"max": 100,
},
})
if err != nil {
b.Fatalf("int.random failed to create processor: %s", err)
}
for b.Loop() {
_, err := processorInstance.Process(b.Context(), common.WrappedPayload{Payload: nil})
if err != nil {
b.Fatalf("int.random processing failed: %s", err)
}
}
}
+32 -2
View File
@@ -69,7 +69,7 @@ func TestGoodIntScale(t *testing.T) {
t.Fatalf("int.scale failed to create processor: %s", err) t.Fatalf("int.scale failed to create processor: %s", err)
} }
got, err := processorInstance.Process(t.Context(), common.GetWrappedPayload(t.Context(), test.payload)) got, err := processorInstance.Process(t.Context(), common.WrappedPayload{Payload: test.payload})
if err != nil { if err != nil {
t.Fatalf("int.scale processing failed: %s", err) t.Fatalf("int.scale processing failed: %s", err)
} }
@@ -157,7 +157,7 @@ func TestBadIntScale(t *testing.T) {
return return
} }
got, err := processorInstance.Process(t.Context(), common.GetWrappedPayload(t.Context(), test.payload)) got, err := processorInstance.Process(t.Context(), common.WrappedPayload{Payload: test.payload})
if err == nil { if err == nil {
t.Fatalf("int.scale expected to fail but got payload: %+v", got) t.Fatalf("int.scale expected to fail but got payload: %+v", got)
@@ -169,3 +169,33 @@ func TestBadIntScale(t *testing.T) {
}) })
} }
} }
func BenchmarkIntScale(b *testing.B) {
registration, ok := processor.ProcessorRegistry["int.scale"]
if !ok {
b.Fatalf("int.scale processor not registered")
}
processorInstance, err := registration.New(config.ProcessorConfig{
Type: "int.scale",
Params: map[string]any{
"inMin": 0,
"inMax": 100,
"outMin": 0,
"outMax": 127,
},
})
if err != nil {
b.Fatalf("int.scale failed to create processor: %s", err)
}
count := 0
for b.Loop() {
_, err := processorInstance.Process(b.Context(), common.WrappedPayload{Payload: count % 100})
if err != nil {
b.Fatalf("int.scale processing failed: %s", err)
}
count++
}
}
+28 -3
View File
@@ -1,6 +1,7 @@
package processor_test package processor_test
import ( import (
"fmt"
"reflect" "reflect"
"testing" "testing"
@@ -32,7 +33,7 @@ func TestJsonDecodeFromRegistry(t *testing.T) {
"property": "hello", "property": "hello",
} }
got, err := processorInstance.Process(t.Context(), common.GetWrappedPayload(t.Context(), payload)) got, err := processorInstance.Process(t.Context(), common.WrappedPayload{Payload: payload})
if err != nil { if err != nil {
t.Fatalf("json.decode processing failed: %s", err) t.Fatalf("json.decode processing failed: %s", err)
} }
@@ -75,7 +76,7 @@ func TestGoodJsonDecode(t *testing.T) {
for _, test := range tests { for _, test := range tests {
t.Run(test.name, func(t *testing.T) { t.Run(test.name, func(t *testing.T) {
got, err := jsonDecoder.Process(t.Context(), common.GetWrappedPayload(t.Context(), test.payload)) got, err := jsonDecoder.Process(t.Context(), common.WrappedPayload{Payload: test.payload})
if err != nil { if err != nil {
t.Fatalf("json.decode processing failed: %s", err) t.Fatalf("json.decode processing failed: %s", err)
} }
@@ -113,7 +114,7 @@ func TestBadJsonDecode(t *testing.T) {
for _, test := range tests { for _, test := range tests {
t.Run(test.name, func(t *testing.T) { t.Run(test.name, func(t *testing.T) {
got, err := stringEncoder.Process(t.Context(), common.GetWrappedPayload(t.Context(), test.payload)) got, err := stringEncoder.Process(t.Context(), common.WrappedPayload{Payload: test.payload})
if err == nil { if err == nil {
t.Fatalf("json.decode expected to fail but got payload: %+v", got) t.Fatalf("json.decode expected to fail but got payload: %+v", got)
@@ -124,3 +125,27 @@ func TestBadJsonDecode(t *testing.T) {
}) })
} }
} }
func BenchmarkJsonDecode(b *testing.B) {
registration, ok := processor.ProcessorRegistry["json.decode"]
if !ok {
b.Fatalf("json.decode processor not registered")
}
processorInstance, err := registration.New(config.ProcessorConfig{
Type: "json.decode",
})
if err != nil {
b.Fatalf("json.decode failed to create processor: %s", err)
}
count := 0
for b.Loop() {
_, err := processorInstance.Process(b.Context(), common.WrappedPayload{Payload: []byte(fmt.Sprintf("{\"key\":%d}", count))})
if err != nil {
b.Fatalf("json.decode processing failed: %s", err)
}
count++
}
}
+28 -3
View File
@@ -1,6 +1,7 @@
package processor_test package processor_test
import ( import (
"fmt"
"slices" "slices"
"testing" "testing"
@@ -35,7 +36,7 @@ func TestJsonEncodeFromRegistry(t *testing.T) {
expected := []byte("{\"property\":\"hello\"}") expected := []byte("{\"property\":\"hello\"}")
got, err := processorInstance.Process(t.Context(), common.GetWrappedPayload(t.Context(), payload)) got, err := processorInstance.Process(t.Context(), common.WrappedPayload{Payload: payload})
if err != nil { if err != nil {
t.Fatalf("json.encode processing failed: %s", err) t.Fatalf("json.encode processing failed: %s", err)
} }
@@ -69,7 +70,7 @@ func TestGoodJsonEncode(t *testing.T) {
for _, test := range tests { for _, test := range tests {
t.Run(test.name, func(t *testing.T) { t.Run(test.name, func(t *testing.T) {
got, err := jsonEncoder.Process(t.Context(), common.GetWrappedPayload(t.Context(), test.payload)) got, err := jsonEncoder.Process(t.Context(), common.WrappedPayload{Payload: test.payload})
if err != nil { if err != nil {
t.Fatalf("json.encode processing failed: %s", err) t.Fatalf("json.encode processing failed: %s", err)
} }
@@ -102,7 +103,7 @@ func TestBadJsonEncode(t *testing.T) {
for _, test := range tests { for _, test := range tests {
t.Run(test.name, func(t *testing.T) { t.Run(test.name, func(t *testing.T) {
got, err := stringEncoder.Process(t.Context(), common.GetWrappedPayload(t.Context(), test.payload)) got, err := stringEncoder.Process(t.Context(), common.WrappedPayload{Payload: test.payload})
if err == nil { if err == nil {
t.Fatalf("json.encode expected to fail but got payload: %+v", got) t.Fatalf("json.encode expected to fail but got payload: %+v", got)
@@ -113,3 +114,27 @@ func TestBadJsonEncode(t *testing.T) {
}) })
} }
} }
func BenchmarkJsonEncode(b *testing.B) {
registration, ok := processor.ProcessorRegistry["json.encode"]
if !ok {
b.Fatalf("json.encode processor not registered")
}
processorInstance, err := registration.New(config.ProcessorConfig{
Type: "json.encode",
})
if err != nil {
b.Fatalf("json.encode failed to create processor: %s", err)
}
count := 0
for b.Loop() {
_, err := processorInstance.Process(b.Context(), common.WrappedPayload{Payload: fmt.Sprintf("{\"key\":%d}", count)})
if err != nil {
b.Fatalf("json.encode processing failed: %s", err)
}
count++
}
}
+58 -41
View File
@@ -1,7 +1,6 @@
package processor_test package processor_test
import ( import (
"context"
"reflect" "reflect"
"testing" "testing"
@@ -35,12 +34,12 @@ func TestKvGetFromRegistry(t *testing.T) {
payload := "hello" payload := "hello"
expected := "test" expected := "test"
got, err := processorInstance.Process(t.Context(), common.GetWrappedPayload(test.GetContextWithModules( got, err := processorInstance.Process(t.Context(), common.WrappedPayload{
t.Context(), Modules: map[string]common.Module{
map[string]common.Module{
"test": test.NewTestKVModule("test"), "test": test.NewTestKVModule("test"),
}, },
), payload)) Payload: payload,
})
if err != nil { if err != nil {
t.Fatalf("kv.get processing failed: %s", err) t.Fatalf("kv.get processing failed: %s", err)
} }
@@ -59,21 +58,10 @@ func TestGoodKvGet(t *testing.T) {
expected any expected any
}{ }{
{ {
name: "basic value", name: "basic key",
params: map[string]any{ params: map[string]any{
"module": "test", "module": "test",
"key": "test", "key": "test",
"value": "hello",
},
payload: "hello",
expected: "test",
},
{
name: "template value",
params: map[string]any{
"module": "test",
"key": "test",
"value": "{{.Payload}}",
}, },
payload: "hello", payload: "hello",
expected: "test", expected: "test",
@@ -95,12 +83,12 @@ func TestGoodKvGet(t *testing.T) {
t.Fatalf("kv.get failed to create processor: %s", err) t.Fatalf("kv.get failed to create processor: %s", err)
} }
got, err := processorInstance.Process(t.Context(), common.GetWrappedPayload(test.GetContextWithModules( got, err := processorInstance.Process(t.Context(), common.WrappedPayload{
t.Context(), Modules: map[string]common.Module{
map[string]common.Module{
"test": test.NewTestKVModule("test"), "test": test.NewTestKVModule("test"),
}, },
), testCase.payload)) Payload: testCase.payload,
})
if err != nil { if err != nil {
t.Fatalf("kv.get processing failed: %s", err) t.Fatalf("kv.get processing failed: %s", err)
@@ -115,11 +103,11 @@ func TestGoodKvGet(t *testing.T) {
func TestBadKvGet(t *testing.T) { func TestBadKvGet(t *testing.T) {
tests := []struct { tests := []struct {
name string name string
params map[string]any params map[string]any
payload any payload any
wrappedPayloadCtx context.Context wrappedPayloadModules map[string]common.Module
errorString string errorString string
}{ }{
{ {
name: "no module param", name: "no module param",
@@ -127,9 +115,9 @@ func TestBadKvGet(t *testing.T) {
params: map[string]any{ params: map[string]any{
"key": "test", "key": "test",
}, },
wrappedPayloadCtx: test.GetContextWithModules(t.Context(), map[string]common.Module{ wrappedPayloadModules: map[string]common.Module{
"test": test.NewTestKVModule("test"), "test": test.NewTestKVModule("test"),
}), },
errorString: "kv.get module error: not found", errorString: "kv.get module error: not found",
}, },
{ {
@@ -139,9 +127,9 @@ func TestBadKvGet(t *testing.T) {
"module": 1, "module": 1,
"key": "test", "key": "test",
}, },
wrappedPayloadCtx: test.GetContextWithModules(t.Context(), map[string]common.Module{ wrappedPayloadModules: map[string]common.Module{
"test": test.NewTestKVModule("test"), "test": test.NewTestKVModule("test"),
}), },
errorString: "kv.get module error: not a string", errorString: "kv.get module error: not a string",
}, },
{ {
@@ -150,9 +138,9 @@ func TestBadKvGet(t *testing.T) {
params: map[string]any{ params: map[string]any{
"module": "test", "module": "test",
}, },
wrappedPayloadCtx: test.GetContextWithModules(t.Context(), map[string]common.Module{ wrappedPayloadModules: map[string]common.Module{
"test": test.NewTestKVModule("test"), "test": test.NewTestKVModule("test"),
}), },
errorString: "kv.get key error: not found", errorString: "kv.get key error: not found",
}, },
{ {
@@ -162,9 +150,9 @@ func TestBadKvGet(t *testing.T) {
"module": "test", "module": "test",
"key": 1, "key": 1,
}, },
wrappedPayloadCtx: test.GetContextWithModules(t.Context(), map[string]common.Module{ wrappedPayloadModules: map[string]common.Module{
"test": test.NewTestKVModule("test"), "test": test.NewTestKVModule("test"),
}), },
errorString: "kv.get key error: not a string", errorString: "kv.get key error: not a string",
}, },
{ {
@@ -174,8 +162,8 @@ func TestBadKvGet(t *testing.T) {
"module": "test", "module": "test",
"key": "test", "key": "test",
}, },
wrappedPayloadCtx: t.Context(), wrappedPayloadModules: nil,
errorString: "kv.get wrapped payload has no modules", errorString: "kv.get wrapped payload has no modules",
}, },
{ {
name: "module not found in context", name: "module not found in context",
@@ -184,8 +172,8 @@ func TestBadKvGet(t *testing.T) {
"module": "test", "module": "test",
"key": "test", "key": "test",
}, },
wrappedPayloadCtx: test.GetContextWithModules(t.Context(), map[string]common.Module{}), wrappedPayloadModules: map[string]common.Module{},
errorString: "kv.get unable to find module with id: test", errorString: "kv.get unable to find module with id: test",
}, },
{ {
name: "module not a kv module", name: "module not a kv module",
@@ -194,9 +182,9 @@ func TestBadKvGet(t *testing.T) {
"module": "test", "module": "test",
"key": "test", "key": "test",
}, },
wrappedPayloadCtx: test.GetContextWithModules(t.Context(), map[string]common.Module{ wrappedPayloadModules: map[string]common.Module{
"test": test.NewTestDBModule("test"), "test": test.NewTestDBModule("test"),
}), },
errorString: "kv.get module with id test is not a KeyValueModule", errorString: "kv.get module with id test is not a KeyValueModule",
}, },
} }
@@ -221,7 +209,7 @@ func TestBadKvGet(t *testing.T) {
return return
} }
got, err := processorInstance.Process(t.Context(), common.GetWrappedPayload(test.wrappedPayloadCtx, test.payload)) got, err := processorInstance.Process(t.Context(), common.WrappedPayload{Modules: test.wrappedPayloadModules, Payload: test.payload})
if err == nil { if err == nil {
t.Fatalf("kv.get expected to fail but got payload: %+v", got) t.Fatalf("kv.get expected to fail but got payload: %+v", got)
@@ -233,3 +221,32 @@ func TestBadKvGet(t *testing.T) {
}) })
} }
} }
func BenchmarkKvGet(b *testing.B) {
registration, ok := processor.ProcessorRegistry["kv.get"]
if !ok {
b.Fatalf("kv.get processor not registered")
}
processorInstance, err := registration.New(config.ProcessorConfig{
Type: "kv.get",
Params: map[string]any{
"module": "test",
"key": "test",
},
})
if err != nil {
b.Fatalf("kv.get failed to create processor: %s", err)
}
modules := map[string]common.Module{
"test": test.NewTestKVModule("test"),
}
for b.Loop() {
_, err := processorInstance.Process(b.Context(), common.WrappedPayload{Payload: nil, Modules: modules})
if err != nil {
b.Fatalf("kv.get processing failed: %s", err)
}
}
}
+68 -37
View File
@@ -1,7 +1,6 @@
package processor_test package processor_test
import ( import (
"context"
"reflect" "reflect"
"testing" "testing"
@@ -36,12 +35,12 @@ func TestKvSetFromRegistry(t *testing.T) {
payload := "" payload := ""
expected := "" expected := ""
got, err := processorInstance.Process(t.Context(), common.GetWrappedPayload(test.GetContextWithModules( got, err := processorInstance.Process(t.Context(), common.WrappedPayload{
t.Context(), Modules: map[string]common.Module{
map[string]common.Module{
"test": &test.TestKVModule{}, "test": &test.TestKVModule{},
}, },
), payload)) Payload: payload,
})
if err != nil { if err != nil {
t.Fatalf("kv.set processing failed: %s", err) t.Fatalf("kv.set processing failed: %s", err)
} }
@@ -86,12 +85,12 @@ func TestGoodKvSet(t *testing.T) {
t.Fatalf("kv.set failed to create processor: %s", err) t.Fatalf("kv.set failed to create processor: %s", err)
} }
got, err := processorInstance.Process(t.Context(), common.GetWrappedPayload(test.GetContextWithModules( got, err := processorInstance.Process(t.Context(), common.WrappedPayload{
t.Context(), Modules: map[string]common.Module{
map[string]common.Module{
"test": &test.TestKVModule{}, "test": &test.TestKVModule{},
}, },
), testCase.payload)) Payload: testCase.payload,
})
if err != nil { if err != nil {
t.Fatalf("kv.set processing failed: %s", err) t.Fatalf("kv.set processing failed: %s", err)
@@ -106,11 +105,11 @@ func TestGoodKvSet(t *testing.T) {
func TestBadKvSet(t *testing.T) { func TestBadKvSet(t *testing.T) {
testCases := []struct { testCases := []struct {
name string name string
params map[string]any params map[string]any
payload any payload any
wrappedPayloadCtx context.Context wrappedPayloadModules map[string]common.Module
errorString string errorString string
}{ }{
{ {
name: "no module param", name: "no module param",
@@ -119,9 +118,9 @@ func TestBadKvSet(t *testing.T) {
"key": "test", "key": "test",
"value": "test", "value": "test",
}, },
wrappedPayloadCtx: test.GetContextWithModules(t.Context(), map[string]common.Module{ wrappedPayloadModules: map[string]common.Module{
"test": &test.TestKVModule{}, "test": &test.TestKVModule{},
}), },
errorString: "kv.set module error: not found", errorString: "kv.set module error: not found",
}, },
{ {
@@ -132,9 +131,9 @@ func TestBadKvSet(t *testing.T) {
"key": "test", "key": "test",
"value": "test", "value": "test",
}, },
wrappedPayloadCtx: test.GetContextWithModules(t.Context(), map[string]common.Module{ wrappedPayloadModules: map[string]common.Module{
"test": &test.TestKVModule{}, "test": &test.TestKVModule{},
}), },
errorString: "kv.set module error: not a string", errorString: "kv.set module error: not a string",
}, },
{ {
@@ -144,9 +143,9 @@ func TestBadKvSet(t *testing.T) {
"module": "test", "module": "test",
"value": "test", "value": "test",
}, },
wrappedPayloadCtx: test.GetContextWithModules(t.Context(), map[string]common.Module{ wrappedPayloadModules: map[string]common.Module{
"test": &test.TestKVModule{}, "test": &test.TestKVModule{},
}), },
errorString: "kv.set key error: not found", errorString: "kv.set key error: not found",
}, },
{ {
@@ -157,9 +156,9 @@ func TestBadKvSet(t *testing.T) {
"key": 1, "key": 1,
"value": "test", "value": "test",
}, },
wrappedPayloadCtx: test.GetContextWithModules(t.Context(), map[string]common.Module{ wrappedPayloadModules: map[string]common.Module{
"test": &test.TestKVModule{}, "test": &test.TestKVModule{},
}), },
errorString: "kv.set key error: not a string", errorString: "kv.set key error: not a string",
}, },
{ {
@@ -169,9 +168,9 @@ func TestBadKvSet(t *testing.T) {
"module": "test", "module": "test",
"key": "test", "key": "test",
}, },
wrappedPayloadCtx: test.GetContextWithModules(t.Context(), map[string]common.Module{ wrappedPayloadModules: map[string]common.Module{
"test": &test.TestKVModule{}, "test": &test.TestKVModule{},
}), },
errorString: "kv.set value error: not found", errorString: "kv.set value error: not found",
}, },
{ {
@@ -182,9 +181,9 @@ func TestBadKvSet(t *testing.T) {
"key": "test", "key": "test",
"value": 1, "value": 1,
}, },
wrappedPayloadCtx: test.GetContextWithModules(t.Context(), map[string]common.Module{ wrappedPayloadModules: map[string]common.Module{
"test": &test.TestKVModule{}, "test": &test.TestKVModule{},
}), },
errorString: "kv.set value error: not a string", errorString: "kv.set value error: not a string",
}, },
{ {
@@ -195,8 +194,8 @@ func TestBadKvSet(t *testing.T) {
"key": "test", "key": "test",
"value": "hello", "value": "hello",
}, },
wrappedPayloadCtx: t.Context(), wrappedPayloadModules: nil,
errorString: "kv.set wrapped payload has no modules", errorString: "kv.set wrapped payload has no modules",
}, },
{ {
name: "value template syntax error", name: "value template syntax error",
@@ -206,9 +205,9 @@ func TestBadKvSet(t *testing.T) {
"key": "test", "key": "test",
"value": "{{", "value": "{{",
}, },
wrappedPayloadCtx: test.GetContextWithModules(t.Context(), map[string]common.Module{ wrappedPayloadModules: map[string]common.Module{
"test": &test.TestKVModule{}, "test": &test.TestKVModule{},
}), },
errorString: "template: template:1: unclosed action", errorString: "template: template:1: unclosed action",
}, },
{ {
@@ -219,9 +218,9 @@ func TestBadKvSet(t *testing.T) {
"key": "test", "key": "test",
"value": "{{.Data}}", "value": "{{.Data}}",
}, },
wrappedPayloadCtx: test.GetContextWithModules(t.Context(), map[string]common.Module{ wrappedPayloadModules: map[string]common.Module{
"test": &test.TestKVModule{}, "test": &test.TestKVModule{},
}), },
errorString: "template: template:1:2: executing \"template\" at <.Data>: can't evaluate field Data in type common.WrappedPayload", errorString: "template: template:1:2: executing \"template\" at <.Data>: can't evaluate field Data in type common.WrappedPayload",
}, },
{ {
@@ -232,8 +231,8 @@ func TestBadKvSet(t *testing.T) {
"key": "test", "key": "test",
"value": "hello", "value": "hello",
}, },
wrappedPayloadCtx: test.GetContextWithModules(t.Context(), map[string]common.Module{}), wrappedPayloadModules: map[string]common.Module{},
errorString: "kv.set unable to find module with id: test", errorString: "kv.set unable to find module with id: test",
}, },
{ {
name: "module not a kv module", name: "module not a kv module",
@@ -243,9 +242,9 @@ func TestBadKvSet(t *testing.T) {
"key": "test", "key": "test",
"value": "hello", "value": "hello",
}, },
wrappedPayloadCtx: test.GetContextWithModules(t.Context(), map[string]common.Module{ wrappedPayloadModules: map[string]common.Module{
"test": test.NewTestDBModule("test"), "test": test.NewTestDBModule("test"),
}), },
errorString: "kv.set module with id test is not a KeyValueModule", errorString: "kv.set module with id test is not a KeyValueModule",
}, },
} }
@@ -270,7 +269,7 @@ func TestBadKvSet(t *testing.T) {
return return
} }
got, err := processorInstance.Process(t.Context(), common.GetWrappedPayload(testCase.wrappedPayloadCtx, testCase.payload)) got, err := processorInstance.Process(t.Context(), common.WrappedPayload{Modules: testCase.wrappedPayloadModules, Payload: testCase.payload})
if err == nil { if err == nil {
t.Fatalf("kv.set expected to fail but got payload: %+v", got) t.Fatalf("kv.set expected to fail but got payload: %+v", got)
@@ -282,3 +281,35 @@ func TestBadKvSet(t *testing.T) {
}) })
} }
} }
func BenchmarkKvSet(b *testing.B) {
registration, ok := processor.ProcessorRegistry["kv.set"]
if !ok {
b.Fatalf("kv.set processor not registered")
}
processorInstance, err := registration.New(config.ProcessorConfig{
Type: "kv.set",
Params: map[string]any{
"module": "test",
"key": "test",
"value": "{{.Payload}}",
},
})
if err != nil {
b.Fatalf("kv.set failed to create processor: %s", err)
}
modules := map[string]common.Module{
"test": test.NewTestKVModule("test"),
}
count := 0
for b.Loop() {
_, err := processorInstance.Process(b.Context(), common.WrappedPayload{Payload: count, Modules: modules})
if err != nil {
b.Fatalf("kv.set processing failed: %s", err)
}
count++
}
}
@@ -71,7 +71,7 @@ func TestGoodMIDIControlChangeCreate(t *testing.T) {
t.Fatalf("midi.control_change.create failed to create processor: %s", err) t.Fatalf("midi.control_change.create failed to create processor: %s", err)
} }
got, err := processorInstance.Process(t.Context(), common.GetWrappedPayload(t.Context(), test.payload)) got, err := processorInstance.Process(t.Context(), common.WrappedPayload{Payload: test.payload})
if err != nil { if err != nil {
t.Fatalf("midi.control_change.create processing failed: %s", err) t.Fatalf("midi.control_change.create processing failed: %s", err)
} }
@@ -147,7 +147,7 @@ func TestBadMIDIControlChangeCreate(t *testing.T) {
return return
} }
got, err := processorInstance.Process(t.Context(), common.GetWrappedPayload(t.Context(), test.payload)) got, err := processorInstance.Process(t.Context(), common.WrappedPayload{Payload: test.payload})
if err == nil { if err == nil {
t.Fatalf("midi.control_change.create expected to fail but succeeded, got: %v", got) t.Fatalf("midi.control_change.create expected to fail but succeeded, got: %v", got)
@@ -159,3 +159,32 @@ func TestBadMIDIControlChangeCreate(t *testing.T) {
}) })
} }
} }
func BenchmarkMIDIControlChangeCreate(b *testing.B) {
registration, ok := processor.ProcessorRegistry["midi.control_change.create"]
if !ok {
b.Fatalf("midi.control_change.create processor not registered")
}
processorInstance, err := registration.New(config.ProcessorConfig{
Type: "midi.control_change.create",
Params: map[string]any{
"channel": "1",
"control": "64",
"value": "127",
},
})
if err != nil {
b.Fatalf("midi.control_change.create failed to create processor: %s", err)
}
count := 0
for b.Loop() {
_, err := processorInstance.Process(b.Context(), common.WrappedPayload{Payload: count})
if err != nil {
b.Fatalf("midi.control_change.create processing failed: %s", err)
}
count++
}
}
@@ -45,7 +45,7 @@ func TestGoodMIDIMessageDecode(t *testing.T) {
for _, test := range tests { for _, test := range tests {
t.Run(test.name, func(t *testing.T) { t.Run(test.name, func(t *testing.T) {
got, err := processorInstance.Process(t.Context(), common.GetWrappedPayload(t.Context(), test.payload)) got, err := processorInstance.Process(t.Context(), common.WrappedPayload{Payload: test.payload})
if err != nil { if err != nil {
t.Fatalf("midi.message.decode processing failed: %s", err) t.Fatalf("midi.message.decode processing failed: %s", err)
} }
@@ -79,7 +79,7 @@ func TestBadMIDIMessageDecode(t *testing.T) {
for _, test := range tests { for _, test := range tests {
t.Run(test.name, func(t *testing.T) { t.Run(test.name, func(t *testing.T) {
got, err := processorInstance.Process(t.Context(), common.GetWrappedPayload(t.Context(), test.payload)) got, err := processorInstance.Process(t.Context(), common.WrappedPayload{Payload: test.payload})
if err == nil { if err == nil {
t.Fatalf("midi.message.decode expected to fail but succeeded, got: %v", got) t.Fatalf("midi.message.decode expected to fail but succeeded, got: %v", got)
@@ -91,3 +91,15 @@ func TestBadMIDIMessageDecode(t *testing.T) {
}) })
} }
} }
func BenchmarkMIDIMessageDecode(b *testing.B) {
processorInstance := processor.MIDIMessageDecode{}
payload := []byte{0x90, 0x40, 0x7F}
for b.Loop() {
_, err := processorInstance.Process(b.Context(), common.WrappedPayload{Payload: payload})
if err != nil {
b.Fatalf("midi.message.decode processing failed: %s", err)
}
}
}
@@ -45,7 +45,7 @@ func TestGoodMIDIMessageEncode(t *testing.T) {
for _, test := range tests { for _, test := range tests {
t.Run(test.name, func(t *testing.T) { t.Run(test.name, func(t *testing.T) {
got, err := midiMessageEncoder.Process(t.Context(), common.GetWrappedPayload(t.Context(), test.payload)) got, err := midiMessageEncoder.Process(t.Context(), common.WrappedPayload{Payload: test.payload})
if err != nil { if err != nil {
t.Fatalf("midi.message.encode processing failed: %s", err) t.Fatalf("midi.message.encode processing failed: %s", err)
} }
@@ -78,7 +78,7 @@ func TestBadMIDIMessageEncode(t *testing.T) {
for _, test := range tests { for _, test := range tests {
t.Run(test.name, func(t *testing.T) { t.Run(test.name, func(t *testing.T) {
got, err := midiMessageEncoder.Process(t.Context(), common.GetWrappedPayload(t.Context(), test.payload)) got, err := midiMessageEncoder.Process(t.Context(), common.WrappedPayload{Payload: test.payload})
if err == nil { if err == nil {
t.Fatalf("midi.message.encode expected to fail but got payload: %+v", got) t.Fatalf("midi.message.encode expected to fail but got payload: %+v", got)
@@ -89,3 +89,15 @@ func TestBadMIDIMessageEncode(t *testing.T) {
}) })
} }
} }
func BenchmarkMIDIMessageEncode(b *testing.B) {
processorInstance := processor.MIDIMessageEncode{}
payload := midi.NoteOn(1, 60, 127)
for b.Loop() {
_, err := processorInstance.Process(b.Context(), common.WrappedPayload{Payload: payload})
if err != nil {
b.Fatalf("midi.message.encode processing failed: %s", err)
}
}
}
@@ -85,7 +85,7 @@ func TestGoodMIDIMessageUnpack(t *testing.T) {
for _, test := range tests { for _, test := range tests {
t.Run(test.name, func(t *testing.T) { t.Run(test.name, func(t *testing.T) {
got, err := processorInstance.Process(t.Context(), common.GetWrappedPayload(t.Context(), test.payload)) got, err := processorInstance.Process(t.Context(), common.WrappedPayload{Payload: test.payload})
if err != nil { if err != nil {
t.Fatalf("midi.message.unpack processing failed: %s", err) t.Fatalf("midi.message.unpack processing failed: %s", err)
} }
@@ -138,7 +138,7 @@ func TestBadMIDIMessageUnpack(t *testing.T) {
return return
} }
got, err := processorInstance.Process(t.Context(), common.GetWrappedPayload(t.Context(), test.payload)) got, err := processorInstance.Process(t.Context(), common.WrappedPayload{Payload: test.payload})
if err == nil { if err == nil {
t.Fatalf("midi.message.unpack expected to fail but succeeded, got: %v", got) t.Fatalf("midi.message.unpack expected to fail but succeeded, got: %v", got)
@@ -150,3 +150,15 @@ func TestBadMIDIMessageUnpack(t *testing.T) {
}) })
} }
} }
func BenchmarkMIDIMessageUnpack(b *testing.B) {
processorInstance := processor.MIDIMessageUnpack{}
payload := midi.NoteOn(1, 60, 127)
for b.Loop() {
_, err := processorInstance.Process(b.Context(), common.WrappedPayload{Payload: payload})
if err != nil {
b.Fatalf("midi.message.unpack processing failed: %s", err)
}
}
}
@@ -70,7 +70,7 @@ func TestGoodMIDINoteOffCretea(t *testing.T) {
t.Fatalf("midi.note_off.create failed to create processor: %s", err) t.Fatalf("midi.note_off.create failed to create processor: %s", err)
} }
got, err := processorInstance.Process(t.Context(), common.GetWrappedPayload(t.Context(), test.payload)) got, err := processorInstance.Process(t.Context(), common.WrappedPayload{Payload: test.payload})
if err != nil { if err != nil {
t.Fatalf("midi.note_off.create processing failed: %s", err) t.Fatalf("midi.note_off.create processing failed: %s", err)
} }
@@ -146,7 +146,7 @@ func TestBadMIDINoteOffCretea(t *testing.T) {
return return
} }
got, err := processorInstance.Process(t.Context(), common.GetWrappedPayload(t.Context(), test.payload)) got, err := processorInstance.Process(t.Context(), common.WrappedPayload{Payload: test.payload})
if err == nil { if err == nil {
t.Fatalf("midi.note_off.create expected to fail but succeeded, got: %v", got) t.Fatalf("midi.note_off.create expected to fail but succeeded, got: %v", got)
@@ -158,3 +158,32 @@ func TestBadMIDINoteOffCretea(t *testing.T) {
}) })
} }
} }
func BenchmarkMIDINoteOffCreate(b *testing.B) {
registration, ok := processor.ProcessorRegistry["midi.note_off.create"]
if !ok {
b.Fatalf("midi.note_off.create processor not registered")
}
processorInstance, err := registration.New(config.ProcessorConfig{
Type: "midi.note_off.create",
Params: map[string]any{
"channel": "1",
"note": "60",
"velocity": "100",
},
})
if err != nil {
b.Fatalf("midi.note_off.create failed to create processor: %s", err)
}
count := 0
for b.Loop() {
_, err := processorInstance.Process(b.Context(), common.WrappedPayload{Payload: count})
if err != nil {
b.Fatalf("midi.note_off.create processing failed: %s", err)
}
count++
}
}
@@ -70,7 +70,7 @@ func TestGoodMIDINoteOnCreate(t *testing.T) {
t.Fatalf("midi.note_on.create failed to create processor: %s", err) t.Fatalf("midi.note_on.create failed to create processor: %s", err)
} }
got, err := processorInstance.Process(t.Context(), common.GetWrappedPayload(t.Context(), test.payload)) got, err := processorInstance.Process(t.Context(), common.WrappedPayload{Payload: test.payload})
if err != nil { if err != nil {
t.Fatalf("midi.note_on.create processing failed: %s", err) t.Fatalf("midi.note_on.create processing failed: %s", err)
} }
@@ -143,7 +143,7 @@ func TestBadMIDINoteOnCreate(t *testing.T) {
return return
} }
got, err := processorInstance.Process(t.Context(), common.GetWrappedPayload(t.Context(), test.payload)) got, err := processorInstance.Process(t.Context(), common.WrappedPayload{Payload: test.payload})
if err == nil { if err == nil {
t.Fatalf("midi.note_on.create expected to fail but succeeded, got: %v", got) t.Fatalf("midi.note_on.create expected to fail but succeeded, got: %v", got)
@@ -155,3 +155,32 @@ func TestBadMIDINoteOnCreate(t *testing.T) {
}) })
} }
} }
func BenchmarkMIDINoteOnCreate(b *testing.B) {
registration, ok := processor.ProcessorRegistry["midi.note_on.create"]
if !ok {
b.Fatalf("midi.note_on.create processor not registered")
}
processorInstance, err := registration.New(config.ProcessorConfig{
Type: "midi.note_on.create",
Params: map[string]any{
"channel": "1",
"note": "60",
"velocity": "100",
},
})
if err != nil {
b.Fatalf("midi.note_on.create failed to create processor: %s", err)
}
count := 0
for b.Loop() {
_, err := processorInstance.Process(b.Context(), common.WrappedPayload{Payload: count})
if err != nil {
b.Fatalf("midi.note_off.create processing failed: %s", err)
}
count++
}
}
@@ -69,7 +69,7 @@ func TestGoodMIDIProgramChangeCreate(t *testing.T) {
t.Fatalf("midi.program_change.create failed to create processor: %s", err) t.Fatalf("midi.program_change.create failed to create processor: %s", err)
} }
got, err := processorInstance.Process(t.Context(), common.GetWrappedPayload(t.Context(), test.payload)) got, err := processorInstance.Process(t.Context(), common.WrappedPayload{Payload: test.payload})
if err != nil { if err != nil {
t.Fatalf("midi.program_change.create processing failed: %s", err) t.Fatalf("midi.program_change.create processing failed: %s", err)
} }
@@ -133,7 +133,7 @@ func TestBadMIDIProgramChangeCreate(t *testing.T) {
return return
} }
got, err := processorInstance.Process(t.Context(), common.GetWrappedPayload(t.Context(), test.payload)) got, err := processorInstance.Process(t.Context(), common.WrappedPayload{Payload: test.payload})
if err == nil { if err == nil {
t.Fatalf("midi.program_change.create expected to fail but succeeded, got: %v", got) t.Fatalf("midi.program_change.create expected to fail but succeeded, got: %v", got)
@@ -145,3 +145,31 @@ func TestBadMIDIProgramChangeCreate(t *testing.T) {
}) })
} }
} }
func BenchmarkMIDIProgramChangeCreate(b *testing.B) {
registration, ok := processor.ProcessorRegistry["midi.program_change.create"]
if !ok {
b.Fatalf("midi.program_change.create processor not registered")
}
processorInstance, err := registration.New(config.ProcessorConfig{
Type: "midi.program_change.create",
Params: map[string]any{
"channel": "1",
"program": "60",
},
})
if err != nil {
b.Fatalf("midi.program_change.create failed to create processor: %s", err)
}
count := 0
for b.Loop() {
_, err := processorInstance.Process(b.Context(), common.WrappedPayload{Payload: count})
if err != nil {
b.Fatalf("midi.program_change.create processing failed: %s", err)
}
count++
}
}
@@ -104,7 +104,7 @@ func TestGoodMQTTMessageCreate(t *testing.T) {
t.Fatalf("mqtt.message.create failed to create processor: %s", err) t.Fatalf("mqtt.message.create failed to create processor: %s", err)
} }
got, err := processorInstance.Process(t.Context(), common.GetWrappedPayload(t.Context(), test.payload)) got, err := processorInstance.Process(t.Context(), common.WrappedPayload{Payload: test.payload})
if err != nil { if err != nil {
t.Fatalf("mqtt.message.create processing failed: %s", err) t.Fatalf("mqtt.message.create processing failed: %s", err)
@@ -228,7 +228,7 @@ func TestBadMQTTMessageCreate(t *testing.T) {
return return
} }
got, err := processorInstance.Process(t.Context(), common.GetWrappedPayload(t.Context(), test.payload)) got, err := processorInstance.Process(t.Context(), common.WrappedPayload{Payload: test.payload})
if err == nil { if err == nil {
t.Fatalf("mqtt.message.create expected to fail but succeeded, got: %v", got) t.Fatalf("mqtt.message.create expected to fail but succeeded, got: %v", got)
@@ -240,3 +240,33 @@ func TestBadMQTTMessageCreate(t *testing.T) {
}) })
} }
} }
func BenchmarkMQTTMessageCreate(b *testing.B) {
registration, ok := processor.ProcessorRegistry["mqtt.message.create"]
if !ok {
b.Fatalf("mqtt.message.create processor not registered")
}
processorInstance, err := registration.New(config.ProcessorConfig{
Type: "mqtt.message.create",
Params: map[string]any{
"topic": "test/topic",
"qos": 1,
"retained": true,
"payload": "{{.Payload}}",
},
})
if err != nil {
b.Fatalf("mqtt.message.create failed to create processor: %s", err)
}
count := 0
for b.Loop() {
_, err := processorInstance.Process(b.Context(), common.WrappedPayload{Payload: count})
if err != nil {
b.Fatalf("mqtt.message.create processing failed: %s", err)
}
count++
}
}
@@ -85,7 +85,7 @@ func TestGoodNATSMessageCreate(t *testing.T) {
t.Fatalf("nats.message.create failed to create processor: %s", err) t.Fatalf("nats.message.create failed to create processor: %s", err)
} }
got, err := processorInstance.Process(t.Context(), common.GetWrappedPayload(t.Context(), test.payload)) got, err := processorInstance.Process(t.Context(), common.WrappedPayload{Payload: test.payload})
if err != nil { if err != nil {
t.Fatalf("nats.message.create processing failed: %s", err) t.Fatalf("nats.message.create processing failed: %s", err)
} }
@@ -196,7 +196,7 @@ func TestBadNATSMessageCreate(t *testing.T) {
return return
} }
got, err := processorInstance.Process(t.Context(), common.GetWrappedPayload(t.Context(), test.payload)) got, err := processorInstance.Process(t.Context(), common.WrappedPayload{Payload: test.payload})
if err == nil { if err == nil {
t.Fatalf("nats.message.create expected to fail but succeeded, got: %v", got) t.Fatalf("nats.message.create expected to fail but succeeded, got: %v", got)
@@ -208,3 +208,31 @@ func TestBadNATSMessageCreate(t *testing.T) {
}) })
} }
} }
func BenchmarkNATSMessageCreate(b *testing.B) {
registration, ok := processor.ProcessorRegistry["nats.message.create"]
if !ok {
b.Fatalf("nats.message.create processor not registered")
}
processorInstance, err := registration.New(config.ProcessorConfig{
Type: "nats.message.create",
Params: map[string]any{
"subject": "test.subject",
"payload": "{{.Payload}}",
},
})
if err != nil {
b.Fatalf("nats.message.create failed to create processor: %s", err)
}
count := 0
for b.Loop() {
_, err := processorInstance.Process(b.Context(), common.WrappedPayload{Payload: count})
if err != nil {
b.Fatalf("nats.message.create processing failed: %s", err)
}
count++
}
}
@@ -59,7 +59,7 @@ func TestGoodOSCMessageCreate(t *testing.T) {
name: "address with template and string arg", name: "address with template and string arg",
params: map[string]any{ params: map[string]any{
"address": "/test/{{.Payload.Value}}", "address": "/test/{{.Payload.Value}}",
"args": []interface{}{"arg1"}, "args": []any{"arg1"},
"types": "s", "types": "s",
}, },
payload: map[string]any{"Value": "value"}, payload: map[string]any{"Value": "value"},
@@ -69,7 +69,7 @@ func TestGoodOSCMessageCreate(t *testing.T) {
name: "address with template and mixed args", name: "address with template and mixed args",
params: map[string]any{ params: map[string]any{
"address": "/test/{{.Payload.Value}}", "address": "/test/{{.Payload.Value}}",
"args": []interface{}{"arg1", "42", "3.14"}, "args": []any{"arg1", "42", "3.14"},
"types": "sif", "types": "sif",
}, },
payload: map[string]any{"Value": "value"}, payload: map[string]any{"Value": "value"},
@@ -86,7 +86,7 @@ func TestGoodOSCMessageCreate(t *testing.T) {
name: "address with template and int64 arg", name: "address with template and int64 arg",
params: map[string]any{ params: map[string]any{
"address": "/test/{{.Payload.Value}}", "address": "/test/{{.Payload.Value}}",
"args": []interface{}{"42"}, "args": []any{"42"},
"types": "h", "types": "h",
}, },
payload: map[string]any{"Value": "value"}, payload: map[string]any{"Value": "value"},
@@ -96,7 +96,7 @@ func TestGoodOSCMessageCreate(t *testing.T) {
name: "address with template and double arg", name: "address with template and double arg",
params: map[string]any{ params: map[string]any{
"address": "/test/{{.Payload.Value}}", "address": "/test/{{.Payload.Value}}",
"args": []interface{}{"42"}, "args": []any{"42"},
"types": "d", "types": "d",
}, },
payload: map[string]any{"Value": "value"}, payload: map[string]any{"Value": "value"},
@@ -106,7 +106,7 @@ func TestGoodOSCMessageCreate(t *testing.T) {
name: "address with template and true arg", name: "address with template and true arg",
params: map[string]any{ params: map[string]any{
"address": "/test/{{.Payload.Value}}", "address": "/test/{{.Payload.Value}}",
"args": []interface{}{""}, "args": []any{""},
"types": "T", "types": "T",
}, },
payload: map[string]any{"Value": "value"}, payload: map[string]any{"Value": "value"},
@@ -116,7 +116,7 @@ func TestGoodOSCMessageCreate(t *testing.T) {
name: "address with template and false arg", name: "address with template and false arg",
params: map[string]any{ params: map[string]any{
"address": "/test/{{.Payload.Value}}", "address": "/test/{{.Payload.Value}}",
"args": []interface{}{""}, "args": []any{""},
"types": "F", "types": "F",
}, },
payload: map[string]any{"Value": "value"}, payload: map[string]any{"Value": "value"},
@@ -126,7 +126,7 @@ func TestGoodOSCMessageCreate(t *testing.T) {
name: "address with template and nil arg", name: "address with template and nil arg",
params: map[string]any{ params: map[string]any{
"address": "/test/{{.Payload.Value}}", "address": "/test/{{.Payload.Value}}",
"args": []interface{}{""}, "args": []any{""},
"types": "N", "types": "N",
}, },
payload: map[string]any{"Value": "value"}, payload: map[string]any{"Value": "value"},
@@ -136,7 +136,7 @@ func TestGoodOSCMessageCreate(t *testing.T) {
name: "blob arg", name: "blob arg",
params: map[string]any{ params: map[string]any{
"address": "/test", "address": "/test",
"args": []interface{}{"deadbeef"}, "args": []any{"deadbeef"},
"types": "b", "types": "b",
}, },
payload: "", payload: "",
@@ -160,7 +160,7 @@ func TestGoodOSCMessageCreate(t *testing.T) {
t.Fatalf("osc.message.create failed to create processor: %s", err) t.Fatalf("osc.message.create failed to create processor: %s", err)
} }
got, err := processorInstance.Process(t.Context(), common.GetWrappedPayload(t.Context(), test.payload)) got, err := processorInstance.Process(t.Context(), common.WrappedPayload{Payload: test.payload})
if err != nil { if err != nil {
t.Fatalf("osc.message.create processing failed: %s", err) t.Fatalf("osc.message.create processing failed: %s", err)
@@ -228,7 +228,7 @@ func TestBadOSCMessageCreate(t *testing.T) {
name: "args without types parameter", name: "args without types parameter",
params: map[string]any{ params: map[string]any{
"address": "/test", "address": "/test",
"args": []interface{}{"arg1"}, "args": []any{"arg1"},
}, },
payload: "test", payload: "test",
errorString: "osc.message.create types error: not found", errorString: "osc.message.create types error: not found",
@@ -237,7 +237,7 @@ func TestBadOSCMessageCreate(t *testing.T) {
name: "args and types length mismatch", name: "args and types length mismatch",
params: map[string]any{ params: map[string]any{
"address": "/test", "address": "/test",
"args": []interface{}{"arg1", "arg2"}, "args": []any{"arg1", "arg2"},
"types": "s", "types": "s",
}, },
payload: "test", payload: "test",
@@ -247,7 +247,7 @@ func TestBadOSCMessageCreate(t *testing.T) {
name: "non-string arg", name: "non-string arg",
params: map[string]any{ params: map[string]any{
"address": "/test", "address": "/test",
"args": []interface{}{"arg1", 123}, "args": []any{"arg1", 123},
"types": "ss", "types": "ss",
}, },
payload: "test", payload: "test",
@@ -257,7 +257,7 @@ func TestBadOSCMessageCreate(t *testing.T) {
name: "bad arg template", name: "bad arg template",
params: map[string]any{ params: map[string]any{
"address": "/test", "address": "/test",
"args": []interface{}{"{{"}, "args": []any{"{{"},
"types": "s", "types": "s",
}, },
payload: "test", payload: "test",
@@ -267,7 +267,7 @@ func TestBadOSCMessageCreate(t *testing.T) {
name: "non-string types parameter", name: "non-string types parameter",
params: map[string]any{ params: map[string]any{
"address": "/test", "address": "/test",
"args": []interface{}{"arg1"}, "args": []any{"arg1"},
"types": 123, "types": 123,
}, },
payload: "test", payload: "test",
@@ -277,7 +277,7 @@ func TestBadOSCMessageCreate(t *testing.T) {
name: "invalid type in types parameter", name: "invalid type in types parameter",
params: map[string]any{ params: map[string]any{
"address": "/test", "address": "/test",
"args": []interface{}{"arg1"}, "args": []any{"arg1"},
"types": "x", "types": "x",
}, },
payload: "test", payload: "test",
@@ -311,7 +311,7 @@ func TestBadOSCMessageCreate(t *testing.T) {
name: "address template with missing field", name: "address template with missing field",
params: map[string]any{ params: map[string]any{
"address": "/test", "address": "/test",
"args": []interface{}{"{{.missing}}"}, "args": []any{"{{.missing}}"},
"types": "s", "types": "s",
}, },
payload: "test", payload: "test",
@@ -321,7 +321,7 @@ func TestBadOSCMessageCreate(t *testing.T) {
name: "wrong arg type for int arg", name: "wrong arg type for int arg",
params: map[string]any{ params: map[string]any{
"address": "/test", "address": "/test",
"args": []interface{}{"{{.Payload}}"}, "args": []any{"{{.Payload}}"},
"types": "i", "types": "i",
}, },
payload: "test", payload: "test",
@@ -331,7 +331,7 @@ func TestBadOSCMessageCreate(t *testing.T) {
name: "wrong arg type for float arg", name: "wrong arg type for float arg",
params: map[string]any{ params: map[string]any{
"address": "/test", "address": "/test",
"args": []interface{}{"{{.Payload}}"}, "args": []any{"{{.Payload}}"},
"types": "f", "types": "f",
}, },
payload: "test", payload: "test",
@@ -341,7 +341,7 @@ func TestBadOSCMessageCreate(t *testing.T) {
name: "wrong arg type for blob arg", name: "wrong arg type for blob arg",
params: map[string]any{ params: map[string]any{
"address": "/test", "address": "/test",
"args": []interface{}{"{{.Payload}}"}, "args": []any{"{{.Payload}}"},
"types": "b", "types": "b",
}, },
payload: "test", payload: "test",
@@ -351,7 +351,7 @@ func TestBadOSCMessageCreate(t *testing.T) {
name: "wrong arg type for int64 arg", name: "wrong arg type for int64 arg",
params: map[string]any{ params: map[string]any{
"address": "/test", "address": "/test",
"args": []interface{}{"{{.Payload}}"}, "args": []any{"{{.Payload}}"},
"types": "h", "types": "h",
}, },
payload: "test", payload: "test",
@@ -361,7 +361,7 @@ func TestBadOSCMessageCreate(t *testing.T) {
name: "wrong arg type for double arg", name: "wrong arg type for double arg",
params: map[string]any{ params: map[string]any{
"address": "/test", "address": "/test",
"args": []interface{}{"{{.Payload}}"}, "args": []any{"{{.Payload}}"},
"types": "d", "types": "d",
}, },
payload: "test", payload: "test",
@@ -388,7 +388,7 @@ func TestBadOSCMessageCreate(t *testing.T) {
return return
} }
got, err := processorInstance.Process(t.Context(), common.GetWrappedPayload(t.Context(), test.payload)) got, err := processorInstance.Process(t.Context(), common.WrappedPayload{Payload: test.payload})
if err == nil { if err == nil {
t.Fatalf("osc.message.create expected to fail but succeeded, got: %v", got) t.Fatalf("osc.message.create expected to fail but succeeded, got: %v", got)
@@ -400,3 +400,32 @@ func TestBadOSCMessageCreate(t *testing.T) {
}) })
} }
} }
func BenchmarkOSCMessageCreate(b *testing.B) {
registration, ok := processor.ProcessorRegistry["osc.message.create"]
if !ok {
b.Fatalf("osc.message.create processor not registered")
}
processorInstance, err := registration.New(config.ProcessorConfig{
Type: "osc.message.create",
Params: map[string]any{
"address": "/hello",
"args": []any{"{{.Payload}}"},
"types": "i",
},
})
if err != nil {
b.Fatalf("osc.message.create failed to create processor: %s", err)
}
count := 0
for b.Loop() {
_, err := processorInstance.Process(b.Context(), common.WrappedPayload{Payload: count})
if err != nil {
b.Fatalf("osc.message.create processing failed: %s", err)
}
count++
}
}
@@ -61,7 +61,7 @@ func TestGoodOSCMessageDecode(t *testing.T) {
for _, test := range tests { for _, test := range tests {
t.Run(test.name, func(t *testing.T) { t.Run(test.name, func(t *testing.T) {
got, err := processorInstance.Process(t.Context(), common.GetWrappedPayload(t.Context(), test.payload)) got, err := processorInstance.Process(t.Context(), common.WrappedPayload{Payload: test.payload})
if err != nil { if err != nil {
t.Fatalf("osc.message.decode processing failed: %s", err) t.Fatalf("osc.message.decode processing failed: %s", err)
@@ -110,7 +110,7 @@ func TestBadOSCMessageDecode(t *testing.T) {
for _, test := range tests { for _, test := range tests {
t.Run(test.name, func(t *testing.T) { t.Run(test.name, func(t *testing.T) {
got, err := processorInstance.Process(t.Context(), common.GetWrappedPayload(t.Context(), test.payload)) got, err := processorInstance.Process(t.Context(), common.WrappedPayload{Payload: test.payload})
if err == nil { if err == nil {
t.Fatalf("osc.message.decode expected to fail but got payload: %+v", got) t.Fatalf("osc.message.decode expected to fail but got payload: %+v", got)
@@ -121,3 +121,15 @@ func TestBadOSCMessageDecode(t *testing.T) {
}) })
} }
} }
func BenchmarkOSCMessageDecode(b *testing.B) {
processorInstance := processor.OSCMessageDecode{}
payload := []byte{47, 116, 101, 115, 116, 0, 0, 0, 44, 105, 0, 0, 0, 0, 0, 42}
for b.Loop() {
_, err := processorInstance.Process(b.Context(), common.WrappedPayload{Payload: payload})
if err != nil {
b.Fatalf("osc.message.decode processing failed: %s", err)
}
}
}
@@ -60,7 +60,7 @@ func TestGoodOSCMessageEncode(t *testing.T) {
for _, test := range tests { for _, test := range tests {
t.Run(test.name, func(t *testing.T) { t.Run(test.name, func(t *testing.T) {
got, err := processorInstance.Process(t.Context(), common.GetWrappedPayload(t.Context(), test.payload)) got, err := processorInstance.Process(t.Context(), common.WrappedPayload{Payload: test.payload})
if err != nil { if err != nil {
t.Fatalf("osc.message.encode processing failed: %s", err) t.Fatalf("osc.message.encode processing failed: %s", err)
} }
@@ -101,7 +101,7 @@ func TestBadOSCMessageEncode(t *testing.T) {
for _, test := range tests { for _, test := range tests {
t.Run(test.name, func(t *testing.T) { t.Run(test.name, func(t *testing.T) {
got, err := processorInstance.Process(t.Context(), common.GetWrappedPayload(t.Context(), test.payload)) got, err := processorInstance.Process(t.Context(), common.WrappedPayload{Payload: test.payload})
if err == nil { if err == nil {
t.Fatalf("osc.message.encode expected to fail but got payload: %+v", got) t.Fatalf("osc.message.encode expected to fail but got payload: %+v", got)
@@ -112,3 +112,23 @@ func TestBadOSCMessageEncode(t *testing.T) {
}) })
} }
} }
func BenchmarkOSCMessageEncode(b *testing.B) {
processorInstance := processor.OSCMessageEncode{}
payload := &osc.OSCMessage{
Address: "/test",
Args: []osc.OSCArg{
{
Type: "i",
Value: int32(42),
},
},
}
for b.Loop() {
_, err := processorInstance.Process(b.Context(), common.WrappedPayload{Payload: payload})
if err != nil {
b.Fatalf("osc.message.encode processing failed: %s", err)
}
}
}
+23 -24
View File
@@ -1,7 +1,6 @@
package processor_test package processor_test
import ( import (
"context"
"reflect" "reflect"
"testing" "testing"
@@ -35,7 +34,10 @@ func TestRouterOutputFromRegistry(t *testing.T) {
payload := "test" payload := "test"
expected := "test" expected := "test"
got, err := processorInstance.Process(test.GetContextWithRouter(t.Context()), common.GetWrappedPayload(t.Context(), payload)) got, err := processorInstance.Process(t.Context(), common.WrappedPayload{
Router: test.GetNewTestRouter(),
Payload: payload,
})
if err != nil { if err != nil {
t.Fatalf("router.output processing failed: %s", err) t.Fatalf("router.output processing failed: %s", err)
} }
@@ -71,7 +73,7 @@ func TestGoodRouterOutput(t *testing.T) {
t.Fatalf("router.output failed to create processor: %s", err) t.Fatalf("router.output failed to create processor: %s", err)
} }
got, err := processorInstance.Process(t.Context(), common.GetWrappedPayload(test.GetContextWithRouter(t.Context()), testCase.payload)) got, err := processorInstance.Process(t.Context(), common.WrappedPayload{Payload: testCase.payload})
if err != nil { if err != nil {
t.Fatalf("router.output processing failed: %s", err) t.Fatalf("router.output processing failed: %s", err)
} }
@@ -85,40 +87,37 @@ func TestGoodRouterOutput(t *testing.T) {
func TestBadRouterOutput(t *testing.T) { func TestBadRouterOutput(t *testing.T) {
testCases := []struct { testCases := []struct {
name string name string
params map[string]any params map[string]any
payload any payload any
processCtx context.Context router common.RouteIO
wrappedPayloadCtx context.Context errorString string
errorString string
}{ }{
{ {
name: "no module param", name: "no module param",
params: map[string]any{}, params: map[string]any{},
payload: "test", payload: "test",
processCtx: test.GetContextWithRouter(t.Context()), router: test.GetNewTestRouter(),
wrappedPayloadCtx: t.Context(), errorString: "router.output module error: not found",
errorString: "router.output module error: not found",
}, },
{ {
name: "non-string module", name: "non-string module",
params: map[string]any{ params: map[string]any{
"module": 123, "module": 123,
}, },
payload: "test", payload: "test",
processCtx: test.GetContextWithRouter(t.Context()), router: test.GetNewTestRouter(),
wrappedPayloadCtx: t.Context(),
errorString: "router.output module error: not a string", errorString: "router.output module error: not a string",
}, },
{ {
name: "router not found in context", name: "router not found in context",
params: map[string]any{ params: map[string]any{
"module": "test", "module": "test",
}, },
payload: "test", payload: "test",
processCtx: t.Context(), router: nil,
wrappedPayloadCtx: t.Context(), errorString: "router.output no router found",
errorString: "router.output no router found",
}, },
} }
@@ -142,7 +141,7 @@ func TestBadRouterOutput(t *testing.T) {
return return
} }
got, err := processorInstance.Process(testCase.processCtx, common.GetWrappedPayload(testCase.wrappedPayloadCtx, testCase.payload)) got, err := processorInstance.Process(t.Context(), common.WrappedPayload{Router: testCase.router, Payload: testCase.payload})
if err == nil { if err == nil {
t.Fatalf("router.output expected to fail but succeeded, got: %v", got) t.Fatalf("router.output expected to fail but succeeded, got: %v", got)
+22 -24
View File
@@ -1,7 +1,6 @@
package processor_test package processor_test
import ( import (
"context"
"reflect" "reflect"
"testing" "testing"
@@ -35,7 +34,10 @@ func TestRouterInputFromRegistry(t *testing.T) {
payload := "test" payload := "test"
expected := "test" expected := "test"
got, err := processorInstance.Process(test.GetContextWithRouter(t.Context()), common.GetWrappedPayload(t.Context(), payload)) got, err := processorInstance.Process(t.Context(), common.WrappedPayload{
Router: test.GetNewTestRouter(),
Payload: payload,
})
if err != nil { if err != nil {
t.Fatalf("router.input processing failed: %s", err) t.Fatalf("router.input processing failed: %s", err)
} }
@@ -71,7 +73,7 @@ func TestGoodRouterInput(t *testing.T) {
t.Fatalf("router.input failed to create processor: %s", err) t.Fatalf("router.input failed to create processor: %s", err)
} }
got, err := processorInstance.Process(t.Context(), common.GetWrappedPayload(test.GetContextWithRouter(t.Context()), testCase.payload)) got, err := processorInstance.Process(t.Context(), common.WrappedPayload{Payload: testCase.payload})
if err != nil { if err != nil {
t.Fatalf("router.input processing failed: %s", err) t.Fatalf("router.input processing failed: %s", err)
} }
@@ -85,40 +87,36 @@ func TestGoodRouterInput(t *testing.T) {
func TestBadRouterInput(t *testing.T) { func TestBadRouterInput(t *testing.T) {
testCases := []struct { testCases := []struct {
name string name string
params map[string]any params map[string]any
payload any payload any
processCtx context.Context router common.RouteIO
wrappedPayloadCtx context.Context errorString string
errorString string
}{ }{
{ {
name: "no source param", name: "no source param",
params: map[string]any{}, params: map[string]any{},
payload: "test", payload: "test",
processCtx: test.GetContextWithRouter(t.Context()), router: test.GetNewTestRouter(),
wrappedPayloadCtx: t.Context(), errorString: "router.input source error: not found",
errorString: "router.input source error: not found",
}, },
{ {
name: "non-string source", name: "non-string source",
params: map[string]any{ params: map[string]any{
"source": 123, "source": 123,
}, },
payload: "test", payload: "test",
processCtx: test.GetContextWithRouter(t.Context()), router: test.GetNewTestRouter(),
wrappedPayloadCtx: t.Context(), errorString: "router.input source error: not a string",
errorString: "router.input source error: not a string",
}, },
{ {
name: "router not found in context", name: "router not found in context",
params: map[string]any{ params: map[string]any{
"source": "test", "source": "test",
}, },
payload: "test", payload: "test",
processCtx: t.Context(), router: nil,
wrappedPayloadCtx: t.Context(), errorString: "router.input no router found",
errorString: "router.input no router found",
}, },
} }
@@ -142,7 +140,7 @@ func TestBadRouterInput(t *testing.T) {
return return
} }
got, err := processorInstance.Process(testCase.processCtx, common.GetWrappedPayload(testCase.wrappedPayloadCtx, testCase.payload)) got, err := processorInstance.Process(t.Context(), common.WrappedPayload{Router: testCase.router, Payload: testCase.payload})
if err == nil { if err == nil {
t.Fatalf("router.input expected to fail but succeeded, got: %v", got) t.Fatalf("router.input expected to fail but succeeded, got: %v", got)

Some files were not shown because too many files have changed in this diff Show More