Skip to content

common: create test helper for reuse in all builders #1098

@klaskosk

Description

@klaskosk

The approach taken in #1096 is to simply remove the unit tests for the builder now that it is a relatively thin wrapper over the EmbeddableBuilder, but this ends up decreasing our test coverage both numerically and for verifying that the resource-specific builder behaves as expected.

My current proposed solution is to create a package with test helpers that can be imported to test specific builders. For a very rough example:

// pkg/internal/common/test
func TestBasicBuilderFunctionality[O runtimeclient.Object, B Builder[O, SO], SO objectPointer[O], SB builderPointer[O, SO, B](t *testing.T, pullBuilder pullBuilderFunc) {
    t.Helper()

    // ...calls to other helpers for each method...
}

// pkg/**/*_test.go
func TestBasic<builder>Functionality(t *testing.T) {
    commontest.TestBasicBuilderFunctionality(t, Pull<builder>Builder)
}

This allows for ensuring that the specific builder still functions as expected whilst reducing the boilerplate to just a few lines

Metadata

Metadata

Assignees

Labels

common-builderMigration to use a common builder struct and interface

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions