-
Notifications
You must be signed in to change notification settings - Fork 20
/
vocabulary_test.go
85 lines (73 loc) · 2.5 KB
/
vocabulary_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
package twiml
import (
"github.com/stretchr/testify/assert"
"testing"
)
func Test_ClientWithIdentity(t *testing.T) {
response := NewResponse()
dial := &Dial{Number: " "}
response.Add(dial)
client := &Client{
Identity: Alice,
URL: "http://google.com/url",
Method: "POST",
StatusCallback: "initiated",
StatusCallbackEvent: "GET",
StatusCallbackMethod: "http://google.com/status",
}
dial.Add(client)
client.Add(Parameter{Name: "FirstName", Value: "Alice"})
client.Add(Parameter{Name: "LastName", Value: "Smith"})
b, err := response.Encode()
assert.NoError(t, err)
assert.NotEmpty(t, b)
data := string(b)
assert.Contains(t, data, `<Client method="POST" url="http://google.com/url" statusCallback="initiated" statusCallbackEvent="GET" statusCallbackMethod="http://google.com/status">`)
assert.Contains(t, data, `<Identity>alice</Identity>`)
assert.Contains(t, data, `<Parameter name="FirstName" value="Alice"></Parameter>`)
assert.Contains(t, data, `<Parameter name="LastName" value="Smith"></Parameter>`)
t.Log(string(b))
}
func Test_ClientWithoutIdentity(t *testing.T) {
response := NewResponse()
dial := &Dial{Number: " "}
response.Add(dial)
client := &Client{Name: Alice}
dial.Add(client)
b, err := response.Encode()
assert.NoError(t, err)
assert.NotEmpty(t, b)
data := string(b)
assert.Contains(t, data, `<Client>alice</Client>`)
}
func TestClient_Validate(t *testing.T) {
type fields struct {
Name string
Identity string
Method string
Children []Markup
}
tests := []struct {
name string
fields fields
wantErr bool
}{
{name: "Identity_No_Parameters", fields: fields{Identity: "Alice"}, wantErr: false},
{name: "Identity_Parameters", fields: fields{Identity: "Alice", Children: []Markup{&Parameter{Name: "FirstName", Value: "Alice"}, &Parameter{Name: "LastName", Value: "Smith"}}}, wantErr: false},
{name: "Name_No_Parameters", fields: fields{Name: "Alice"}, wantErr: false},
{name: "Name_Parameters", fields: fields{Name: "Alice", Children: []Markup{&Parameter{Name: "FirstName", Value: "Alice"}, &Parameter{Name: "LastName", Value: "Smith"}}}, wantErr: true},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
c := &Client{
Name: tt.fields.Name,
Identity: tt.fields.Identity,
Method: tt.fields.Method,
Children: tt.fields.Children,
}
if err := c.Validate(); (err != nil) != tt.wantErr {
t.Errorf("Validate() error = %v, wantErr %v", err, tt.wantErr)
}
})
}
}