testutil.go 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. // Copyright 2015 CoreOS, Inc.
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. package testutil
  15. import (
  16. "net/url"
  17. "runtime"
  18. "testing"
  19. )
  20. // WARNING: This is a hack.
  21. // Remove this when we are able to block/check the status of the go-routines.
  22. func ForceGosched() {
  23. // possibility enough to sched up to 10 go routines.
  24. for i := 0; i < 10000; i++ {
  25. runtime.Gosched()
  26. }
  27. }
  28. func MustNewURLs(t *testing.T, urls []string) []url.URL {
  29. if urls == nil {
  30. return nil
  31. }
  32. var us []url.URL
  33. for _, url := range urls {
  34. u := MustNewURL(t, url)
  35. us = append(us, *u)
  36. }
  37. return us
  38. }
  39. func MustNewURL(t *testing.T, s string) *url.URL {
  40. u, err := url.Parse(s)
  41. if err != nil {
  42. t.Fatalf("parse %v error: %v", s, err)
  43. }
  44. return u
  45. }