traefik/pkg/testhelpers/helpers.go

27 lines
624 B
Go
Raw Normal View History

package testhelpers
import (
"fmt"
"io"
"net/http"
2017-06-03 13:02:28 +00:00
"net/url"
)
2020-05-11 10:06:07 +00:00
// MustNewRequest creates a new http get request or panics if it can't.
func MustNewRequest(method, urlStr string, body io.Reader) *http.Request {
request, err := http.NewRequest(method, urlStr, body)
if err != nil {
panic(fmt.Sprintf("failed to create HTTP %s Request for '%s': %s", method, urlStr, err))
}
return request
}
2017-06-03 13:02:28 +00:00
2020-05-11 10:06:07 +00:00
// MustParseURL parses a URL or panics if it can't.
2017-06-03 13:02:28 +00:00
func MustParseURL(rawURL string) *url.URL {
u, err := url.Parse(rawURL)
if err != nil {
panic(fmt.Sprintf("failed to parse URL '%s': %s", rawURL, err))
}
return u
}