Stats
Actions
Tags
From skills
Go testing with Ginkgo BDD suites, Gomega matchers, uber-go/mock mocks, and benchmarks. Use when writing unit tests, generating mocks for interfaces, setting up test suites, or running parallel tests in Go projects. Apply whenever user writes Describe/It/BeforeEach blocks, uses mockgen, or asks about Ginkgo setup.
How this skill is triggered — by the user, by Claude, or both
Slash command
/skills:golang-testingThe summary Claude sees in its skill listing — used to decide when to auto-load this skill
```go
import (. "github.com/onsi/ginkgo/v2"; . "github.com/onsi/gomega"; "testing")
func TestUser(t *testing.T) { RegisterFailHandler(Fail); RunSpecs(t, "User Suite") }
var _ = Describe("UserBiz", func() {
var (mockStore *mock_store.MockIStore; biz UserBiz)
BeforeEach(func() {
ctrl := gomock.NewController(GinkgoT())
mockStore = mock_store.NewMockIStore(ctrl)
biz = New(mockStore)
})
It("returns a token on valid login", func() {
mockStore.EXPECT().User().Return(mockUserStore).AnyTimes()
mockUserStore.EXPECT().GetByUsername(gomock.Any(), "alice").Return(&model.UserM{}, nil)
resp, err := biz.Login(ctx, req)
Expect(err).NotTo(HaveOccurred())
Expect(resp.Token).NotTo(BeEmpty())
})
})
DescribeTable("isValidUsername",
func(input string, wantErr bool) { Expect(isValidUsername(input) != nil).To(Equal(wantErr)) },
Entry("valid", "user_123", false),
Entry("too short", "ab", true),
Entry("invalid char", "user*name", true),
)
var db *sql.DB
var _ = BeforeSuite(func() { db, _ = sql.Open("postgres", testDSN) })
var _ = AfterSuite(func() { db.Close() })
// DeferCleanup — scoped teardown inside any node:
It("creates user", func() { u := createUser(db); DeferCleanup(deleteUser, db, u.ID) })
Eventually(func() string { return getJobStatus(jobID) }, "5s", "200ms").Should(Equal("completed"))
Consistently(func() int { return queue.Len() }, "1s", "100ms").Should(BeZero())
//go:generate mockgen -destination mock_store.go -package store <module>/internal/store IStore,UserStore
// go generate ./... — place directive in the file that defines the interface
func BenchmarkIsValidUsername(b *testing.B) {
for i := 0; i < b.N; i++ { isValidUsername("valid_user123") }
}
// go test -bench=. -benchmem ./...
gomock.NewController(t) in Ginkgo — use GinkgoT() for proper failure integrationIt blocks — reset in BeforeEach, not BeforeSuiteIt/BeforeEach — Ginkgo silently ignores them//go:generate in a separate file — put it next to the interface definition-race — always run go test -race ./... in CIProvides a checklist for code reviews covering functionality, security, performance, maintainability, tests, and quality. Use for pull requests, audits, team standards, and developer training.
npx claudepluginhub shipengqi/skills --plugin database-redis