Skip to content

Commit 21ab3d0

Browse files
author
Chris Busbey
committed
go check purged
1 parent bd1898f commit 21ab3d0

File tree

4 files changed

+267
-148
lines changed

4 files changed

+267
-148
lines changed

Makefile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ all: vet test
22

33
get:
44
go get github.com/golang/lint/golint
5-
go get gopkg.in/check.v1
65

76
GEN_MESSAGES = go run _gen/generate-messages/main.go
87
GEN_COMPONENTS = go run _gen/generate-components/main.go

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ See [examples](https://github.com/quickfixgo/examples) for some simple examples
1313
Build and Test
1414
--------------
1515

16-
QuickFIX/Go has build dependencies for testing. To fetch Go dependencies, run `make get`. Acceptance tests depend on ruby in path.
17-
1816
The default make target runs [go vet](https://godoc.org/golang.org/x/tools/cmd/vet) and unit tests.
1917

18+
QuickFIX/Go acceptance tests depend on ruby in path.
19+
2020
To run acceptance tests,
2121

2222
# build acceptance test rig
Lines changed: 164 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -1,113 +1,191 @@
11
package datadictionary
22

33
import (
4-
. "gopkg.in/check.v1"
4+
"testing"
55
)
66

7-
var _ = Suite(&DataDictionaryTests{})
8-
9-
type DataDictionaryTests struct {
10-
dict *DataDictionary
7+
func TestParseBadPath(t *testing.T) {
8+
if _, err := Parse("../spec/bogus.xml"); err == nil {
9+
t.Error("Expected err")
10+
}
1111
}
1212

13-
func (s *DataDictionaryTests) SetUpTest(c *C) {
14-
dict, err := Parse("../spec/FIX43.xml")
15-
c.Check(err, IsNil)
16-
c.Check(dict, NotNil)
13+
func TestParseRecursiveComponents(t *testing.T) {
14+
dict, err := Parse("../spec/FIX44.xml")
1715

18-
s.dict = dict
19-
}
16+
if dict == nil {
17+
t.Error("Dictionary is nil")
18+
}
2019

21-
func (s *DataDictionaryTests) TestParseBadPath(c *C) {
22-
_, err := Parse("../spec/bogus.xml")
23-
c.Check(err, NotNil)
20+
if err != nil {
21+
t.Errorf("Unexpected err: %v", err)
22+
}
2423
}
2524

26-
func (s *DataDictionaryTests) TestParseRecursiveComponents(c *C) {
27-
dict, err := Parse("../spec/FIX44.xml")
28-
c.Check(err, IsNil)
29-
c.Check(dict, NotNil)
30-
}
25+
var cachedDataDictionary *DataDictionary
3126

32-
func (s *DataDictionaryTests) TestComponents(c *C) {
33-
_, ok := s.dict.Components["SpreadOrBenchmarkCurveData"]
34-
c.Check(ok, Equals, true)
35-
}
27+
func dict() (*DataDictionary, error) {
28+
if cachedXmlDoc != nil {
29+
return cachedDataDictionary, nil
30+
}
3631

37-
func (s *DataDictionaryTests) TestFieldsByTag(c *C) {
38-
f, ok := s.dict.FieldTypeByTag[655]
39-
c.Check(ok, Equals, true)
40-
c.Check(f.Tag, Equals, 655)
41-
c.Check(f.Name, Equals, "ContraLegRefID")
42-
c.Check(f.Type, Equals, "STRING")
43-
c.Check(f.Enums, IsNil)
44-
45-
f, ok = s.dict.FieldTypeByTag[658]
46-
c.Check(ok, Equals, true)
47-
c.Check(f.Tag, Equals, 658)
48-
c.Check(f.Name, Equals, "QuoteRequestRejectReason")
49-
c.Check(f.Type, Equals, "INT")
50-
51-
c.Check(f.Enums, NotNil)
52-
c.Check(len(f.Enums), Equals, 6)
53-
c.Check(f.Enums["1"].Value, Equals, "1")
54-
c.Check(f.Enums["1"].Description, Equals, "UNKNOWN_SYMBOL")
32+
var err error
33+
cachedDataDictionary, err = Parse("../spec/FIX43.xml")
34+
return cachedDataDictionary, err
5535
}
5636

57-
func (s *DataDictionaryTests) TestMessages(c *C) {
58-
_, ok := s.dict.Messages["D"]
59-
c.Check(ok, Equals, true)
37+
func TestComponents(t *testing.T) {
38+
d, _ := dict()
39+
if _, ok := d.Components["SpreadOrBenchmarkCurveData"]; ok != true {
40+
t.Error("Component not found")
41+
}
6042
}
6143

62-
func (s *DataDictionaryTests) TestHeader(c *C) {
63-
c.Check(s.dict.Header, NotNil)
44+
func TestFieldsByTag(t *testing.T) {
45+
d, _ := dict()
46+
47+
var tests = []struct {
48+
Tag int
49+
Name string
50+
Type string
51+
EnumsAreNil bool
52+
}{
53+
{655, "ContraLegRefID", "STRING", true},
54+
{658, "QuoteRequestRejectReason", "INT", false},
55+
}
56+
57+
for _, test := range tests {
58+
f, ok := d.FieldTypeByTag[test.Tag]
59+
60+
if !ok {
61+
t.Errorf("%v not found", test.Tag)
62+
}
63+
64+
if f.Name != test.Name {
65+
t.Errorf("Expected %v got %v", test.Name, f.Name)
66+
}
67+
68+
if f.Type != test.Type {
69+
t.Errorf("Expected %v got %v", test.Type, f.Type)
70+
}
71+
72+
switch {
73+
74+
case f.Enums != nil && test.EnumsAreNil:
75+
t.Errorf("Expected no enums")
76+
case f.Enums == nil && !test.EnumsAreNil:
77+
t.Errorf("Expected enums")
78+
}
79+
}
6480
}
6581

66-
func (s *DataDictionaryTests) TestTrailer(c *C) {
67-
c.Check(s.dict.Trailer, NotNil)
82+
func TestEnumFieldsByTag(t *testing.T) {
83+
84+
d, _ := dict()
85+
f, _ := d.FieldTypeByTag[658]
86+
87+
var tests = []struct {
88+
Value string
89+
Description string
90+
}{
91+
{"1", "UNKNOWN_SYMBOL"},
92+
{"2", "EXCHANGE"},
93+
{"3", "QUOTE_REQUEST_EXCEEDS_LIMIT"},
94+
{"4", "TOO_LATE_TO_ENTER"},
95+
{"5", "INVALID_PRICE"},
96+
{"6", "NOT_AUTHORIZED_TO_REQUEST_QUOTE"},
97+
}
98+
99+
if len(f.Enums) != len(tests) {
100+
t.Errorf("Expected %v enums got %v", len(tests), len(f.Enums))
101+
}
102+
103+
for _, test := range tests {
104+
if enum, ok := f.Enums[test.Value]; !ok {
105+
t.Errorf("Expected Enum %v", test.Value)
106+
} else {
107+
108+
if enum.Value != test.Value {
109+
t.Errorf("Expected value %v got %v", test.Value, enum.Value)
110+
}
111+
112+
if enum.Description != test.Description {
113+
t.Errorf("Expected description %v got %v", test.Description, enum.Description)
114+
}
115+
}
116+
}
68117
}
69118

70-
func (s *DataDictionaryTests) TestMessageRequiredTags(c *C) {
71-
m, ok := s.dict.Messages["D"]
72-
c.Check(ok, Equals, true)
73-
74-
_, required := m.RequiredTags[11]
75-
c.Check(required, Equals, true)
76-
_, required = m.RequiredTags[526]
77-
c.Check(required, Equals, false)
78-
79-
_, required = s.dict.Header.RequiredTags[8]
80-
c.Check(required, Equals, true)
81-
82-
_, required = s.dict.Header.RequiredTags[115]
83-
c.Check(required, Equals, false)
84-
85-
_, required = s.dict.Trailer.RequiredTags[10]
86-
c.Check(required, Equals, true)
87-
88-
_, required = s.dict.Trailer.RequiredTags[89]
89-
c.Check(required, Equals, false)
90-
119+
func TestDataDictionaryMessages(t *testing.T) {
120+
d, _ := dict()
121+
_, ok := d.Messages["D"]
122+
if !ok {
123+
t.Error("Did not find message")
124+
}
91125
}
92126

93-
func (s *DataDictionaryTests) TestMessageTags(c *C) {
94-
m, ok := s.dict.Messages["D"]
95-
c.Check(ok, Equals, true)
96-
97-
_, known := m.Tags[11]
98-
c.Check(known, Equals, true)
99-
_, known = m.Tags[526]
100-
c.Check(known, Equals, true)
101-
102-
_, known = s.dict.Header.Tags[8]
103-
c.Check(known, Equals, true)
127+
func TestDataDictionaryHeader(t *testing.T) {
128+
d, _ := dict()
129+
if d.Header == nil {
130+
t.Error("Did not find header")
131+
}
132+
}
104133

105-
_, known = s.dict.Header.Tags[115]
106-
c.Check(known, Equals, true)
134+
func TestDataDictionaryTrailer(t *testing.T) {
135+
d, _ := dict()
136+
if d.Trailer == nil {
137+
t.Error("Did not find trailer")
138+
}
139+
}
107140

108-
_, known = s.dict.Trailer.Tags[10]
109-
c.Check(known, Equals, true)
141+
func TestMessageRequiredTags(t *testing.T) {
142+
d, _ := dict()
143+
144+
nos, _ := d.Messages["D"]
145+
146+
var tests = []struct {
147+
*MessageDef
148+
Tag int
149+
Required bool
150+
}{
151+
{nos, 11, true},
152+
{nos, 526, false},
153+
{d.Header, 8, true},
154+
{d.Header, 115, false},
155+
{d.Trailer, 10, true},
156+
{d.Trailer, 89, false},
157+
}
158+
159+
for _, test := range tests {
160+
switch _, required := test.MessageDef.RequiredTags[test.Tag]; {
161+
case required && !test.Required:
162+
t.Errorf("%v should not be required", test.Tag)
163+
case !required && test.Required:
164+
t.Errorf("%v should not required", test.Tag)
165+
}
166+
}
167+
}
110168

111-
_, known = s.dict.Trailer.Tags[89]
112-
c.Check(known, Equals, true)
169+
func TestMessageTags(t *testing.T) {
170+
d, _ := dict()
171+
172+
nos, _ := d.Messages["D"]
173+
174+
var tests = []struct {
175+
*MessageDef
176+
Tag int
177+
}{
178+
{nos, 11},
179+
{nos, 526},
180+
{d.Header, 8},
181+
{d.Header, 115},
182+
{d.Trailer, 10},
183+
{d.Trailer, 89},
184+
}
185+
186+
for _, test := range tests {
187+
if _, known := test.MessageDef.Tags[test.Tag]; !known {
188+
t.Errorf("%v is not known", test.Tag)
189+
}
190+
}
113191
}

0 commit comments

Comments
 (0)