pkg/testutils¶
Testing helpers that reduce boilerplate when working with temporary files and structured assertions.
Helpers¶
MustMakeTempFile(t, dir, pattern) *os.File¶
- Creates a file using
os.CreateTemp. - Fails the test via
assert.Failif creation fails. - Closes the returned file automatically; reopen with
os.Openif you need to append later.
AssertValidUUID(t, value, fieldName)¶
- Delegates to
uuid.Parse. - Fails the test with a friendly message that includes
fieldName.
ContainsAllRunes(t, str, chars, msgAndArgs...)¶
- Ensures every rune in
charsexists at least once instr. - Useful for asserting generated passwords or tokens meet composition rules.
Tips¶
- The helpers pull in
stretchr/testify/assert, so you can mix these with other testify assertions without additional setup. - When using
MustMakeTempFile, prefert.TempDir()so Go cleans up the directory after the test run.