OLD | NEW |
1 package types | 1 package types |
2 | 2 |
3 import ( | 3 import ( |
| 4 "net/url" |
4 "testing" | 5 "testing" |
5 | 6 |
6 "skia.googlesource.com/buildbot.git/perf/go/config" | 7 "skia.googlesource.com/buildbot.git/perf/go/config" |
7 ) | 8 ) |
8 | 9 |
9 func TestMerge(t *testing.T) { | 10 func TestMerge(t *testing.T) { |
10 t1 := NewTile() | 11 t1 := NewTile() |
11 t1.Scale = 1 | 12 t1.Scale = 1 |
12 t1.TileIndex = 20 | 13 t1.TileIndex = 20 |
13 t1.Commits[1].Hash = "hash1" | 14 t1.Commits[1].Hash = "hash1" |
(...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
318 } | 319 } |
319 t2, err = t1.Trim(-1, 1) | 320 t2, err = t1.Trim(-1, 1) |
320 if err == nil { | 321 if err == nil { |
321 t.Errorf("Failed to raise error on Trim(-1, 1).") | 322 t.Errorf("Failed to raise error on Trim(-1, 1).") |
322 } | 323 } |
323 t2, err = t1.Trim(0, config.TILE_SIZE+1) | 324 t2, err = t1.Trim(0, config.TILE_SIZE+1) |
324 if err == nil { | 325 if err == nil { |
325 t.Errorf("Failed to raise error on Trim(0, config.TILE_SIZE+1)."
) | 326 t.Errorf("Failed to raise error on Trim(0, config.TILE_SIZE+1)."
) |
326 } | 327 } |
327 } | 328 } |
| 329 |
| 330 func TestMatchesWithIgnore(t *testing.T) { |
| 331 tr := NewPerfTrace() |
| 332 tr.Params_["p1"] = "v1" |
| 333 tr.Params_["p2"] = "v2" |
| 334 |
| 335 testCases := []struct { |
| 336 q url.Values |
| 337 ignore []url.Values |
| 338 want bool |
| 339 }{ |
| 340 // Empty case. |
| 341 { |
| 342 q: url.Values{}, |
| 343 ignore: []url.Values{}, |
| 344 want: true, |
| 345 }, |
| 346 // Only ignore. |
| 347 { |
| 348 q: url.Values{}, |
| 349 ignore: []url.Values{ |
| 350 url.Values{}, |
| 351 url.Values{"p2": []string{"v2"}}, |
| 352 }, |
| 353 want: false, |
| 354 }, |
| 355 // Not match query. |
| 356 { |
| 357 q: url.Values{"p1": []string{"bad"}}, |
| 358 ignore: []url.Values{}, |
| 359 want: false, |
| 360 }, |
| 361 // Match query, fail to match ignore. |
| 362 { |
| 363 q: url.Values{"p1": []string{"v1"}}, |
| 364 ignore: []url.Values{ |
| 365 url.Values{"p1": []string{"bad"}}, |
| 366 }, |
| 367 want: true, |
| 368 }, |
| 369 // Match query, and match ignore. |
| 370 { |
| 371 q: url.Values{"p1": []string{"v1"}}, |
| 372 ignore: []url.Values{ |
| 373 url.Values{"p1": []string{"v1"}}, |
| 374 }, |
| 375 want: false, |
| 376 }, |
| 377 // Match query, and match one of many ignores. |
| 378 { |
| 379 q: url.Values{"p1": []string{"v1"}}, |
| 380 ignore: []url.Values{ |
| 381 url.Values{}, |
| 382 url.Values{"p1": []string{"v1"}}, |
| 383 }, |
| 384 want: false, |
| 385 }, |
| 386 } |
| 387 |
| 388 for _, tc := range testCases { |
| 389 if got, want := MatchesWithIgnores(tr, tc.q, tc.ignore...), tc.w
ant; got != want { |
| 390 t.Errorf("MatchesWithIgnores(%v, %v, %v): Got %v Want %v
", tr, tc.q, tc.ignore, got, want) |
| 391 } |
| 392 } |
| 393 } |
OLD | NEW |