Documentation
¶
Index ¶
- func AddServices(t testing.TB, srv *testutil.TestServer, svcs []testutil.TestService)
- func CheckDir(t testing.TB, exists bool, dir string) []os.FileInfo
- func CheckFile(t testing.TB, exists bool, path, filename string) string
- func CheckStateFile(t *testing.T, consulAddr, taskname string)
- func ConsulServiceRegistered(tb testing.TB, srv *testutil.TestServer, serviceID string) bool
- func CopyFile(t testing.TB, src, dst string)
- func CopyFiles(t testing.TB, srcFiles []string, dst string)
- func DeleteKV(tb testing.TB, srv *testutil.TestServer, key string)
- func DeregisterConsulService(tb testing.TB, srv *testutil.TestServer, id string)
- func FindFileMatches(t testing.TB, rootDir, pattern string) []string
- func FreePort(t testing.TB) int
- func ListConsulChecks(tb testing.TB, srv *testutil.TestServer) map[string]ConsulCheck
- func ListConsulServices(tb testing.TB, srv *testutil.TestServer, filter string) map[string]ConsulService
- func MakeTempDir(t testing.TB, tempDir string) func() error
- func NewHttpClient(t *testing.T, intercepts []*HttpIntercept) *http.Client
- func NewTestConsulServer(tb testing.TB, config TestConsulServerConfig) *testutil.TestServer
- func RegisterConsulService(tb testing.TB, srv *testutil.TestServer, s testutil.TestService, ...)
- func RegisterConsulServiceHealth(tb testing.TB, srv *testutil.TestServer, s testutil.TestService, ...)
- func RequestHTTP(t testing.TB, method, url, body string) *http.Response
- func RequestHTTPS(t testing.TB, method, url, body string, conf TLSConfig) *http.Response
- func RequestJSON(t testing.TB, method, url string, body interface{}) *http.Response
- func Setenv(envvar, value string) func()
- func ShowMeHealth(t testing.TB, srv *testutil.TestServer, svcName string)
- func ShowMeServices(t testing.TB, srv *testutil.TestServer)
- func TestServices(n int) []testutil.TestService
- func WaitForConsulServiceDeregistered(tb testing.TB, srv *testutil.TestServer, serviceID string, wait time.Duration)
- func WaitForConsulServiceRegistered(tb testing.TB, srv *testutil.TestServer, serviceID string, wait time.Duration)
- func WaitForHttpStatusChange(ctx context.Context, pollInterval time.Duration, method, url, body string, ...) (*http.Response, error)
- func WriteFile(t testing.TB, path, content string)
- type ConsulCheck
- type ConsulService
- type HttpIntercept
- type TLSConfig
- type TestConsulServerConfig
- type TestingTB
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AddServices ¶ added in v0.1.3
func AddServices(t testing.TB, srv *testutil.TestServer, svcs []testutil.TestService)
Bulk add test data for seeding consul
func CheckDir ¶ added in v0.2.0
CheckDir checks whether a directory exists. If it exists, returns the file infos for further checking.
func CheckFile ¶ added in v0.2.0
CheckFile checks whether a file exists or not. If it exists, returns the contents for further checking. If path parameter already includes filename, leave filename parameter as an empty string.
func CheckStateFile ¶ added in v0.1.3
CheckStateFile checks statefile in the default Terraform backend ConsulKV.
func ConsulServiceRegistered ¶ added in v0.6.0
ConsulServiceRegistered returns whether the Consul service with the given ID is registered or not.
func DeregisterConsulService ¶
func DeregisterConsulService(tb testing.TB, srv *testutil.TestServer, id string)
func FindFileMatches ¶ added in v0.4.2
FindFileMatches walks a root directory and returns a list of all files that match a particular pattern string. E.g. If you want to find all files that end with .txt, pattern=*.txt
func FreePort ¶ added in v0.1.3
FreePort finds the next free port incrementing upwards. Use for testing.
func ListConsulChecks ¶ added in v0.6.0
func ListConsulChecks(tb testing.TB, srv *testutil.TestServer) map[string]ConsulCheck
ListConsulChecks returns a list of checks from a Consul agent.
func ListConsulServices ¶ added in v0.6.0
func ListConsulServices(tb testing.TB, srv *testutil.TestServer, filter string) map[string]ConsulService
ListConsulServices returns a list of services registered with the Consul agent.
func MakeTempDir ¶
MakeTempDir creates a directory in the current path for a test. Caller is responsible for managing the uniqueness of the directory name. Returns a function for the caller to delete the temporary directory.
func NewHttpClient ¶ added in v0.6.0
func NewHttpClient(t *testing.T, intercepts []*HttpIntercept) *http.Client
NewHttpClient returns an HTTP client that returns mocked responses to specific request paths based on the specified intercepts.
func NewTestConsulServer ¶ added in v0.1.1
func NewTestConsulServer(tb testing.TB, config TestConsulServerConfig) *testutil.TestServer
NewTestConsulServer starts a test Consul server as configured
func RegisterConsulService ¶
func RegisterConsulService(tb testing.TB, srv *testutil.TestServer, s testutil.TestService, wait time.Duration)
RegisterConsulService regsiters a service to the Consul Catalog. The Consul sdk/testutil package currently does not support a method to register multiple service instances, distinguished by their IDs.
func RegisterConsulServiceHealth ¶ added in v0.4.0
func RegisterConsulServiceHealth(tb testing.TB, srv *testutil.TestServer, s testutil.TestService, wait time.Duration, health string)
RegisterConsulServiceHealth is similar to RegisterConsulService and also sets the health status of the service.
func RequestHTTP ¶
RequestHTTP makes an http request. The caller is responsible for closing the response.
func RequestHTTPS ¶ added in v0.6.0
RequestHTTPS makes an https request using TLS. The caller is responsible for closing the response.
func RequestJSON ¶ added in v0.5.0
RequestJSON encodes the body to JSON and makes an HTTP request. The caller is responsible for closing the response.
func Setenv ¶ added in v0.3.0
func Setenv(envvar, value string) func()
Setenv sets an environment variable to a value. Returns a reset function to reset the environment variable back to the original state.
func ShowMeHealth ¶ added in v0.1.3
func ShowMeHealth(t testing.TB, srv *testutil.TestServer, svcName string)
Health status for all services
func ShowMeServices ¶ added in v0.1.3
func ShowMeServices(t testing.TB, srv *testutil.TestServer)
All registered services
func TestServices ¶ added in v0.1.3
func TestServices(n int) []testutil.TestService
Generate service TestService entries. Services with different IDs and Names.
func WaitForConsulServiceDeregistered ¶ added in v0.6.0
func WaitForConsulServiceDeregistered(tb testing.TB, srv *testutil.TestServer, serviceID string, wait time.Duration)
WaitForConsulServiceDeregistered polls Consul until the given service is deregistered or the timeout is reached.
func WaitForConsulServiceRegistered ¶ added in v0.6.0
func WaitForConsulServiceRegistered(tb testing.TB, srv *testutil.TestServer, serviceID string, wait time.Duration)
WaitForConsulServiceRegistered polls Consul until the given service is registered or the timeout is reached.
func WaitForHttpStatusChange ¶ added in v0.7.0
func WaitForHttpStatusChange(ctx context.Context, pollInterval time.Duration, method, url, body string, oldStatus, newStatus int) (*http.Response, error)
WaitForHttpStatusChange performs a blocking http call every pollInterval and returns the response whenever it encounters a StatusCode of newStatus. Any StatusCode other than oldStatus or newStatus will return an error immediately. It is the caller's responsibility to:
- prevent an infinite loop by eventually cancelling the context
- close the response
Types ¶
type ConsulCheck ¶ added in v0.6.0
type ConsulCheck struct { CheckID string Name string Status string Notes string Output string ServiceID string ServiceName string ServiceTags []string Type string }
ConsulCheck represents a Consul check with a subset of its attributes that are verified by the tests.
func WaitForConsulCheckStatus ¶ added in v0.6.0
func WaitForConsulCheckStatus(tb testing.TB, srv *testutil.TestServer, checkID, status string, wait time.Duration) (ConsulCheck, error)
WaitForConsulCheckStatus polls a Consul check until the check has the given status or the timeout is reached.
type ConsulService ¶ added in v0.6.0
ConsulService represents a Consul service with a subset of its attributes that are verified by the tests.
func GetConsulService ¶ added in v0.6.0
func GetConsulService(tb testing.TB, srv *testutil.TestServer, serviceID string) (ConsulService, error)
GetConsulService returns a service instance with the given ID from the Consul agent.
type HttpIntercept ¶ added in v0.6.0
type HttpIntercept struct { Path string RequestTest func(*testing.T, *http.Request) ResponseStatusCode int ResponseData []byte }
HttpIntercept represents a mapping of a path to the response that the HTTP client should return for requests to that path (including query parameters).
type TestConsulServerConfig ¶ added in v0.1.1
type TestConsulServerConfig struct { HTTPSRelPath string PortHTTP int // random port will be generated if unset PortHTTPS int // random port will be generated if unset }
TestConsulServerConfig configures a test Consul server
type TestingTB ¶
TestingTB implements Consul's testutil.TestingTB
func (*TestingTB) Cleanup ¶
func (t *TestingTB) Cleanup(f func())
Cleanup implements Consul's testutil.TestingTB's Cleanup()
func (*TestingTB) DoCleanup ¶
func (t *TestingTB) DoCleanup()
DoCleanup implements Consul's testutil.TestingTB's DoCleanup()