-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for validating a sip uri in the From and To fields
Add ParsedNumber to provide details about different types of To and From values including SIP URI's
- Loading branch information
Showing
4 changed files
with
219 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,9 @@ | ||
package twiml | ||
|
||
import "testing" | ||
import ( | ||
"reflect" | ||
"testing" | ||
) | ||
|
||
func TestRequestValues_Duration(t *testing.T) { | ||
tests := []struct { | ||
|
@@ -25,3 +28,28 @@ func TestRequestValues_Duration(t *testing.T) { | |
}) | ||
} | ||
} | ||
|
||
func TestParseNumber(t *testing.T) { | ||
type args struct { | ||
v string | ||
} | ||
tests := []struct { | ||
name string | ||
args args | ||
want *ParsedNumber | ||
}{ | ||
{name: "Valid Number", args: args{v: "+18005642365"}, want: &ParsedNumber{Valid: true, Number: "+18005642365", Raw: "+18005642365"}}, | ||
{name: "Valid SIP us1", args: args{v: "sips:[email protected]:5061"}, want: &ParsedNumber{Valid: true, Number: "+18005642365", Sip: true, SipDomain: "domain", Region: "sip", Raw: "sips:[email protected]:5061"}}, | ||
{name: "Valid SIP us2", args: args{v: "sips:[email protected]:5061"}, want: &ParsedNumber{Valid: true, Number: "+18005642365", Sip: true, SipDomain: "domain", Region: "sip", Raw: "sips:[email protected]:5061"}}, | ||
{name: "Invalid SIP sip.domain.com", args: args{v: "sips:[email protected]:5061"}, want: &ParsedNumber{Number: "sips:[email protected]:5061", Raw: "sips:[email protected]:5061"}}, | ||
{name: "Invalid SIP sip2.twilio.com", args: args{v: "sips:[email protected]:5061"}, want: &ParsedNumber{Number: "sips:[email protected]:5061", Raw: "sips:[email protected]:5061"}}, | ||
{name: "Invalid SIP twilio.com", args: args{v: "sips:[email protected]:5061"}, want: &ParsedNumber{Number: "sips:[email protected]:5061", Raw: "sips:[email protected]:5061"}}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
if got := ParseNumber(tt.args.v); !reflect.DeepEqual(got, tt.want) { | ||
t.Errorf("ParseNumber() = %v, want %v", got, tt.want) | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package twiml | ||
|
||
import "testing" | ||
|
||
func Test_validSipURI(t *testing.T) { | ||
type args struct { | ||
v interface{} | ||
param string | ||
} | ||
tests := []struct { | ||
name string | ||
args args | ||
wantErr bool | ||
}{ | ||
{name: "Valid SIPS URI", args: args{v: "sips:[email protected]:5061", param: ""}, wantErr: false}, | ||
{name: "Valid SIP URI", args: args{v: "sip:[email protected]:5061", param: ""}, wantErr: false}, | ||
{name: "Valid", args: args{v: "", param: "allowempty"}, wantErr: false}, | ||
{name: "Invaid", args: args{v: "", param: ""}, wantErr: true}, | ||
{name: "Invalid SIP URI", args: args{v: "+18002368945", param: ""}, wantErr: true}, | ||
{name: "Invalid URL", args: args{v: "https://[email protected]:5061", param: ""}, wantErr: true}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
if err := validSipURI(tt.args.v, tt.args.param); (err != nil) != tt.wantErr { | ||
t.Errorf("validSipURI() error = %v, wantErr %v", err, tt.wantErr) | ||
} | ||
}) | ||
} | ||
} |