Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(594)

Delta Between Two Patch Sets: environs/tools/list_test.go

Issue 8604043: environs/tools: new package
Left Patch Set: environs/tools: new package Created 10 years, 11 months ago
Right Patch Set: environs/tools: new package Created 10 years, 11 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « environs/tools/list.go ('k') | no next file » | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 package tools_test 1 package tools_test
2 2
3 import ( 3 import (
4 . "launchpad.net/gocheck" 4 . "launchpad.net/gocheck"
5 "launchpad.net/juju-core/environs/tools" 5 "launchpad.net/juju-core/environs/tools"
6 "launchpad.net/juju-core/state" 6 "launchpad.net/juju-core/state"
7 "launchpad.net/juju-core/version" 7 "launchpad.net/juju-core/version"
8 "testing" 8 "testing"
9 ) 9 )
10 10
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
49 } 49 }
50 t2001precise = mustParseTools("2.0.0.1-precise-amd64") 50 t2001precise = mustParseTools("2.0.0.1-precise-amd64")
51 tAll = extend(t100all, t190all, append(t200all, t2001precise)) 51 tAll = extend(t100all, t190all, append(t200all, t2001precise))
52 ) 52 )
53 53
54 type stringsTest struct { 54 type stringsTest struct {
55 src tools.List 55 src tools.List
56 expect []string 56 expect []string
57 } 57 }
58 58
59 var seriesTests = []stringsTest{{
60 tools.List{t100precise},
61 []string{"precise"},
62 }, {
63 tools.List{t100precise, t100precise32, t200precise},
64 []string{"precise"},
65 }, {
66 tAll,
67 []string{"precise", "quantal"},
68 }}
69
59 func (s *ListSuite) TestSeries(c *C) { 70 func (s *ListSuite) TestSeries(c *C) {
60 » for i, test := range []stringsTest{{ 71 » for i, test := range seriesTests {
61 » » tools.List{t100precise},
62 » » []string{"precise"},
63 » }, {
64 » » tools.List{t100precise, t100precise32, t200precise},
65 » » []string{"precise"},
66 » }, {
67 » » tAll,
68 » » []string{"precise", "quantal"},
69 » }} {
70 c.Logf("test %d", i) 72 c.Logf("test %d", i)
71 c.Check(test.src.Series(), DeepEquals, test.expect) 73 c.Check(test.src.Series(), DeepEquals, test.expect)
72 } 74 }
73 } 75 }
74 76
77 var archesTests = []stringsTest{{
78 tools.List{t100precise},
79 []string{"amd64"},
80 }, {
81 tools.List{t100precise, t100quantal, t200precise},
82 []string{"amd64"},
83 }, {
84 tAll,
85 []string{"amd64", "i386"},
86 }}
87
75 func (s *ListSuite) TestArches(c *C) { 88 func (s *ListSuite) TestArches(c *C) {
76 » for i, test := range []stringsTest{{ 89 » for i, test := range archesTests {
77 » » tools.List{t100precise},
78 » » []string{"amd64"},
79 » }, {
80 » » tools.List{t100precise, t100quantal, t200precise},
81 » » []string{"amd64"},
82 » }, {
83 » » tAll,
84 » » []string{"amd64", "i386"},
85 » }} {
86 c.Logf("test %d", i) 90 c.Logf("test %d", i)
87 c.Check(test.src.Arches(), DeepEquals, test.expect) 91 c.Check(test.src.Arches(), DeepEquals, test.expect)
88 } 92 }
89 } 93 }
90 94
95 var newestTests = []struct {
96 src tools.List
97 expect tools.List
98 }{{
99 nil,
100 nil,
101 }, {
102 tools.List{t100precise},
103 tools.List{t100precise},
104 }, {
105 t100all,
106 t100all,
107 }, {
108 extend(t100all, t190all, t200all),
109 t200all,
110 }, {
111 tAll,
112 tools.List{t2001precise},
113 }}
114
91 func (s *ListSuite) TestNewest(c *C) { 115 func (s *ListSuite) TestNewest(c *C) {
92 » for i, test := range []struct { 116 » for i, test := range newestTests {
93 » » src tools.List
94 » » expect tools.List
95 » }{{
96 » » tools.List{t100precise},
97 » » tools.List{t100precise},
98 » }, {
99 » » t100all,
100 » » t100all,
101 » }, {
102 » » extend(t100all, t190all, t200all),
103 » » t200all,
104 » }, {
105 » » tAll,
106 » » tools.List{t2001precise},
107 » }} {
108 c.Logf("test %d", i) 117 c.Logf("test %d", i)
109 c.Check(test.src.Newest(), DeepEquals, test.expect) 118 c.Check(test.src.Newest(), DeepEquals, test.expect)
110 } 119 }
111 } 120 }
112 121
113 func (s *ListSuite) TestDifference(c *C) { 122 var excludeTests = []struct {
114 » for i, test := range []struct { 123 » src tools.List
115 » » src tools.List 124 » arg tools.List
116 » » arg tools.List 125 » expect tools.List
117 » » expect tools.List 126 }{{
118 » }{{ 127 » nil, tools.List{t100precise}, nil,
119 » » nil, tools.List{t100precise}, nil, 128 }, {
120 » }, { 129 » tools.List{t100precise}, nil, tools.List{t100precise},
121 » » tools.List{t100precise}, nil, tools.List{t100precise}, 130 }, {
122 » }, { 131 » tools.List{t100precise}, tools.List{t100precise}, nil,
123 » » tools.List{t100precise}, tools.List{t100precise}, nil, 132 }, {
124 » }, { 133 » nil, tAll, nil,
125 » » nil, tAll, nil, 134 }, {
126 » }, { 135 » tAll, nil, tAll,
127 » » tAll, nil, tAll, 136 }, {
128 » }, { 137 » tAll, tAll, nil,
129 » » tAll, tAll, nil, 138 }, {
130 » }, { 139 » t100all,
131 » » t100all, 140 » tools.List{t100precise},
132 » » tools.List{t100precise}, 141 » tools.List{t100precise32, t100quantal, t100quantal32},
133 » » tools.List{t100precise32, t100quantal, t100quantal32}, 142 }, {
134 » }, { 143 » t100all,
135 » » t100all, 144 » tools.List{t100precise32, t100quantal, t100quantal32},
136 » » tools.List{t100precise32, t100quantal, t100quantal32}, 145 » tools.List{t100precise},
137 » » tools.List{t100precise}, 146 }, {
138 » }, { 147 » t100all, t190all, t100all,
139 » » t100all, t190all, t100all, 148 }, {
140 » }, { 149 » t190all, t100all, t190all,
141 » » t190all, t100all, t190all, 150 }, {
142 » }, { 151 » extend(t100all, t190all),
143 » » extend(t100all, t190all), 152 » t190all,
144 » » t190all, 153 » t100all,
145 » » t100all, 154 }}
146 » }} { 155
147 » » c.Logf("test %d", i) 156 func (s *ListSuite) TestExclude(c *C) {
148 » » c.Check(test.src.Difference(test.arg), DeepEquals, test.expect) 157 » for i, test := range excludeTests {
149 » } 158 » » c.Logf("test %d", i)
150 } 159 » » c.Check(test.src.Exclude(test.arg), DeepEquals, test.expect)
151 160 » }
152 func (s *ListSuite) TestFilter(c *C) { 161 }
153 » for i, test := range []struct { 162
154 » » src tools.List 163 var matchTests = []struct {
155 » » filter tools.Filter 164 » src tools.List
156 » » expect tools.List 165 » filter tools.Filter
157 » }{{ 166 » expect tools.List
158 » » tools.List{t100precise}, 167 }{{
159 » » tools.Filter{}, 168 » tools.List{t100precise},
160 » » tools.List{t100precise}, 169 » tools.Filter{},
161 » }, { 170 » tools.List{t100precise},
162 » » tAll, 171 }, {
163 » » tools.Filter{}, 172 » tAll,
164 » » tAll, 173 » tools.Filter{},
165 » }, { 174 » tAll,
166 » » tAll, 175 }, {
167 » » tools.Filter{Released: true}, 176 » tAll,
168 » » t200all, 177 » tools.Filter{Released: true},
169 » }, { 178 » t200all,
170 » » t100all, 179 }, {
171 » » tools.Filter{Released: true}, 180 » t100all,
172 » » nil, 181 » tools.Filter{Released: true},
173 » }, { 182 » nil,
174 » » tAll, 183 }, {
175 » » tools.Filter{Number: version.MustParse("1.9.0")}, 184 » tAll,
176 » » t190all, 185 » tools.Filter{Number: version.MustParse("1.9.0")},
177 » }, { 186 » t190all,
178 » » tAll, 187 }, {
179 » » tools.Filter{Number: version.MustParse("1.9.0.1")}, 188 » tAll,
180 » » nil, 189 » tools.Filter{Number: version.MustParse("1.9.0.1")},
181 » }, { 190 » nil,
182 » » tAll, 191 }, {
183 » » tools.Filter{Series: "quantal"}, 192 » tAll,
184 » » tools.List{t100quantal, t100quantal32, t190quantal, t200quantal3 2}, 193 » tools.Filter{Series: "quantal"},
185 » }, { 194 » tools.List{t100quantal, t100quantal32, t190quantal, t200quantal32},
186 » » tAll, 195 }, {
187 » » tools.Filter{Series: "raring"}, 196 » tAll,
188 » » nil, 197 » tools.Filter{Series: "raring"},
189 » }, { 198 » nil,
190 » » tAll, 199 }, {
191 » » tools.Filter{Arch: "i386"}, 200 » tAll,
192 » » tools.List{t100precise32, t100quantal32, t190precise32, t200quan tal32}, 201 » tools.Filter{Arch: "i386"},
193 » }, { 202 » tools.List{t100precise32, t100quantal32, t190precise32, t200quantal32},
194 » » tAll, 203 }, {
195 » » tools.Filter{Arch: "arm"}, 204 » tAll,
196 » » nil, 205 » tools.Filter{Arch: "arm"},
197 » }, { 206 » nil,
198 » » tAll, 207 }, {
199 » » tools.Filter{ 208 » tAll,
200 » » » Released: true, 209 » tools.Filter{
201 » » » Number: version.MustParse("2.0.0"), 210 » » Released: true,
202 » » » Series: "quantal", 211 » » Number: version.MustParse("2.0.0"),
203 » » » Arch: "i386", 212 » » Series: "quantal",
204 » » }, 213 » » Arch: "i386",
205 » » tools.List{t200quantal32}, 214 » },
206 » }} { 215 » tools.List{t200quantal32},
thumper 2013/04/10 04:32:51 This line does my head in. I do find it easier to
rog 2013/04/10 08:30:32 +1. i prefer the tests to be outside the function
TheMue 2013/04/10 09:25:00 And another +1.
fwereade 2013/04/10 23:07:30 Public opinion is clearly against me here, so I'll
207 » » c.Logf("test %d", i) 216 }}
208 » » actual, err := test.src.Filter(test.filter) 217
218 func (s *ListSuite) TestMatch(c *C) {
219 » for i, test := range matchTests {
220 » » c.Logf("test %d", i)
221 » » actual, err := test.src.Match(test.filter)
209 c.Check(actual, DeepEquals, test.expect) 222 c.Check(actual, DeepEquals, test.expect)
210 if len(test.expect) > 0 { 223 if len(test.expect) > 0 {
211 c.Check(err, IsNil) 224 c.Check(err, IsNil)
212 } else { 225 } else {
213 c.Check(err, Equals, tools.ErrNoMatches) 226 c.Check(err, Equals, tools.ErrNoMatches)
214 } 227 }
215 } 228 }
216 } 229 }
LEFTRIGHT

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b