Convert license tests to use test fixtures

Used to exercise the new functions to allow the env configuration of a
test fixture to be customized.

Bug: 181070625
Test: m nothing
Change-Id: Iea1d7b20498d690fcade4b6699a70773ea9175c2
This commit is contained in:
Paul Duffin
2021-03-03 00:42:36 +00:00
parent 672cb9fbc7
commit 8bd286590b
3 changed files with 91 additions and 159 deletions

View File

@@ -8,7 +8,7 @@ import (
var licenseKindTests = []struct {
name string
fs map[string][]byte
fs MockFS
expectedErrors []string
}{
{
@@ -97,48 +97,18 @@ var licenseKindTests = []struct {
func TestLicenseKind(t *testing.T) {
for _, test := range licenseKindTests {
t.Run(test.name, func(t *testing.T) {
_, errs := testLicenseKind(test.fs)
expectedErrors := test.expectedErrors
if expectedErrors == nil {
FailIfErrored(t, errs)
} else {
for _, expectedError := range expectedErrors {
FailIfNoMatchingErrors(t, expectedError, errs)
}
if len(errs) > len(expectedErrors) {
t.Errorf("additional errors found, expected %d, found %d", len(expectedErrors), len(errs))
for i, expectedError := range expectedErrors {
t.Errorf("expectedErrors[%d] = %s", i, expectedError)
}
for i, err := range errs {
t.Errorf("errs[%d] = %s", i, err)
}
}
}
licenseTestFixtureFactory.
Extend(
FixtureRegisterWithContext(func(ctx RegistrationContext) {
ctx.RegisterModuleType("mock_license", newMockLicenseModule)
}),
test.fs.AddToFixture(),
).ExtendWithErrorHandler(FixtureExpectsAllErrorsToMatchAPattern(test.expectedErrors)).
RunTest(t)
})
}
}
func testLicenseKind(fs map[string][]byte) (*TestContext, []error) {
// Create a new config per test as license_kind information is stored in the config.
config := TestArchConfig(buildDir, nil, "", fs)
ctx := NewTestArchContext(config)
RegisterLicenseKindBuildComponents(ctx)
ctx.RegisterModuleType("mock_license", newMockLicenseModule)
ctx.Register()
_, errs := ctx.ParseBlueprintsFiles(".")
if len(errs) > 0 {
return ctx, errs
}
_, errs = ctx.PrepareBuildActions(config)
return ctx, errs
}
type mockLicenseProperties struct {
License_kinds []string
}