From 9967d62fad2fdfcf3785a450707804e1a3e34666 Mon Sep 17 00:00:00 2001 From: Liz Kammer Date: Tue, 26 Apr 2022 09:15:13 -0400 Subject: [PATCH] Update CreateModule to require a type name This makes the LoadHook and TopDownMutatorContext interfaces for CreateModule the same. Test: CI Change-Id: I30122099bdf109cda40f9d81a574dd6fa861f459 --- context_test.go | 6 +++--- module_ctx.go | 5 +++-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/context_test.go b/context_test.go index 6308ba9..6b9b599 100644 --- a/context_test.go +++ b/context_test.go @@ -461,17 +461,17 @@ func createTestMutator(ctx TopDownMutatorContext) { Deps []string } - ctx.CreateModule(newBarModule, &props{ + ctx.CreateModule(newBarModule, "new_bar", &props{ Name: "B", Deps: []string{"D"}, }) - ctx.CreateModule(newBarModule, &props{ + ctx.CreateModule(newBarModule, "new_bar", &props{ Name: "C", Deps: []string{"D"}, }) - ctx.CreateModule(newFooModule, &props{ + ctx.CreateModule(newFooModule, "new_foo", &props{ Name: "D", }) } diff --git a/module_ctx.go b/module_ctx.go index 787f483..b241712 100644 --- a/module_ctx.go +++ b/module_ctx.go @@ -862,7 +862,7 @@ type TopDownMutatorContext interface { // CreateModule creates a new module by calling the factory method for the specified moduleType, and applies // the specified property structs to it as if the properties were set in a blueprint file. - CreateModule(ModuleFactory, ...interface{}) Module + CreateModule(ModuleFactory, string, ...interface{}) Module } type BottomUpMutatorContext interface { @@ -1228,13 +1228,14 @@ func (mctx *mutatorContext) Rename(name string) { mctx.rename = append(mctx.rename, rename{mctx.module.group, name}) } -func (mctx *mutatorContext) CreateModule(factory ModuleFactory, props ...interface{}) Module { +func (mctx *mutatorContext) CreateModule(factory ModuleFactory, typeName string, props ...interface{}) Module { module := newModule(factory) module.relBlueprintsFile = mctx.module.relBlueprintsFile module.pos = mctx.module.pos module.propertyPos = mctx.module.propertyPos module.createdBy = mctx.module + module.typeName = typeName for _, p := range props { err := proptools.AppendMatchingProperties(module.properties, p, nil)