/gomega:gstructfrom gomega
Builds composite Gomega matchers that apply a separate matcher to each struct field, slice element, or map key, with options for partial matching and ignoring extras or missing entries.
Ships in gomega. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
gstruct builds composite matchers that apply a separate matcher to each field of a struct, each element of a slice, each key of a map, or the target of a pointer. It is the tool for fuzzy-matching large, deeply nested values. Docs: https://onsi.github.io/gomega/#gstruct-testing-complex-data-types.
Dot-import gomega; import gstruct normally (or dot-import it too):
import (
. "github.com/onsi/gomega"
"github.com/onsi/gomega/gstruct"
)
The values in Fields/Elements/Keys are themselves matchers. That is the whole point: compose with the core catalog (gomega:matchers) and combinators like And/Or/Not/WithTransform (gomega:composing-matchers). Examples below assume gstruct is dot-imported for brevity.
If you find yourself building an overly complex gstruct matcher, consider if you should be building a custom matcher (gomega:custom-matchers) instead.
FieldsFields is map[string]types.GomegaMatcher keyed by field name.
actual := struct {
A int
B bool
C string
}{5, true, "foo"}
Expect(actual).To(MatchAllFields(Fields{
"A": BeNumerically("<", 10),
"B": BeTrue(),
"C": Equal("foo"),
}))
MatchAllFields requires an exact 1:1 mapping — every field must have a matcher and every matcher must map to a field. This is great for maintainability: adding or removing a struct field breaks the test until you update it.
To match a subset/superset, use MatchFields(options, Fields{...}):
// IgnoreExtras: ignore struct fields with no matcher
Expect(actual).To(MatchFields(IgnoreExtras, Fields{
"A": BeNumerically("<", 10),
"B": BeTrue(), // no entry for C — fine
}))
// IgnoreMissing: ignore matchers with no corresponding field
Expect(actual).To(MatchFields(IgnoreMissing, Fields{
"A": BeNumerically("<", 10),
"B": BeTrue(),
"C": Equal("foo"),
"D": Equal("bar"), // ignored — actual has no field D
}))
IgnoreUnexportedExtras is a middle ground: it ignores only unexported extra fields (gstruct can't read them via reflect anyway) while still requiring all exported fields to be matched.
Elements + an id functionElements is map[string]types.GomegaMatcher keyed by a string id. You supply an Identifier (func(element any) string) that maps each element to its key.
actual := []string{"A: foo bar baz", "B: once upon a time", "C: the end"}
id := func(element any) string { return string(element.(string)[0]) }
Expect(actual).To(MatchAllElements(id, Elements{
"A": Not(BeZero()),
"B": MatchRegexp("[A-Z]: [a-z ]+"),
"C": ContainSubstring("end"),
}))
MatchAllElements requires a 1:1 mapping. Use MatchElements(id, options, Elements{...}) with IgnoreExtras/IgnoreMissing to relax, exactly as with fields. AllowDuplicates lets several elements share one key/matcher (all of them must pass).
Index-based variants MatchAllElementsWithIndex/MatchElementsWithIndex take an IdentifierWithIndex (func(index int, element any) string); the built-in IndexIdentity just uses the index as the key.
KeysThe *Fields API has a *Keys mirror for maps: MatchAllKeys(Keys{...}) and MatchKeys(options, Keys{...}).
actual := map[string]string{"A": "correct", "B": "incorrect"}
// MatchAllKeys requires every key be matched (this would fail without B):
Expect(actual).To(MatchAllKeys(Keys{
"A": Equal("correct"),
"B": Equal("incorrect"),
}))
// IgnoreMissing tolerates matchers for absent keys:
Expect(actual).To(MatchKeys(IgnoreMissing, Keys{
"A": Equal("correct"),
"B": Equal("incorrect"),
"C": Equal("whatever"), // ignored — actual has no key C
}))
PointToPointTo(matcher) dereferences a pointer and applies matcher to the pointed-to value. It fails if the pointer is nil.
foo := 5
Expect(&foo).To(PointTo(Equal(5)))
var bar *int
Expect(bar).NotTo(PointTo(BeNil())) // nil pointer fails PointTo
Ignore() and Reject()Ignore() always succeeds, Reject() always fails — use them as entries to skip a field/element or to assert one must never appear.
The matchers nest arbitrarily, mixing struct/slice/map/pointer matchers with the core catalog:
coreID := func(element any) string { return strconv.Itoa(element.(CoreStats).Index) }
Expect(actual).To(MatchAllFields(Fields{
"Name": Ignore(),
"StartTime": BeTemporally(">=", time.Now().Add(-100*time.Hour)),
"CPU": PointTo(MatchAllFields(Fields{
"Time": BeTemporally(">=", time.Now().Add(-time.Hour)),
"UsageNanoCores": BeNumerically("~", 1e9, 1e8),
"UsageCoreNanoSeconds": BeNumerically(">", 1e6),
"Cores": MatchElements(coreID, IgnoreExtras, Elements{
"0": MatchAllFields(Fields{
"Index": Ignore(),
"UsageNanoCores": BeNumerically("<", 1e9),
"UsageCoreNanoSeconds": BeNumerically(">", 1e5),
}),
}),
})),
"Memory": PointTo(MatchAllFields(Fields{
"Time": BeTemporally(">=", time.Now().Add(-time.Hour)),
"AvailableBytes": BeZero(),
"UsageBytes": BeNumerically(">", 5e6),
"WorkingSetBytes": BeNumerically(">", 5e6),
})),
"Rootfs": Ignore(),
"Logs": Ignore(),
}))
MatchAllFields/MatchAllElements/MatchAllKeys fail on missing OR extra entries. They demand an exact 1:1 mapping. The instant you want a partial match, switch to MatchFields/MatchElements/MatchKeys and pass IgnoreExtras, IgnoreMissing, or both (IgnoreExtras|IgnoreMissing).AllowDuplicates. Don't derive keys from data that changes between runs.Elements keys are strings. The id function returns a string, so numeric ids must be stringified (e.g. strconv.Itoa(i)), and the keys in your Elements{} literal must match those strings exactly.PointTo rejects nil pointers — a nil actual fails the match outright, before the inner matcher ever runs.gomega:matchers and gomega:composing-matchers.What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
npx claudepluginhub onsi/gomega --plugin gomega12 skills in this plugin
/assertionsWrite correct synchronous Gomega assertions — Expect/Ω notation, the To/NotTo/ToNot/Should/ShouldNot equivalences, the multi-return error idiom, Succeed vs HaveOccurred, the .Error() chaining form, annotating assertions (format-string and func()string), tuning failure output via the format subpackage (MaxLength/MaxDepth/UseStringerRepresentation/GomegaStringer/TruncatedDiff/RegisterCustomFormatter/format.Object), and asserting inside helper functions with GinkgoHelper/WithOffset/ExpectWithOffset, NewWithT(t) for plain testing, and the g Gomega callback. Use when writing or reviewing synchronous (non-polling) Gomega assertions./asyncPolling assertions in Gomega — Eventually (poll until it passes) and Consistently (must keep passing), the func(g Gomega) callback idiom, WithTimeout/WithPolling/Within/ProbeEvery, WithContext and Ginkgo SpecContext, StopTrying/TryAgainAfter bail-outs, MustPassRepeatedly, and default-interval tuning. Use when an assertion can't be true synchronously — anything involving goroutines, channels, network calls, eventual consistency, or "wait until / stays true"./composing-matchersBuild compound Gomega assertions by combining matchers — And/SatisfyAll (all pass), Or/SatisfyAny (any pass), Not (negate), WithTransform to map the actual before matching, Satisfy for an ad-hoc predicate, HaveValue to dereference pointers/interfaces, HaveField for struct fields and method results, HaveEach for every element, plus the matchers-as-arguments idiom that lets you nest matchers inside ContainElement/ConsistOf/HaveKeyWithValue/Receive. Use when one Expect needs several requirements at once, or you want to assert deep into a value without writing a custom matcher./custom-matchersWriting your own Gomega matchers — the GomegaMatcher interface (Match/FailureMessage/NegatedFailureMessage), gcustom.MakeMatcher with message templates and template data, the format package helpers (format.Message/format.Object), MatchMayChangeInTheFuture and StopTrying for Eventually/Consistently, and how to test and package custom matchers. Use when a built-in or composed matcher can't express your domain assertion and you need to build one./gbytesTesting streaming io buffers with gbytes — gbytes.NewBuffer() (an io.Writer also returned by gexec sessions), the Say(regexp) matcher that forward-scans from a moving read cursor, the canonical Eventually(buffer).Should(Say(...)) streaming pattern, sequential cursor-advancing Say calls, Contents(), BufferWithBytes/BufferReader, buffer.Detect for branching, and TimeoutReader/Writer/Closer for testing blocking io.Reader/Writer/Closer. Use when asserting on streaming or incremental output (process stdout/stderr, API streams, io.Readers) rather than a complete value./gexecTesting external processes with gexec — compile binaries with Build/BuildWithEnvironment/BuildIn and CleanupBuildArtifacts, start them with Start returning a *Session, await exit with the Exit matcher (Eventually(session).Should(Exit(0))), Wait/ExitCode, signal via Kill/Terminate/Interrupt/Signal and package-level KillAndWait/TerminateAndWait, and assert on session.Out/Err which are gbytes buffers (Say, Contents). Use when building, running, signaling, or asserting on subprocesses in Go tests.Other plugins' skills for the same job