testutil

package
v0.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 19, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

Package testutil provides test assertion helpers and sample data fixtures.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CaptureStdout

func CaptureStdout(t testing.TB, f func()) string

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 Contains

func Contains(t testing.TB, s, substr string)

Contains checks that s contains substr.

func Empty

func Empty(t testing.TB, s string)

Empty checks that s is the empty string.

func Equal

func Equal[T comparable](t testing.TB, got, want T)

Equal checks that got equals want using comparable constraint.

func Error

func Error(t testing.TB, err error)

Error checks that err is not nil.

func ErrorIs

func ErrorIs(t testing.TB, err, target error)

ErrorIs checks that err matches target using errors.Is.

func False

func False(t testing.TB, condition bool)

False checks that condition is false.

func Greater

func Greater(t testing.TB, a, b int)

Greater checks that a > b.

func GreaterOrEqual

func GreaterOrEqual(t testing.TB, a, b int)

GreaterOrEqual checks that a >= b.

func Len

func Len[T any](t testing.TB, slice []T, want int)

Len checks that the slice has the expected length.

func LenSlice

func LenSlice(t testing.TB, length, want int)

LenSlice checks that an arbitrary slice has the expected length. Use this when Len's type parameter cannot be inferred.

func Less

func Less(t testing.TB, a, b int)

Less checks that a < b.

func Nil

func Nil(t testing.TB, val any)

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 NoError

func NoError(t testing.TB, err error)

NoError fails the test immediately if err is not nil.

func NotContains

func NotContains(t testing.TB, s, substr string)

NotContains checks that s does not contain substr.

func NotEmpty

func NotEmpty(t testing.TB, s string)

NotEmpty checks that s is not the empty string.

func NotNil

func NotNil(t testing.TB, val any)

NotNil fails the test immediately if val is nil.

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

func SampleDriveFile(id string) *driveapi.File

SampleDriveFile returns a sample Drive file for testing

func SampleDriveFiles

func SampleDriveFiles(count int) []*driveapi.File

SampleDriveFiles returns sample Drive files for testing

func SampleEvent

func SampleEvent(id string) *calendar.Event

SampleEvent returns a sample calendar event for testing

func SampleGoogleDoc

func SampleGoogleDoc(id string) *driveapi.File

SampleGoogleDoc returns a Google Doc file for testing export scenarios

func SampleLabels

func SampleLabels() []*gmail.Label

SampleLabels returns sample Gmail labels for testing

func SampleMessage

func SampleMessage(id string) *gmailapi.Message

SampleMessage returns a sample Gmail message for testing

func SampleMessages

func SampleMessages(count int) []*gmailapi.Message

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

func SamplePerson(resourceName string) *people.Person

SamplePerson returns a sample Google People API Person for testing

func SampleProfile

func SampleProfile() *gmailapi.Profile

SampleProfile returns a sample Gmail profile for testing

func SampleSharedDrive

func SampleSharedDrive(id, name string) *driveapi.SharedDrive

SampleSharedDrive returns a sample shared drive for testing

func SampleSharedDriveFile

func SampleSharedDriveFile(id, driveID string) *driveapi.File

SampleSharedDriveFile returns a file that belongs to a shared drive

func SampleSharedDrives

func SampleSharedDrives() []*driveapi.SharedDrive

SampleSharedDrives returns a set of sample shared drives for testing

func SliceContains

func SliceContains[T comparable](t testing.TB, slice []T, target T)

SliceContains checks that the slice contains the target value.

func True

func True(t testing.TB, condition bool)

True checks that condition is true.

func WithFactory

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL