Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(42)

Side by Side Diff: go/src/infra/appengine/test-results/model/aggregate_result_test.go

Issue 2234353002: test-results: package model: Add full_result.go and tests (Closed) Base URL: https://chromium.googlesource.com/infra/infra.git@master
Patch Set: Improve coverage Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 package model 1 package model
2 2
3 import ( 3 import (
4 "bytes" 4 "bytes"
5 "encoding/json" 5 "encoding/json"
6 "io/ioutil" 6 "io/ioutil"
7 "path/filepath" 7 "path/filepath"
8 "testing" 8 "testing"
9 9
10 . "github.com/smartystreets/goconvey/convey" 10 . "github.com/smartystreets/goconvey/convey"
11 ) 11 )
12 12
13 func TestCleanTestResultsJSON(t *testing.T) { 13 func TestCleanJSON(t *testing.T) {
14 » Convey("CleanTestResultsJSON", t, func() { 14 » Convey("CleanJSON", t, func() {
15 data := `{"foo":"bar"}` 15 data := `{"foo":"bar"}`
16 16
17 Convey("Strips prefix and suffix", func() { 17 Convey("Strips prefix and suffix", func() {
18 r := bytes.NewReader([]byte(`ADD_RESULTS(` + data + `);` )) 18 r := bytes.NewReader([]byte(`ADD_RESULTS(` + data + `);` ))
19 » » » res, err := CleanTestResultsJSON(r) 19 » » » res, err := CleanJSON(r)
20 So(err, ShouldBeNil) 20 So(err, ShouldBeNil)
21 b, err := ioutil.ReadAll(res) 21 b, err := ioutil.ReadAll(res)
22 So(err, ShouldBeNil) 22 So(err, ShouldBeNil)
23 So(string(b), ShouldEqual, data) 23 So(string(b), ShouldEqual, data)
24 }) 24 })
25 25
26 Convey("Returns original when prefix and suffix are absent", fun c() { 26 Convey("Returns original when prefix and suffix are absent", fun c() {
27 r := bytes.NewReader([]byte(data)) 27 r := bytes.NewReader([]byte(data))
28 » » » res, err := CleanTestResultsJSON(r) 28 » » » res, err := CleanJSON(r)
29 So(err, ShouldBeNil) 29 So(err, ShouldBeNil)
30 b, err := ioutil.ReadAll(res) 30 b, err := ioutil.ReadAll(res)
31 So(err, ShouldBeNil) 31 So(err, ShouldBeNil)
32 So(string(b), ShouldEqual, data) 32 So(string(b), ShouldEqual, data)
33 }) 33 })
34 }) 34 })
35 } 35 }
36 36
37 func TestResultSummary(t *testing.T) { 37 func TestResultSummary(t *testing.T) {
38 t.Parallel() 38 t.Parallel()
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after
254 254
255 Convey("secondsSinceEpoch", func() { 255 Convey("secondsSinceEpoch", func() {
256 Convey("Wrong secondsSinceEpoch element type", func() { 256 Convey("Wrong secondsSinceEpoch element type", func() {
257 tm["foo_builder"].(map[string]in terface{})["secondsSinceEpoch"] = 257 tm["foo_builder"].(map[string]in terface{})["secondsSinceEpoch"] =
258 []interface{}{1, 2, "a"} 258 []interface{}{1, 2, "a"}
259 b := marshal(tm) 259 b := marshal(tm)
260 err := json.Unmarshal(b, &t) 260 err := json.Unmarshal(b, &t)
261 So(err, ShouldNotBeNil) 261 So(err, ShouldNotBeNil)
262 }) 262 })
263 263
264 Convey("Wrong secondsSinceEpoch list typ e", func() {
265 tm["foo_builder"].(map[string]in terface{})["secondsSinceEpoch"] =
266 nil
267 b := marshal(tm)
268 err := json.Unmarshal(b, &t)
269 So(err, ShouldNotBeNil)
270 })
271
272 Convey("Valid secondsSinceEpoch", func() { 264 Convey("Valid secondsSinceEpoch", func() {
273 b := marshal(tm) 265 b := marshal(tm)
274 err := json.Unmarshal(b, &t) 266 err := json.Unmarshal(b, &t)
275 So(err, ShouldBeNil) 267 So(err, ShouldBeNil)
276 So(t.SecondsEpoch, ShouldResembl e, 268 So(t.SecondsEpoch, ShouldResembl e,
277 tm["foo_builder"].(map[s tring]interface{})["secondsSinceEpoch"]) 269 tm["foo_builder"].(map[s tring]interface{})["secondsSinceEpoch"])
278 }) 270 })
279 }) 271 })
280 272
281 Convey("blinkRevison", func() { 273 Convey("blinkRevison", func() {
282 Convey("Wrong blinkRevison element type" , func() { 274 Convey("Wrong blinkRevison element type" , func() {
283 tm["foo_builder"].(map[string]in terface{})["blinkRevision"] = 275 tm["foo_builder"].(map[string]in terface{})["blinkRevision"] =
284 []interface{}{"900", "ba d"} 276 []interface{}{"900", "ba d"}
285 b := marshal(tm) 277 b := marshal(tm)
286 err := json.Unmarshal(b, &t) 278 err := json.Unmarshal(b, &t)
287 So(err, ShouldNotBeNil) 279 So(err, ShouldNotBeNil)
288 }) 280 })
289 281
290 Convey("Wrong blinkRevision list type", func() {
291 tm["foo_builder"].(map[string]in terface{})["blinkRevision"] = nil
292 b := marshal(tm)
293 err := json.Unmarshal(b, &t)
294 So(err, ShouldNotBeNil)
295 })
296
297 Convey("Valid blinkRevision", func() { 282 Convey("Valid blinkRevision", func() {
298 b := marshal(tm) 283 b := marshal(tm)
299 err := json.Unmarshal(b, &t) 284 err := json.Unmarshal(b, &t)
300 So(err, ShouldBeNil) 285 So(err, ShouldBeNil)
301 » » » » » » So(t.BlinkRevs, ShouldResemble, []number{100, 200, 0, -50}) 286 » » » » » » So(t.BlinkRevs, ShouldResemble, []Number{100, 200, 0, -50})
302 }) 287 })
303 }) 288 })
304 289
305 Convey("buildNumbers", func() { 290 Convey("buildNumbers", func() {
306 Convey("Wrong buildNumbers element type" , func() { 291 Convey("Wrong buildNumbers element type" , func() {
307 tm["foo_builder"].(map[string]in terface{})["buildNumbers"] = 292 tm["foo_builder"].(map[string]in terface{})["buildNumbers"] =
308 []interface{}{"900", "ba d"} 293 []interface{}{"900", "ba d"}
309 b := marshal(tm) 294 b := marshal(tm)
310 err := json.Unmarshal(b, &t) 295 err := json.Unmarshal(b, &t)
311 So(err, ShouldNotBeNil) 296 So(err, ShouldNotBeNil)
312 }) 297 })
313 298
314 Convey("Wrong buildNumbers list type", f unc() { 299 Convey("Wrong buildNumbers list type", f unc() {
315 tm["foo_builder"].(map[string]in terface{})["buildNumbers"] = nil 300 tm["foo_builder"].(map[string]in terface{})["buildNumbers"] = nil
316 b := marshal(tm) 301 b := marshal(tm)
317 err := json.Unmarshal(b, &t) 302 err := json.Unmarshal(b, &t)
318 So(err, ShouldNotBeNil) 303 So(err, ShouldNotBeNil)
319 }) 304 })
320 305
321 Convey("Valid buildNumbers", func() { 306 Convey("Valid buildNumbers", func() {
322 b := marshal(tm) 307 b := marshal(tm)
323 err := json.Unmarshal(b, &t) 308 err := json.Unmarshal(b, &t)
324 So(err, ShouldBeNil) 309 So(err, ShouldBeNil)
325 » » » » » » So(t.BuildNumbers, ShouldResembl e, []number{9000, 7500, -42, 0}) 310 » » » » » » So(t.BuildNumbers, ShouldResembl e, []Number{9000, 7500, -42, 0})
326 }) 311 })
327 }) 312 })
328 313
329 Convey("chromeRevision", func() { 314 Convey("chromeRevision", func() {
330 Convey("Wrong chromeRevision element typ e", func() { 315 Convey("Wrong chromeRevision element typ e", func() {
331 tm["foo_builder"].(map[string]in terface{})["chromeRevision"] = 316 tm["foo_builder"].(map[string]in terface{})["chromeRevision"] =
332 []interface{}{"900", fal se, "str"} 317 []interface{}{"900", fal se, "str"}
333 b := marshal(tm) 318 b := marshal(tm)
334 err := json.Unmarshal(b, &t) 319 err := json.Unmarshal(b, &t)
335 So(err, ShouldNotBeNil) 320 So(err, ShouldNotBeNil)
336 }) 321 })
337 322
338 Convey("Wrong chromeRevision list type", func() {
339 tm["foo_builder"].(map[string]in terface{})["chromeRevision"] = nil
340 b := marshal(tm)
341 err := json.Unmarshal(b, &t)
342 So(err, ShouldNotBeNil)
343 })
344
345 Convey("Valid chromeRevision", func() { 323 Convey("Valid chromeRevision", func() {
346 b := marshal(tm) 324 b := marshal(tm)
347 err := json.Unmarshal(b, &t) 325 err := json.Unmarshal(b, &t)
348 So(err, ShouldBeNil) 326 So(err, ShouldBeNil)
349 So(t.ChromeRevs, ShouldResemble, 327 So(t.ChromeRevs, ShouldResemble,
350 []string{"10", "40", "90 0", "65536", "afd807a", "88da8f4"}, 328 []string{"10", "40", "90 0", "65536", "afd807a", "88da8f4"},
351 ) 329 )
352 }) 330 })
353 }) 331 })
354 332
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
428 So(err, ShouldBeNil) 406 So(err, ShouldBeNil)
429 407
430 So(json.Unmarshal(b, &actual), S houldBeNil) 408 So(json.Unmarshal(b, &actual), S houldBeNil)
431 So(actual, ShouldResemble, t) 409 So(actual, ShouldResemble, t)
432 }) 410 })
433 }) 411 })
434 }) 412 })
435 }) 413 })
436 }) 414 })
437 } 415 }
OLDNEW
« no previous file with comments | « go/src/infra/appengine/test-results/model/aggregate_result.go ('k') | go/src/infra/appengine/test-results/model/common.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698