Hi, I've just discovered the new AroundNode feature and found it's absolutely awesome, thanks a lot! Yet it may be far more useful.
In according to the docs, an AroundNode when applied to a container, is being executed even for BeforeEach nodes, and this makes it unusable to cleanup after(or before) tests.
For instance, I create some database records in a BeforeEach node and use DeferCleanup to clean the database after:
// root Describe
BeforeEach(func(ctx SpecContext) {
tenant = factory.CreateTenant(ctx)
DeferCleanup(func(ctx SpecContext) {
testhelpers.CleanDB(ctx, db)
})
})
Since I have a lot of suites working with the database, I don't really want to repeat the same DeferCleanup over and over again and AroundNode would a good place to truncate the database if there was a way to distinguish what node it wraps.
Currently, if I define a decorator like
// Should be used as Describe("SomeDBService", Serial, testhelpers.WithDB(), func...
func WithDB() types.AroundNodeDecorator {
return ginkgo.AroundNode(func(ctx context.Context, body func(ctx context.Context)) {
defer CleanDB(ctx, db)
body(ctx)
})
}
it will truncate the database after the BeforeEach node, so the test itself will see a clean database. The problem is that not all my tests interact with the database, so I don't need and want to truncate after every single test, that's why a decorator like I described above is useful, I can only apply it to specific containers.
I'm wondering if there is way to know what node an AroundNode wraps so I can only clean the database after actual tests and not after setup nodes.
Maybe there is a different way to achieve what I want?
Hi, I've just discovered the new
AroundNodefeature and found it's absolutely awesome, thanks a lot! Yet it may be far more useful.In according to the docs, an
AroundNodewhen applied to a container, is being executed even forBeforeEachnodes, and this makes it unusable to cleanup after(or before) tests.For instance, I create some database records in a
BeforeEachnode and useDeferCleanupto clean the database after:Since I have a lot of suites working with the database, I don't really want to repeat the same
DeferCleanupover and over again andAroundNodewould a good place to truncate the database if there was a way to distinguish what node it wraps.Currently, if I define a decorator like
it will truncate the database after the
BeforeEachnode, so the test itself will see a clean database. The problem is that not all my tests interact with the database, so I don't need and want to truncate after every single test, that's why a decorator like I described above is useful, I can only apply it to specific containers.I'm wondering if there is way to know what node an
AroundNodewraps so I can only clean the database after actual tests and not after setup nodes.Maybe there is a different way to achieve what I want?