go-tdd-patterns
# Go TDD Patterns & Best Practices
What this skill does
# Go TDD Patterns & Best Practices
This skill provides Go-specific testing patterns and conventions.
## When to Use
Activates when:
- Writing Go code
- Creating or modifying Go tests
- Reviewing Go test coverage
- Refactoring Go code
## Test Organization
### File Naming
- Unit tests: `*_test.go`
- Integration tests: `e2e_test.go` or `integration_test.go`
- Place tests alongside the code they test
### Test Function Naming
```go
func TestFunctionName(t *testing.T) // Basic test
func TestFunctionName_Scenario(t *testing.T) // Specific scenario
func TestFunctionName_EdgeCase(t *testing.T) // Edge case
```
## Table-Driven Tests
Use table-driven tests for multiple inputs/scenarios:
```go
func TestValidation(t *testing.T) {
tests := []struct {
name string
input string
want bool
wantErr error
}{
{
name: "valid input",
input: "test",
want: true,
wantErr: nil,
},
{
name: "empty input",
input: "",
want: false,
wantErr: ErrEmptyInput,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, err := Validate(tt.input)
if tt.wantErr != nil {
require.ErrorIs(t, err, tt.wantErr)
return
}
require.NoError(t, err)
assert.Equal(t, tt.want, got)
})
}
}
```
## Testify Assertions
### require vs assert
**Use `testify/require`** - Stop test execution on failure:
```go
require.NoError(t, err) // Stop if error
require.NotNil(t, result) // Stop if nil
require.Equal(t, expected, actual) // Stop if not equal
require.ErrorIs(t, err, ErrExpected) // Stop if wrong error
```
**Use `testify/assert`** - Continue test execution:
```go
assert.Equal(t, expected, actual) // Continue on failure
assert.True(t, condition) // Continue on failure
assert.Contains(t, slice, element) // Continue on failure
```
**Pattern:** Use `require` for prerequisites, `assert` for multiple checks
## Mock External Dependencies
Mock external dependencies for unit tests:
- Network calls
- Filesystem operations
- Time-dependent code
- External services
```go
type mockClient struct {
mock.Mock
}
func (m *mockClient) FetchData(ctx context.Context) ([]byte, error) {
args := m.Called(ctx)
return args.Get(0).([]byte), args.Error(1)
}
```
## Test Error Cases
Always test error cases and edge conditions:
```go
func TestHandler_Errors(t *testing.T) {
tests := []struct {
name string
setup func(*mockDeps)
wantErr error
}{
{
name: "database connection failed",
setup: func(m *mockDeps) {
m.db.On("Connect").Return(ErrConnFailed)
},
wantErr: ErrConnFailed,
},
{
name: "invalid input",
setup: func(m *mockDeps) {
// No setup needed
},
wantErr: ErrInvalidInput,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
m := newMockDeps()
if tt.setup != nil {
tt.setup(m)
}
err := Handler(m)
require.ErrorIs(t, err, tt.wantErr)
})
}
}
```
## Integration Test Patterns
Use build tags for integration tests:
```go
//go:build integration
// +build integration
package mypackage_test
func TestIntegration_RealDatabase(t *testing.T) {
// Integration test code
}
```
Run with: `go test -tags=integration ./...`
## Test Coverage Standards
- Minimum coverage: 90% lines and branches
- Every exported function must have tests
- Critical paths need both positive and negative tests
- Edge cases must be explicitly tested
## Running Tests
```bash
# Run all tests
go test -v ./...
# Run with race detector
go test -v -race ./...
# Run with coverage
go test -v -cover ./...
# Run single test
go test -v ./path/to/package -run TestName
# Run with failfast
go test -v --failfast ./...
```
## Test Documentation
Tests serve as documentation:
- Use descriptive test names
- Use table-driven test `name` field to describe scenario
- Add comments only for complex setup or non-obvious behavior
Related in General
modeling-omnistudio-epc-catalog
IncludedSalesforce Industries CME EPC product-modeling skill for Product2-based catalog creation. Use when creating EPC products, configuring product attributes, building offer bundles with Product Child Items, or reviewing EPC DataPack JSON metadata for product catalog changes. TRIGGER when: user creates or updates Product2 EPC records, AttributeAssignment payloads, AttributeMetadata/AttributeDefaultValues, Offer bundles, or ProductChildItem relationships. DO NOT TRIGGER when: designing OmniScripts/FlexCards/Integration Procedures (use building-omnistudio-omniscript, building-omnistudio-flexcard, or building-omnistudio-integration-procedure), implementing Apex business logic (use generating-apex), or troubleshooting deployment pipelines (use deploying-metadata).
relationship-science-coach
IncludedUse this skill for direct, practical adult relationship coaching: couples conflict, repair, trust, marriage, dating, flirting, attachment patterns, emotional connection, sex, desire differences, eroticism, kink negotiation, affection, love languages, breakups, and long-term passion. Draw on Gottman, EFT and Hold Me Tight, attachment science, modern sex research, Perel, Nagoski, Kerner, Schnarch, Love and Stosny, and flexible love-language tools. Be concrete and low-hedge. Redirect only for imminent danger, abuse, coercive control, minors, non-consent, self-harm, stalking, or medical/legal/psychiatric decisions.
building-sf-integrations
IncludedSalesforce integration architecture and runtime plumbing with 120-point scoring. Use this skill to set up Named Credentials, External Credentials, External Services, REST/SOAP callout patterns, Platform Events, and Change Data Capture. TRIGGER when: user sets up Named Credentials, External Services, REST/SOAP callouts, Platform Events, CDC, or touches .namedCredential-meta.xml files. DO NOT TRIGGER when: Connected App/OAuth config (use configuring-connected-apps), Apex-only logic (use generating-apex), or data import/export (use handling-sf-data).
venue-templates
IncludedAccess comprehensive LaTeX templates, formatting requirements, and submission guidelines for major scientific publication venues (Nature, Science, PLOS, IEEE, ACM), academic conferences (NeurIPS, ICML, CVPR, CHI), research posters, and grant proposals (NSF, NIH, DOE, DARPA). This skill should be used when preparing manuscripts for journal submission, conference papers, research posters, or grant proposals and need venue-specific formatting requirements and templates.
let-fate-decide
IncludedDraws the 12 Houses of the Zodiac Tarot spread to inject entropy into planning when prompts are vague, ambiguous, or casually delegated. Interprets the spread to guide next steps. Use when the user says 'let fate decide', 'YOLO', 'whatever', 'idk', or other nonchalant phrases, makes Yu-Gi-Oh references, or when you are about to arbitrarily pick between multiple reasonable approaches. Prefer over ask-questions-if-underspecified when the user's tone is casual or playful rather than precision-seeking.
net-ops
IncludedCross-platform network troubleshooting (Windows, macOS, Linux) via local or remote shell. Use for: DNS broken, can't resolve hostnames, nslookup/dig works but apps fail, NRPT, WFP, scutil, /etc/resolver, systemd-resolved, /etc/resolv.conf, NetworkManager, VPN DNS leak residue (ProtonVPN/Mullvad/WireGuard/AnyConnect), AV/firewall blocking DNS or DoH, Tailscale DNS interaction, intermittent connectivity, remote diagnostics over SSH.