mirror of
https://github.com/jwetzell/showbridge-go.git
synced 2026-09-01 03:08:58 +00:00
remove SIP things
This commit is contained in:
@@ -1,109 +0,0 @@
|
||||
package processor
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"fmt"
|
||||
"text/template"
|
||||
|
||||
"github.com/google/jsonschema-go/jsonschema"
|
||||
"github.com/jwetzell/showbridge-go/internal/common"
|
||||
"github.com/jwetzell/showbridge-go/internal/config"
|
||||
)
|
||||
|
||||
func init() {
|
||||
RegisterProcessor(ProcessorRegistration{
|
||||
Type: "sip.response.audio.create",
|
||||
Title: "Create SIP Audio Response",
|
||||
ParamsSchema: &jsonschema.Schema{
|
||||
Type: "object",
|
||||
Properties: map[string]*jsonschema.Schema{
|
||||
"preWait": {
|
||||
Title: "Pre Wait (ms)",
|
||||
Description: "number of milliseconds to wait before playing the audio",
|
||||
Type: "integer",
|
||||
},
|
||||
"audioFile": {
|
||||
Title: "Audio File",
|
||||
Description: "path to the audio file to play",
|
||||
Type: "string",
|
||||
},
|
||||
"postWait": {
|
||||
Title: "Post Wait (ms)",
|
||||
Description: "number of milliseconds to wait after playing the audio",
|
||||
Type: "integer",
|
||||
},
|
||||
},
|
||||
Required: []string{"preWait", "postWait", "audioFile"},
|
||||
AdditionalProperties: &jsonschema.Schema{Not: &jsonschema.Schema{}},
|
||||
},
|
||||
New: func(config config.ProcessorConfig) (Processor, error) {
|
||||
params := config.Params
|
||||
|
||||
preWaitNum, err := params.GetInt("preWait")
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("sip.response.audio.create preWait error: %w", err)
|
||||
}
|
||||
|
||||
postWaitNum, err := params.GetInt("postWait")
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("sip.response.audio.create postWait error: %w", err)
|
||||
}
|
||||
|
||||
audioFileString, err := params.GetString("audioFile")
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("sip.response.audio.create audioFile error: %w", err)
|
||||
}
|
||||
|
||||
audioFileTemplate, err := template.New("audioFile").Parse(audioFileString)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &SipResponseAudioCreate{config: config, AudioFile: audioFileTemplate, PreWait: int(preWaitNum), PostWait: int(postWaitNum)}, nil
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
type SipResponseAudioCreate struct {
|
||||
config config.ProcessorConfig
|
||||
PreWait int
|
||||
PostWait int
|
||||
AudioFile *template.Template
|
||||
}
|
||||
|
||||
type SipAudioFileResponse struct {
|
||||
PreWait int
|
||||
PostWait int
|
||||
AudioFile string
|
||||
}
|
||||
|
||||
func (srac *SipResponseAudioCreate) Process(ctx context.Context, wrappedPayload common.WrappedPayload) (common.WrappedPayload, error) {
|
||||
|
||||
templateData := wrappedPayload
|
||||
|
||||
var audioFileBuffer bytes.Buffer
|
||||
err := srac.AudioFile.Execute(&audioFileBuffer, templateData)
|
||||
|
||||
if err != nil {
|
||||
wrappedPayload.End = true
|
||||
return wrappedPayload, err
|
||||
}
|
||||
|
||||
audioFileString := audioFileBuffer.String()
|
||||
|
||||
wrappedPayload.Payload = SipAudioFileResponse{
|
||||
PreWait: srac.PreWait,
|
||||
PostWait: srac.PostWait,
|
||||
AudioFile: audioFileString,
|
||||
}
|
||||
return wrappedPayload, nil
|
||||
}
|
||||
|
||||
func (srac *SipResponseAudioCreate) Id() string {
|
||||
return srac.config.Id
|
||||
}
|
||||
|
||||
func (srac *SipResponseAudioCreate) Type() string {
|
||||
return srac.config.Type
|
||||
}
|
||||
@@ -1,119 +0,0 @@
|
||||
package processor
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"regexp"
|
||||
"text/template"
|
||||
|
||||
"github.com/google/jsonschema-go/jsonschema"
|
||||
"github.com/jwetzell/showbridge-go/internal/common"
|
||||
"github.com/jwetzell/showbridge-go/internal/config"
|
||||
)
|
||||
|
||||
func init() {
|
||||
RegisterProcessor(ProcessorRegistration{
|
||||
Type: "sip.response.dtmf.create",
|
||||
Title: "Create SIP DTMF Response",
|
||||
ParamsSchema: &jsonschema.Schema{
|
||||
Type: "object",
|
||||
Properties: map[string]*jsonschema.Schema{
|
||||
"preWait": {
|
||||
Title: "Pre Wait (ms)",
|
||||
Description: "number of milliseconds to wait before sending the DTMF tones",
|
||||
Type: "integer",
|
||||
},
|
||||
"digits": {
|
||||
Title: "Digits",
|
||||
Description: "DTMF digits to send",
|
||||
Type: "string",
|
||||
},
|
||||
"postWait": {
|
||||
Title: "Post Wait (ms)",
|
||||
Description: "number of milliseconds to wait after sending the DTMF tones",
|
||||
Type: "integer",
|
||||
},
|
||||
},
|
||||
Required: []string{"preWait", "postWait", "digits"},
|
||||
AdditionalProperties: &jsonschema.Schema{Not: &jsonschema.Schema{}},
|
||||
},
|
||||
New: func(config config.ProcessorConfig) (Processor, error) {
|
||||
params := config.Params
|
||||
|
||||
preWaitNum, err := params.GetInt("preWait")
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("sip.response.dtmf.create preWait error: %w", err)
|
||||
}
|
||||
|
||||
postWaitNum, err := params.GetInt("postWait")
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("sip.response.dtmf.create postWait error: %w", err)
|
||||
}
|
||||
|
||||
digitsString, err := params.GetString("digits")
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("sip.response.dtmf.create digits error: %w", err)
|
||||
}
|
||||
|
||||
digitsTemplate, err := template.New("digits").Parse(digitsString)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &SipResponseDTMFCreate{config: config, Digits: digitsTemplate, PreWait: int(preWaitNum), PostWait: int(postWaitNum), validDTMF: validDTMFRegex}, nil
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
type SipResponseDTMFCreate struct {
|
||||
config config.ProcessorConfig
|
||||
PreWait int
|
||||
PostWait int
|
||||
Digits *template.Template
|
||||
validDTMF *regexp.Regexp
|
||||
}
|
||||
|
||||
type SipDTMFResponse struct {
|
||||
PreWait int
|
||||
PostWait int
|
||||
Digits string
|
||||
}
|
||||
|
||||
var validDTMFRegex = regexp.MustCompile(`^[0-9*#A-Da-d]+$`)
|
||||
|
||||
func (srdc *SipResponseDTMFCreate) Process(ctx context.Context, wrappedPayload common.WrappedPayload) (common.WrappedPayload, error) {
|
||||
|
||||
templateData := wrappedPayload
|
||||
|
||||
var digitsBuffer bytes.Buffer
|
||||
err := srdc.Digits.Execute(&digitsBuffer, templateData)
|
||||
|
||||
if err != nil {
|
||||
wrappedPayload.End = true
|
||||
return wrappedPayload, err
|
||||
}
|
||||
|
||||
digitsString := digitsBuffer.String()
|
||||
|
||||
if !srdc.validDTMF.MatchString(digitsString) {
|
||||
wrappedPayload.End = true
|
||||
return wrappedPayload, errors.New("sip.response.dtmf.create result of digits template contains invalid characters")
|
||||
}
|
||||
|
||||
wrappedPayload.Payload = SipDTMFResponse{
|
||||
PreWait: srdc.PreWait,
|
||||
PostWait: srdc.PostWait,
|
||||
Digits: digitsString,
|
||||
}
|
||||
return wrappedPayload, nil
|
||||
}
|
||||
|
||||
func (srdc *SipResponseDTMFCreate) Id() string {
|
||||
return srdc.config.Id
|
||||
}
|
||||
|
||||
func (srdc *SipResponseDTMFCreate) Type() string {
|
||||
return srdc.config.Type
|
||||
}
|
||||
@@ -1,248 +0,0 @@
|
||||
package processor_test
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
"github.com/jwetzell/showbridge-go/internal/common"
|
||||
"github.com/jwetzell/showbridge-go/internal/config"
|
||||
"github.com/jwetzell/showbridge-go/internal/processor"
|
||||
)
|
||||
|
||||
func TestSipResponseAudioCreateFromRegistry(t *testing.T) {
|
||||
registration, ok := processor.GetProcessorRegistration("sip.response.audio.create")
|
||||
if !ok {
|
||||
t.Fatalf("sip.response.audio.create processor not registered")
|
||||
}
|
||||
|
||||
processorInstance, err := registration.New(config.ProcessorConfig{
|
||||
Id: "test-id",
|
||||
Type: "sip.response.audio.create",
|
||||
Params: map[string]any{
|
||||
"preWait": 0,
|
||||
"audioFile": "good.wav",
|
||||
"postWait": 0,
|
||||
},
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
t.Fatalf("failed to filter sip.response.audio.create processor: %s", err)
|
||||
}
|
||||
|
||||
if processorInstance.Id() != "test-id" {
|
||||
t.Fatalf("sip.response.audio.create processor has wrong id: %s", processorInstance.Id())
|
||||
}
|
||||
|
||||
if processorInstance.Type() != "sip.response.audio.create" {
|
||||
t.Fatalf("sip.response.audio.create processor has wrong type: %s", processorInstance.Type())
|
||||
}
|
||||
}
|
||||
|
||||
func TestGoodSipResponseAudioCreate(t *testing.T) {
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
params map[string]any
|
||||
payload any
|
||||
expected any
|
||||
}{
|
||||
{
|
||||
name: "basic",
|
||||
params: map[string]any{
|
||||
"preWait": 0,
|
||||
"audioFile": "good.wav",
|
||||
"postWait": 0,
|
||||
},
|
||||
payload: nil,
|
||||
expected: processor.SipAudioFileResponse{
|
||||
PreWait: 0,
|
||||
PostWait: 0,
|
||||
AudioFile: "good.wav",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "template audio file",
|
||||
params: map[string]any{
|
||||
"preWait": 1,
|
||||
"audioFile": "{{.Payload.SomeField}}.wav",
|
||||
"postWait": 2,
|
||||
},
|
||||
payload: map[string]any{
|
||||
"SomeField": "templated",
|
||||
},
|
||||
expected: processor.SipAudioFileResponse{
|
||||
PreWait: 1,
|
||||
PostWait: 2,
|
||||
AudioFile: "templated.wav",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
|
||||
registration, ok := processor.GetProcessorRegistration("sip.response.audio.create")
|
||||
if !ok {
|
||||
t.Fatalf("sip.response.audio.create processor not registered")
|
||||
}
|
||||
|
||||
processorInstance, err := registration.New(config.ProcessorConfig{
|
||||
Type: "sip.response.audio.create",
|
||||
Params: test.params,
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
t.Fatalf("sip.response.audio.create failed to create processor: %s", err)
|
||||
}
|
||||
|
||||
got, err := processorInstance.Process(t.Context(), common.WrappedPayload{Payload: test.payload})
|
||||
if err != nil {
|
||||
t.Fatalf("sip.response.audio.create processing failed: %s", err)
|
||||
}
|
||||
|
||||
if !reflect.DeepEqual(got.Payload, test.expected) {
|
||||
t.Fatalf("sip.response.audio.create got %+v (%T), expected %+v (%T)", got.Payload, got.Payload, test.expected, test.expected)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestBadSipResponseAudioCreate(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
params map[string]any
|
||||
payload any
|
||||
errorString string
|
||||
}{
|
||||
{
|
||||
name: "missing preWait param",
|
||||
params: map[string]any{
|
||||
"audioFile": "good.wav",
|
||||
"postWait": 0,
|
||||
},
|
||||
errorString: "sip.response.audio.create preWait error: not found",
|
||||
},
|
||||
{
|
||||
name: "non-numeric preWait param",
|
||||
params: map[string]any{
|
||||
"preWait": "not a number",
|
||||
"audioFile": "good.wav",
|
||||
"postWait": 0,
|
||||
},
|
||||
errorString: "sip.response.audio.create preWait error: not a number",
|
||||
},
|
||||
{
|
||||
name: "missing audioFile param",
|
||||
params: map[string]any{
|
||||
"preWait": 0,
|
||||
"postWait": 0,
|
||||
},
|
||||
errorString: "sip.response.audio.create audioFile error: not found",
|
||||
},
|
||||
{
|
||||
name: "non-string audioFile param",
|
||||
params: map[string]any{
|
||||
"preWait": 0,
|
||||
"audioFile": 123,
|
||||
"postWait": 0,
|
||||
},
|
||||
errorString: "sip.response.audio.create audioFile error: not a string",
|
||||
},
|
||||
{
|
||||
name: "audioFile template syntax error",
|
||||
params: map[string]any{
|
||||
"preWait": 0,
|
||||
"audioFile": "{{.Unclosed",
|
||||
"postWait": 0,
|
||||
},
|
||||
errorString: "template: audioFile:1: unclosed action",
|
||||
},
|
||||
{
|
||||
name: "audioFile template error",
|
||||
params: map[string]any{
|
||||
"preWait": 0,
|
||||
"audioFile": "{{.NonExistentField}} ",
|
||||
"postWait": 0,
|
||||
},
|
||||
errorString: "template: audioFile:1:2: executing \"audioFile\" at <.NonExistentField>: can't evaluate field NonExistentField in type common.WrappedPayload",
|
||||
},
|
||||
{
|
||||
name: "missing postWait param",
|
||||
params: map[string]any{
|
||||
"preWait": 0,
|
||||
"audioFile": "good.wav",
|
||||
},
|
||||
errorString: "sip.response.audio.create postWait error: not found",
|
||||
},
|
||||
{
|
||||
name: "non-numeric postWait param",
|
||||
params: map[string]any{
|
||||
"preWait": 0,
|
||||
"audioFile": "good.wav",
|
||||
"postWait": "not a number",
|
||||
},
|
||||
errorString: "sip.response.audio.create postWait error: not a number",
|
||||
},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
|
||||
registration, ok := processor.GetProcessorRegistration("sip.response.audio.create")
|
||||
if !ok {
|
||||
t.Fatalf("sip.response.audio.create processor not registered")
|
||||
}
|
||||
|
||||
processorInstance, err := registration.New(config.ProcessorConfig{
|
||||
Type: "sip.response.audio.create",
|
||||
Params: test.params,
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
if test.errorString != err.Error() {
|
||||
t.Fatalf("sip.response.audio.create got error '%s', expected '%s'", err.Error(), test.errorString)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
got, err := processorInstance.Process(t.Context(), common.WrappedPayload{Payload: test.payload})
|
||||
|
||||
if err == nil {
|
||||
t.Fatalf("sip.response.audio.create expected to fail but succeeded, got: %v", got)
|
||||
}
|
||||
|
||||
if err.Error() != test.errorString {
|
||||
t.Fatalf("sip.response.audio.create got error '%s', expected '%s'", err.Error(), test.errorString)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkSipResponseAudioCreate(b *testing.B) {
|
||||
registration, ok := processor.GetProcessorRegistration("sip.response.audio.create")
|
||||
if !ok {
|
||||
b.Fatalf("sip.response.audio.create processor not registered")
|
||||
}
|
||||
|
||||
processorInstance, err := registration.New(config.ProcessorConfig{
|
||||
Type: "sip.response.audio.create",
|
||||
Params: map[string]any{
|
||||
"preWait": 0,
|
||||
"audioFile": "good.wav",
|
||||
"postWait": 0,
|
||||
},
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
b.Fatalf("sip.response.audio.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("sip.response.audio.create processing failed: %s", err)
|
||||
}
|
||||
count++
|
||||
}
|
||||
}
|
||||
@@ -1,256 +0,0 @@
|
||||
package processor_test
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
"github.com/jwetzell/showbridge-go/internal/common"
|
||||
"github.com/jwetzell/showbridge-go/internal/config"
|
||||
"github.com/jwetzell/showbridge-go/internal/processor"
|
||||
)
|
||||
|
||||
func TestSipResponseDTMFCreateFromRegistry(t *testing.T) {
|
||||
registration, ok := processor.GetProcessorRegistration("sip.response.dtmf.create")
|
||||
if !ok {
|
||||
t.Fatalf("sip.response.dtmf.create processor not registered")
|
||||
}
|
||||
|
||||
processorInstance, err := registration.New(config.ProcessorConfig{
|
||||
Id: "test-id",
|
||||
Type: "sip.response.dtmf.create",
|
||||
Params: map[string]any{
|
||||
"preWait": 0,
|
||||
"digits": "good.wav",
|
||||
"postWait": 0,
|
||||
},
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
t.Fatalf("failed to filter sip.response.dtmf.create processor: %s", err)
|
||||
}
|
||||
|
||||
if processorInstance.Id() != "test-id" {
|
||||
t.Fatalf("sip.response.dtmf.create processor has wrong id: %s", processorInstance.Id())
|
||||
}
|
||||
|
||||
if processorInstance.Type() != "sip.response.dtmf.create" {
|
||||
t.Fatalf("sip.response.dtmf.create processor has wrong type: %s", processorInstance.Type())
|
||||
}
|
||||
}
|
||||
|
||||
func TestGoodSipResponseDTMFCreate(t *testing.T) {
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
params map[string]any
|
||||
payload any
|
||||
expected any
|
||||
}{
|
||||
{
|
||||
name: "basic",
|
||||
params: map[string]any{
|
||||
"preWait": 0,
|
||||
"digits": "12345",
|
||||
"postWait": 0,
|
||||
},
|
||||
payload: nil,
|
||||
expected: processor.SipDTMFResponse{
|
||||
PreWait: 0,
|
||||
PostWait: 0,
|
||||
Digits: "12345",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "template digits",
|
||||
params: map[string]any{
|
||||
"preWait": 0,
|
||||
"digits": "{{.Payload}}",
|
||||
"postWait": 0,
|
||||
},
|
||||
payload: "67890",
|
||||
expected: processor.SipDTMFResponse{
|
||||
PreWait: 0,
|
||||
PostWait: 0,
|
||||
Digits: "67890",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
|
||||
registration, ok := processor.GetProcessorRegistration("sip.response.dtmf.create")
|
||||
if !ok {
|
||||
t.Fatalf("sip.response.dtmf.create processor not registered")
|
||||
}
|
||||
|
||||
processorInstance, err := registration.New(config.ProcessorConfig{
|
||||
Type: "sip.response.dtmf.create",
|
||||
Params: test.params,
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
t.Fatalf("sip.response.dtmf.create failed to create processor: %s", err)
|
||||
}
|
||||
|
||||
got, err := processorInstance.Process(t.Context(), common.WrappedPayload{Payload: test.payload})
|
||||
if err != nil {
|
||||
t.Fatalf("sip.response.dtmf.create processing failed: %s", err)
|
||||
}
|
||||
|
||||
if !reflect.DeepEqual(got.Payload, test.expected) {
|
||||
t.Fatalf("sip.response.dtmf.create got %+v (%T), expected %+v (%T)", got.Payload, got.Payload, test.expected, test.expected)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestBadSipResponseDTMFCreate(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
params map[string]any
|
||||
payload any
|
||||
errorString string
|
||||
}{
|
||||
{
|
||||
name: "missing preWait param",
|
||||
params: map[string]any{
|
||||
"digits": "good.wav",
|
||||
"postWait": 0,
|
||||
},
|
||||
errorString: "sip.response.dtmf.create preWait error: not found",
|
||||
},
|
||||
{
|
||||
name: "non-numeric preWait param",
|
||||
params: map[string]any{
|
||||
"preWait": "not a number",
|
||||
"digits": "good.wav",
|
||||
"postWait": 0,
|
||||
},
|
||||
errorString: "sip.response.dtmf.create preWait error: not a number",
|
||||
},
|
||||
{
|
||||
name: "missing digits param",
|
||||
params: map[string]any{
|
||||
"preWait": 0,
|
||||
"postWait": 0,
|
||||
},
|
||||
errorString: "sip.response.dtmf.create digits error: not found",
|
||||
},
|
||||
{
|
||||
name: "non-string digits param",
|
||||
params: map[string]any{
|
||||
"preWait": 0,
|
||||
"digits": 12345,
|
||||
"postWait": 0,
|
||||
},
|
||||
errorString: "sip.response.dtmf.create digits error: not a string",
|
||||
},
|
||||
{
|
||||
name: "digits template syntax error",
|
||||
params: map[string]any{
|
||||
"preWait": 0,
|
||||
"digits": "{{.Unclosed",
|
||||
"postWait": 0,
|
||||
},
|
||||
errorString: "template: digits:1: unclosed action",
|
||||
},
|
||||
{
|
||||
name: "digits template error",
|
||||
params: map[string]any{
|
||||
"preWait": 0,
|
||||
"digits": "{{.NonExistentField}} ",
|
||||
"postWait": 0,
|
||||
},
|
||||
errorString: "template: digits:1:2: executing \"digits\" at <.NonExistentField>: can't evaluate field NonExistentField in type common.WrappedPayload",
|
||||
},
|
||||
{
|
||||
name: "invalid digits template result",
|
||||
payload: "nhf",
|
||||
params: map[string]any{
|
||||
"preWait": 0,
|
||||
"digits": "{{.Payload}}",
|
||||
"postWait": 0,
|
||||
},
|
||||
errorString: "sip.response.dtmf.create result of digits template contains invalid characters",
|
||||
},
|
||||
{
|
||||
name: "missing postWait param",
|
||||
params: map[string]any{
|
||||
"preWait": 0,
|
||||
"digits": "good.wav",
|
||||
},
|
||||
errorString: "sip.response.dtmf.create postWait error: not found",
|
||||
},
|
||||
{
|
||||
name: "non-numeric postWait param",
|
||||
params: map[string]any{
|
||||
"preWait": 0,
|
||||
"digits": "good.wav",
|
||||
"postWait": "not a number",
|
||||
},
|
||||
errorString: "sip.response.dtmf.create postWait error: not a number",
|
||||
},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
|
||||
registration, ok := processor.GetProcessorRegistration("sip.response.dtmf.create")
|
||||
if !ok {
|
||||
t.Fatalf("sip.response.dtmf.create processor not registered")
|
||||
}
|
||||
|
||||
processorInstance, err := registration.New(config.ProcessorConfig{
|
||||
Type: "sip.response.dtmf.create",
|
||||
Params: test.params,
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
if test.errorString != err.Error() {
|
||||
t.Fatalf("sip.response.dtmf.create got error '%s', expected '%s'", err.Error(), test.errorString)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
got, err := processorInstance.Process(t.Context(), common.WrappedPayload{Payload: test.payload})
|
||||
|
||||
if err == nil {
|
||||
t.Fatalf("sip.response.dtmf.create expected to fail but succeeded, got: %v", got)
|
||||
}
|
||||
|
||||
if err.Error() != test.errorString {
|
||||
t.Fatalf("sip.response.dtmf.create got error '%s', expected '%s'", err.Error(), test.errorString)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkSipResponseDTMFCreate(b *testing.B) {
|
||||
registration, ok := processor.GetProcessorRegistration("sip.response.dtmf.create")
|
||||
if !ok {
|
||||
b.Fatalf("sip.response.dtmf.create processor not registered")
|
||||
}
|
||||
|
||||
processorInstance, err := registration.New(config.ProcessorConfig{
|
||||
Type: "sip.response.dtmf.create",
|
||||
Params: map[string]any{
|
||||
"preWait": 0,
|
||||
"digits": "{{.Payload}}",
|
||||
"postWait": 0,
|
||||
},
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
b.Fatalf("sip.response.dtmf.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("sip.response.dtmf.create processing failed: %s", err)
|
||||
}
|
||||
count++
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user