-
Notifications
You must be signed in to change notification settings - Fork 3
/
template_test.go
60 lines (47 loc) · 1.43 KB
/
template_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
package gtpv2_test
import (
"fmt"
"testing"
"github.com/blorticus/gtpv2"
)
var badYamlDefintions = []string{
"lkaj;ion",
`---
Gtpv2Pdus:
- Name: malprop
Type: Yoodle
`,
}
func TestInvalidValuesForReadYamlTemplateFromString(t *testing.T) {
for definitionNumber, definitionString := range badYamlDefintions {
if _, err := gtpv2.ReadYamlTemplateFromString(definitionString); err == nil {
t.Errorf("[ReadYamlTemplateFromString] On badYamlDefinition at index (%d) expected error, but received none", definitionNumber)
}
}
}
func errorIfValidTemplateReadFails(testname string, template *gtpv2.Template, errorFromRead error) error {
if errorFromRead != nil {
return fmt.Errorf("%s, expected no error, got = (%s)", testname, errorFromRead.Error())
}
if template == nil {
return fmt.Errorf("%s, expected template != nil; template == nil", testname)
}
return nil
}
var validYamlDefinitions = []string{
`---
Gtpv2Pdus:
- Name: csr
Type: CreateSessionRequest
`,
}
func TestReadYamlTemplateFromString(t *testing.T) {
template, err := gtpv2.ReadYamlTemplateFromString("")
if err = errorIfValidTemplateReadFails("[ReadYamlTemplateFromString] on empty string", template, err); err != nil {
t.Fatal(err)
}
template, err = gtpv2.ReadYamlTemplateFromString(validYamlDefinitions[0])
if err = errorIfValidTemplateReadFails("[ReadYamlTemplateFromString] validYamlDefinition[0]", template, err); err != nil {
t.Fatal(err)
}
}