Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

fixtures: added post processors to loaders #1193

Merged
merged 1 commit into from
Jan 30, 2025
Merged

Conversation

j4k4
Copy link
Member

@j4k4 j4k4 commented Jan 27, 2025

Major change of this release is the additions of post processors to the fixture package. These allow additional handling after loading the fixture data, e.g. populating internal caches. For this change, the signatures of adding fixtures has changed slightly:

func main() {
	application.RunHttpDefaultServer(
		api.DefineRouter,
		application.WithFixtureSetFactory("default", service.FixtureSetsFactory, service.PostProcessor),
	)
}

or if you want to add multiple groups with the same post processor:

func main() {
	application.RunHttpDefaultServer(
		api.DefineRouter,
		application.WithFixtureSetFactories(map[string]fixtures.FixtureSetsFactory{
			"group1": service.FixtureSetsFactory1,
			"group2": service.FixtureSetsFactory2,
		}, service.PostProcessor),
	)
}

The options for creating test suites have been adjusted accordingly:

func (s *TestSuite) SetupSuite() []suite.Option {
	return []suite.Option{
		suite.WithLogLevel(log.LevelWarn),
		suite.WithConfigFile("./config.test.yml"),
		suite.WithFixtureSetFactory(service.FixtureSetsFactory, service.PostProcessors...),
	}
}

and

func (s *TestSuite) SetupSuite() []suite.Option {
	return []suite.Option{
		suite.WithLogLevel("warn"),
		suite.WithConfigFile("../config.test.yml"),
		suite.WithFixtureSetFactories([]fixtures.FixtureSetsFactory{
			common.FixtureSetsFactory,
			service.FixtureSetsFactory,
		}, service.PostProcessor),
	}
}

Post processors have to implement a simple interface:

type PostProcessor interface {
	Process(ctx context.Context) error
}

pkg/application/options.go Show resolved Hide resolved
@j4k4 j4k4 force-pushed the fixture-post-processor branch 2 times, most recently from 062bd25 to 034111f Compare January 29, 2025 08:28
pkg/fixtures/loader.go Outdated Show resolved Hide resolved
@j4k4 j4k4 force-pushed the fixture-post-processor branch 2 times, most recently from c3a0a00 to 565bd1b Compare January 29, 2025 19:26
@j4k4 j4k4 force-pushed the fixture-post-processor branch from 565bd1b to da88ea4 Compare January 29, 2025 19:36
@j4k4 j4k4 merged commit bfd48b0 into main Jan 30, 2025
12 checks passed
@j4k4 j4k4 deleted the fixture-post-processor branch January 30, 2025 09:11
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants