Documentation ¶
Index ¶
- func CloseAndRemove(t *testing.T, files ...*os.File)
- func MkTmpdir(prefix string) (string, error)
- func MkTmpdirOrDie(prefix string) string
- type FakeHandler
- func (f *FakeHandler) ServeHTTP(response http.ResponseWriter, request *http.Request)
- func (f *FakeHandler) SetResponseBody(responseBody string)
- func (f *FakeHandler) ValidateRequest(t TestInterface, expectedPath, expectedMethod string, body *string)
- func (f *FakeHandler) ValidateRequestCount(t TestInterface, count int) bool
- type FakeOpenAPIServer
- type LogInterface
- type TestInterface
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CloseAndRemove ¶ added in v0.28.0
CloseAndRemove is a helper to close and remove test file.
func MkTmpdir ¶
MkTmpdir creates a temporary directory based upon the prefix passed in. If successful, it returns the temporary directory path. The directory can be deleted with a call to "os.RemoveAll(...)". In case of error, it'll return an empty string and the error.
func MkTmpdirOrDie ¶
MkTmpdirOrDie does the same work as "MkTmpdir", except in case of errors, it'll trigger a panic.
Types ¶
type FakeHandler ¶
type FakeHandler struct { RequestReceived *http.Request RequestBody string StatusCode int ResponseBody string // For logging - you can use a *testing.T // This will keep log messages associated with the test. T LogInterface SkipRequestFn func(verb string, url url.URL) bool // contains filtered or unexported fields }
FakeHandler is to assist in testing HTTP requests. Notice that FakeHandler is not thread safe and you must not direct traffic to except for the request you want to test. You can do this by hiding it in an http.ServeMux.
func (*FakeHandler) ServeHTTP ¶
func (f *FakeHandler) ServeHTTP(response http.ResponseWriter, request *http.Request)
func (*FakeHandler) SetResponseBody ¶
func (f *FakeHandler) SetResponseBody(responseBody string)
func (*FakeHandler) ValidateRequest ¶
func (f *FakeHandler) ValidateRequest(t TestInterface, expectedPath, expectedMethod string, body *string)
ValidateRequest verifies that FakeHandler received a request with expected path, method, and body.
func (*FakeHandler) ValidateRequestCount ¶
func (f *FakeHandler) ValidateRequestCount(t TestInterface, count int) bool
type FakeOpenAPIServer ¶ added in v0.24.0
type FakeOpenAPIServer struct { HttpServer *httptest.Server ServedDocuments map[string]*spec3.OpenAPI RequestCounters map[string]int }
func NewFakeOpenAPIV3Server ¶ added in v0.24.0
func NewFakeOpenAPIV3Server(specsPath string) (*FakeOpenAPIServer, error)
Creates a mock OpenAPIV3 server as it would be on a standing kubernetes API server.
specsPath - Give a path to some test data organized so that each GroupVersion has its own OpenAPI V3 JSON file.
i.e. apps/v1beta1 is stored in <specsPath>/apps/v1beta1.json
type LogInterface ¶
type LogInterface interface {
Logf(format string, args ...interface{})
}
LogInterface is a simple interface to allow injection of Logf to report serving errors.
type TestInterface ¶
type TestInterface interface { Errorf(format string, args ...interface{}) Logf(format string, args ...interface{}) }
TestInterface is a simple interface providing Errorf, to make injection for testing easier (insert 'yo dawg' meme here).