Documentation
¶
Overview ¶
Package testutil provides test assertion helpers and sample data fixtures.
Index ¶
- func CaptureStdout(t testing.TB, f func()) string
- func Contains(t testing.TB, s, substr string)
- func Empty(t testing.TB, s string)
- func Equal[T comparable](t testing.TB, got, want T)
- func Error(t testing.TB, err error)
- func ErrorIs(t testing.TB, err, target error)
- func False(t testing.TB, condition bool)
- func Greater(t testing.TB, a, b int)
- func GreaterOrEqual(t testing.TB, a, b int)
- func Len[T any](t testing.TB, slice []T, want int)
- func LenSlice(t testing.TB, length, want int)
- func Less(t testing.TB, a, b int)
- func Nil(t testing.TB, val any)
- func NoError(t testing.TB, err error)
- func NotContains(t testing.TB, s, substr string)
- func NotEmpty(t testing.TB, s string)
- func NotNil(t testing.TB, val any)
- func SampleAttachment(filename string) *gmailapi.Attachment
- func SampleCalendar(id string, primary bool) *calendar.CalendarListEntry
- func SampleCalendars() []*calendar.CalendarListEntry
- func SampleContact(resourceName string) *contactsapi.Contact
- func SampleContactGroup(resourceName string) *contactsapi.ContactGroup
- func SampleDriveFile(id string) *driveapi.File
- func SampleDriveFiles(count int) []*driveapi.File
- func SampleEvent(id string) *calendar.Event
- func SampleGoogleDoc(id string) *driveapi.File
- func SampleLabels() []*gmail.Label
- func SampleMessage(id string) *gmailapi.Message
- func SampleMessages(count int) []*gmailapi.Message
- func SampleParsedEvent(id string) *calendarapi.Event
- func SamplePerson(resourceName string) *people.Person
- func SampleProfile() *gmailapi.Profile
- func SampleSharedDrive(id, name string) *driveapi.SharedDrive
- func SampleSharedDriveFile(id, driveID string) *driveapi.File
- func SampleSharedDrives() []*driveapi.SharedDrive
- func SliceContains[T comparable](t testing.TB, slice []T, target T)
- func True(t testing.TB, condition bool)
- func WithFactory[T any](factoryPtr *T, replacement T, f func())
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CaptureStdout ¶ added in v1.0.35
CaptureStdout captures everything written to os.Stdout during the execution of f and returns it as a string. This is useful for testing commands that print output directly to stdout.
func Equal ¶ added in v1.0.35
func Equal[T comparable](t testing.TB, got, want T)
Equal checks that got equals want using comparable constraint.
func GreaterOrEqual ¶ added in v1.0.35
GreaterOrEqual checks that a >= b.
func LenSlice ¶ added in v1.0.35
LenSlice checks that an arbitrary slice has the expected length. Use this when Len's type parameter cannot be inferred.
func Nil ¶ added in v1.0.35
Nil checks that val is nil. Uses reflection to handle nil slices, maps, pointers, channels, and functions that appear non-nil when boxed into an interface.
func NotContains ¶ added in v1.0.35
NotContains checks that s does not contain substr.
func SampleAttachment ¶
func SampleAttachment(filename string) *gmailapi.Attachment
SampleAttachment returns a sample attachment for testing
func SampleCalendar ¶
func SampleCalendar(id string, primary bool) *calendar.CalendarListEntry
SampleCalendar returns a sample calendar for testing
func SampleCalendars ¶
func SampleCalendars() []*calendar.CalendarListEntry
SampleCalendars returns sample calendars for testing
func SampleContact ¶
func SampleContact(resourceName string) *contactsapi.Contact
SampleContact returns a parsed contact for testing
func SampleContactGroup ¶
func SampleContactGroup(resourceName string) *contactsapi.ContactGroup
SampleContactGroup returns a sample contact group for testing
func SampleDriveFile ¶
SampleDriveFile returns a sample Drive file for testing
func SampleDriveFiles ¶
SampleDriveFiles returns sample Drive files for testing
func SampleEvent ¶
SampleEvent returns a sample calendar event for testing
func SampleGoogleDoc ¶
SampleGoogleDoc returns a Google Doc file for testing export scenarios
func SampleLabels ¶
SampleLabels returns sample Gmail labels for testing
func SampleMessage ¶
SampleMessage returns a sample Gmail message for testing
func SampleMessages ¶
SampleMessages returns a slice of sample messages
func SampleParsedEvent ¶
func SampleParsedEvent(id string) *calendarapi.Event
SampleParsedEvent returns a parsed calendar event for testing
func SamplePerson ¶
SamplePerson returns a sample Google People API Person for testing
func SampleProfile ¶
SampleProfile returns a sample Gmail profile for testing
func SampleSharedDrive ¶ added in v1.0.32
func SampleSharedDrive(id, name string) *driveapi.SharedDrive
SampleSharedDrive returns a sample shared drive for testing
func SampleSharedDriveFile ¶ added in v1.0.32
SampleSharedDriveFile returns a file that belongs to a shared drive
func SampleSharedDrives ¶ added in v1.0.32
func SampleSharedDrives() []*driveapi.SharedDrive
SampleSharedDrives returns a set of sample shared drives for testing
func SliceContains ¶ added in v1.0.35
func SliceContains[T comparable](t testing.TB, slice []T, target T)
SliceContains checks that the slice contains the target value.
func WithFactory ¶ added in v1.0.35
func WithFactory[T any](factoryPtr *T, replacement T, f func())
WithFactory temporarily replaces a factory function variable with a replacement value, executes f, then restores the original. This is the generic building block for per-package withMockClient helpers.
Usage:
testutil.WithFactory(&ClientFactory, mockFactory, func() {
// ClientFactory now returns the mock
})
Types ¶
This section is empty.