package test
import "github.com/Azure/azure-sdk-for-go/sdk/messaging/azeventhubs/internal/test"
Index ¶
- Variables
- func CaptureLogsForTest() func() []string
- func CaptureLogsForTestWithChannel(messagesCh chan string) func() []string
- func EnableStdoutLogging()
- func NewContextWithTimeoutForTests(parent context.Context, timeout time.Duration) (context.Context, context.CancelFunc)
- func RandomString(prefix string, length int) string
- func RequireClose[T interface { Close(ctx context.Context) error }](t *testing.T, closeable T)
- func RequireContextHasDefaultTimeout(t *testing.T, ctx context.Context, timeout time.Duration)
- func RequireNSClose(t *testing.T, closeable interface { Close(ctx context.Context, permanent bool) error })
- func URLJoinPaths(base string, subPath string) string
- type ConnectionParamsForTest
- func GetConnectionParamsForTest(t *testing.T) ConnectionParamsForTest
- func (c ConnectionParamsForTest) CS(t *testing.T) struct{ Primary, ListenOnly, SendOnly, Storage string }
- type ContextCancelledMatcher
- func (m ContextCancelledMatcher) Matches(x any) bool
- func (m ContextCancelledMatcher) String() string
- type ContextHasTestValueMatcher
Variables ¶
var Cancelled gomock.Matcher = ContextCancelledMatcher{true}
Cancelled matches context.Context instances that are cancelled.
var CancelledAndHasTimeout gomock.Matcher = gomock.All(ContextCancelledMatcher{true}, ContextHasTestValueMatcher{})
CancelledAndHasTimeout matches context.Context instances that are cancelled AND were also created from NewContextForTest.
var NotCancelled gomock.Matcher = ContextCancelledMatcher{false}
NotCancelled matches context.Context instances that are not cancelled.
var NotCancelledAndHasTimeout gomock.Matcher = gomock.All(ContextCancelledMatcher{false}, ContextHasTestValueMatcher{})
NotCancelledAndHasTimeout matches context.Context instances that are not cancelled AND were also created from NewContextForTest.
Functions ¶
func CaptureLogsForTest ¶
func CaptureLogsForTest() func() []string
CaptureLogsForTest adds a logging listener which captures messages to an internal channel. Returns a function that ends log capturing and returns any captured messages. It's safe to call endCapture() multiple times, so a simple call pattern is:
endCapture := CaptureLogsForTest() defer endCapture() // ensure cleanup in case of test assert failures /* some test code */ messages := endCapture() /* do inspection of log messages */
func CaptureLogsForTestWithChannel ¶
func EnableStdoutLogging ¶
func EnableStdoutLogging()
EnableStdoutLogging turns on logging to stdout for diagnostics.
func NewContextWithTimeoutForTests ¶
func NewContextWithTimeoutForTests(parent context.Context, timeout time.Duration) (context.Context, context.CancelFunc)
NewContextWithTimeoutForTests creates a context with a lower timeout than requested just to keep unit test times reasonable.
It validates that the passed in timeout is the actual defaultCloseTimeout and also adds in a testContextKey(0) as a value, which can be used to verify that the context has been properly propagated.
func RandomString ¶
RandomString generates a random string with prefix
func RequireClose ¶
func RequireContextHasDefaultTimeout ¶
RequireContextHasDefaultTimeout checks that the context has a deadline set, and that it's using the right timeout. NOTE: There's some wiggle room since some time will expire before this is called.
func RequireNSClose ¶
func RequireNSClose(t *testing.T, closeable interface { Close(ctx context.Context, permanent bool) error })
func URLJoinPaths ¶
Types ¶
type ConnectionParamsForTest ¶
type ConnectionParamsForTest struct { ClientID string Cred azcore.TokenCredential EventHubName string EventHubLinksOnlyName string EventHubNamespace string StorageEndpoint string ResourceGroup string SubscriptionID string TenantID string }
func GetConnectionParamsForTest ¶
func GetConnectionParamsForTest(t *testing.T) ConnectionParamsForTest
func (ConnectionParamsForTest) CS ¶
func (c ConnectionParamsForTest) CS(t *testing.T) struct{ Primary, ListenOnly, SendOnly, Storage string }
type ContextCancelledMatcher ¶
type ContextCancelledMatcher struct { // WantCancelled should be set if we expect the context should // be cancelled. If true, we check if Err() != nil, if false we check // that it's nil. WantCancelled bool }
func (ContextCancelledMatcher) Matches ¶
func (m ContextCancelledMatcher) Matches(x any) bool
Matches returns whether x is a match.
func (ContextCancelledMatcher) String ¶
func (m ContextCancelledMatcher) String() string
String describes what the matcher matches.
type ContextHasTestValueMatcher ¶
type ContextHasTestValueMatcher struct{}
func (ContextHasTestValueMatcher) Matches ¶
func (m ContextHasTestValueMatcher) Matches(x any) bool
func (ContextHasTestValueMatcher) String ¶
func (m ContextHasTestValueMatcher) String() string
Source Files ¶
mock_helpers.go test_helpers.go
- Version
- v1.3.0 (latest)
- Published
- Feb 8, 2025
- Platform
- linux/amd64
- Imports
- 17 packages
- Last checked
- 4 months ago –
Tools for package owners.