Skip to content

Navigation Menu

Sign in
Sign up

rivertest: enable metadata assertions - #1137

Open
bgentry wants to merge 1 commit into
master from
bg/rivertest-metadata
Open

rivertest: enable metadata assertions #1137
bgentry wants to merge 1 commit into
master from
bg/rivertest-metadata

Conversation

@bgentry

@bgentry bgentry commented Jan 30, 2026

Copy link
Copy Markdown
Contributor

This enables basic assertions against metadata in rivertest.RequireX methods. The approach here isn't anything special: it allows a map[string]any to be specified and considers it a failure if all keys & values in it are not also in the metadata.

This should make it possible to build workflow-related assertions and other metadata assertions much more easily.

@brandur brandur left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, my fault on the delay here.

Just want to run one alt by you, but generally looks fine.

Comment thread rivertest/rivertest.go
// ignored.
//
// No assertion is made if left nil or empty.
Metadata map[string]any

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just related to our convo last weekend, wanted to quickly get your thoughts on allowing people to do something like specify an exact match versus partial match.

If this became:

	Metadata MetadataMatcher

And you had something like:

type MetadataMatcher interface {
	CheckMatch(t testingT, actualBytes []byte, requireNotInserted bool) (bool, []string)
}
type metadataContainsMatcher struct {
	expected map[string]any
}
// MetadataContains checks that the given key-value pairs are present in job
// metadata, ignoring any extra keys that may also be there.
func MetadataContains(expected map[string]any) metadataContainsMatcher {
	return metadataContainsMatcher{expected: expected}
}
type metadataExactlyMatcher struct {
	expected map[string]any
}
// MetadataExactly checks that the given key-value pairs are present in job
// metadata, and that no extra keys are present.
func MetadataExactly(expected map[string]any) metadataExactlyMatcher {
	return metadataExactlyMatcher{expected: expected}
}

You get a pretty clean check that's a bit more readable than what's in here right now like:

			opts.Metadata = MetadataContains(map[string]any{
				"key": "value",
			})

The downside is that sometimes these interface-based checks can be a little hard to figure out how to use.

Thoughts?

This enables basic assertions against metadata in `rivertest.RequireX`
methods. The approach here isn't anything special: it allows a
`map[string]any` to be specified and considers it a failure if all keys
& values in it are not also in the metadata.
This should make it possible to build workflow-related assertions and
other metadata assertions much more easily.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@brandur brandur brandur left review comments

At least 1 approving review is required to merge this pull request.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

2 participants

AltStyle によって変換されたページ (->オリジナル) /