From 52f70b5d8281ed62bfde7310db9a95f5947c2711 Mon Sep 17 00:00:00 2001 From: Tom Downes Date: Thu, 23 Mar 2023 13:18:14 -0500 Subject: [PATCH 1/2] Refactoring to support edge-tracking in graph - Re-implement `modReference` and `varReference` structs to implement a new interface named `reference` - Adopt the `reference` interface in the `ModConnection` struct that tracks edges within the blueprint graph --- pkg/config/config.go | 18 +++--- pkg/config/config_test.go | 34 +++++++--- pkg/config/expand.go | 131 +++++++++++++++++++++++++------------- pkg/config/expand_test.go | 93 +++++++++++++++------------ 4 files changed, 171 insertions(+), 105 deletions(-) diff --git a/pkg/config/config.go b/pkg/config/config.go index 166c46fd4f..07f6fe1ddb 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -271,11 +271,8 @@ const ( // ModConnection defines details about connections between modules. Currently, // only modules connected with "use" are tracked. type ModConnection struct { - toID string - fromID string - // Currently only supports useConnection - kind ConnectionKind - // List of variables shared from module `fromID` to module `toID` + ref reference + kind ConnectionKind sharedVariables []string } @@ -322,7 +319,8 @@ func (dc *DeploymentConfig) listUnusedModules() map[string][]string { unusedModules := make(map[string][]string) for _, conn := range dc.moduleConnections { if conn.isEmpty() { - unusedModules[conn.fromID] = append(unusedModules[conn.fromID], conn.toID) + fromMod := conn.ref.getFromModuleID() + unusedModules[fromMod] = append(unusedModules[fromMod], conn.ref.getToModuleID()) } } return unusedModules @@ -508,8 +506,8 @@ func modToGrp(groups []DeploymentGroup, modID string) (int, error) { // checkUsedModuleNames verifies that any used modules have valid names and // are in the correct group -func checkUsedModuleNames(depGroups []DeploymentGroup) error { - for _, grp := range depGroups { +func checkUsedModuleNames(bp Blueprint) error { + for _, grp := range bp.DeploymentGroups { for _, mod := range grp.Modules { for _, usedMod := range mod.Use { ref, err := identifyModuleByReference(usedMod, grp) @@ -517,7 +515,7 @@ func checkUsedModuleNames(depGroups []DeploymentGroup) error { return err } - if err = ref.validate(depGroups); err != nil { + if err = ref.validate(bp); err != nil { return err } @@ -570,7 +568,7 @@ func (dc *DeploymentConfig) validateConfig() { if err = checkModuleAndGroupNames(dc.Config.DeploymentGroups); err != nil { log.Fatal(err) } - if err = checkUsedModuleNames(dc.Config.DeploymentGroups); err != nil { + if err = checkUsedModuleNames(dc.Config); err != nil { log.Fatal(err) } if err = checkBackends(dc.Config); err != nil { diff --git a/pkg/config/config_test.go b/pkg/config/config_test.go index 02747d6c66..c30540cdca 100644 --- a/pkg/config/config_test.go +++ b/pkg/config/config_test.go @@ -400,10 +400,15 @@ func (s *MySuite) TestListUnusedModules(c *C) { got := dc.listUnusedModules() c.Assert(got, HasLen, 0) - // All "use" modules actually used + // test used module with shared variables usedConn := ModConnection{ - toID: "usedModule", - fromID: "usingModule", + ref: modReference{ + ToModuleID: "usedModule", + FromModuleID: "usingModule", + ToGroupID: "group1", + FromGroupID: "group1", + Explicit: true, + }, kind: useConnection, sharedVariables: []string{"var1"}, } @@ -411,10 +416,15 @@ func (s *MySuite) TestListUnusedModules(c *C) { got = dc.listUnusedModules() c.Assert(got["usingModule"], HasLen, 0) - // One fully unused module + // test used module with no shared variables (i.e. "unused") unusedConn := ModConnection{ - toID: "usedModule", - fromID: "usingModule", + ref: modReference{ + ToModuleID: "firstUnusedModule", + FromModuleID: "usingModule", + ToGroupID: "group1", + FromGroupID: "group1", + Explicit: true, + }, kind: useConnection, sharedVariables: []string{}, } @@ -422,17 +432,21 @@ func (s *MySuite) TestListUnusedModules(c *C) { got = dc.listUnusedModules() c.Assert(got["usingModule"], HasLen, 1) - // Two fully unused modules + // test second used module with no shared variables (i.e. "unused") secondUnusedConn := ModConnection{ - toID: "secondUnusedModule", - fromID: "usingModule", + ref: modReference{ + ToModuleID: "secondUnusedModule", + FromModuleID: "usingModule", + ToGroupID: "group1", + FromGroupID: "group1", + Explicit: true, + }, kind: useConnection, sharedVariables: []string{}, } dc.moduleConnections = append(dc.moduleConnections, secondUnusedConn) got = dc.listUnusedModules() c.Assert(got["usingModule"], HasLen, 2) - } func (s *MySuite) TestAddKindToModules(c *C) { diff --git a/pkg/config/expand.go b/pkg/config/expand.go index f338fa01a6..6554906f13 100644 --- a/pkg/config/expand.go +++ b/pkg/config/expand.go @@ -275,7 +275,7 @@ func (dc *DeploymentConfig) applyUseModules() error { // this module contains information about the target module that // was specified by the user in the blueprint - toMod, err := toGroup.getModuleByID(modRef.ID) + toMod, err := toGroup.getModuleByID(modRef.ToModuleID) if err != nil { return err } @@ -300,8 +300,7 @@ func (dc *DeploymentConfig) applyUseModules() error { return err } connection := ModConnection{ - toID: toModID, - fromID: fromMod.ID, + ref: modRef, kind: useConnection, sharedVariables: usedVars, } @@ -513,20 +512,46 @@ type varContext struct { blueprint Blueprint } +type reference interface { + validate(Blueprint) error + isIntergroup() bool + String() string + getFromModuleID() string + getToModuleID() string +} + /* A module reference is made by the use keyword and is subject to IGC constraints of references (ordering, explicitness). It has the following fields: - - ID: a module ID + - ToModuleID: the target module ID + - FromModuleID: the source module ID - ToGroupID: the deployment group in which the module is *expected* to be found - FromGroupID: the deployment group from which the reference is made - Explicit: a boolean value indicating whether the user made a reference that explicitly identified ToGroupID rather than inferring it using FromGroupID */ type modReference struct { - ID string - ToGroupID string - FromGroupID string - Explicit bool + ToModuleID string + FromModuleID string + ToGroupID string + FromGroupID string + Explicit bool +} + +func (ref modReference) String() string { + return ref.ToGroupID + "." + ref.ToModuleID +} + +func (ref modReference) isIntergroup() bool { + return ref.ToGroupID == ref.FromGroupID +} + +func (ref modReference) getFromModuleID() string { + return ref.FromModuleID +} + +func (ref modReference) getToModuleID() string { + return ref.FromModuleID } /* @@ -543,12 +568,12 @@ func identifyModuleByReference(yamlReference string, dg DeploymentGroup) (modRef modComponents := strings.Split(yamlReference, ".") switch len(modComponents) { case 1: - ref.ID = modComponents[0] + ref.ToModuleID = modComponents[0] ref.ToGroupID = dg.Name ref.FromGroupID = dg.Name case 2: ref.ToGroupID = modComponents[0] - ref.ID = modComponents[1] + ref.ToModuleID = modComponents[1] ref.FromGroupID = dg.Name ref.Explicit = true } @@ -557,7 +582,7 @@ func identifyModuleByReference(yamlReference string, dg DeploymentGroup) (modRef // for now check that no fields are the empty string; due to the default // zero values for strings in the "ref" struct, this will also cover the // case that modComponents has wrong # of fields - if ref.ID == "" || ref.ToGroupID == "" || ref.FromGroupID == "" { + if ref.ToModuleID == "" || ref.ToGroupID == "" || ref.FromGroupID == "" { return ref, fmt.Errorf("%s: %s, expected %s", errorMessages["invalidMod"], yamlReference, expectedModFormat) } @@ -567,19 +592,37 @@ func identifyModuleByReference(yamlReference string, dg DeploymentGroup) (modRef /* A variable reference has the following fields - - ID: a module ID or "vars" if referring to a deployment variable - Name: the name of the module output or deployment variable + - ToModuleID: the target module ID or "vars" if referring to a deployment variable + - FromModuleID: the source module ID - ToGroupID: the deployment group in which the module is *expected* to be found - FromGroupID: the deployment group from which the reference is made - Explicit: a boolean value indicating whether the user made a reference that explicitly identified ToGroupID rather than inferring it using FromGroupID */ type varReference struct { - ID string - ToGroupID string - FromGroupID string - Name string - Explicit bool + Name string + ToModuleID string + FromModuleID string + ToGroupID string + FromGroupID string + Explicit bool +} + +func (ref varReference) String() string { + return ref.ToGroupID + "." + ref.ToModuleID + "." + ref.Name +} + +func (ref varReference) isIntergroup() bool { + return ref.ToGroupID == ref.FromGroupID +} + +func (ref varReference) getFromModuleID() string { + return ref.FromModuleID +} + +func (ref varReference) getToModuleID() string { + return ref.FromModuleID } /* @@ -599,17 +642,17 @@ func identifySimpleVariable(yamlReference string, dg DeploymentGroup) (varRefere // intra-group references length 2 and inter-group references length 3 switch len(varComponents) { case 2: - ref.ID = varComponents[0] + ref.ToModuleID = varComponents[0] ref.Name = varComponents[1] - if ref.ID == "vars" { + if ref.ToModuleID == "vars" { ref.ToGroupID = "deployment" } else { ref.ToGroupID = dg.Name } case 3: ref.ToGroupID = varComponents[0] - ref.ID = varComponents[1] + ref.ToModuleID = varComponents[1] ref.Name = varComponents[2] ref.Explicit = true } @@ -618,24 +661,24 @@ func identifySimpleVariable(yamlReference string, dg DeploymentGroup) (varRefere // for now check that source and name are not empty strings; due to the // default zero values for strings in the "ref" struct, this will also // cover the case that varComponents has wrong # of fields - if ref.FromGroupID == "" || ref.ToGroupID == "" || ref.ID == "" || ref.Name == "" { + if ref.FromGroupID == "" || ref.ToGroupID == "" || ref.ToModuleID == "" || ref.Name == "" { return varReference{}, fmt.Errorf("%s %s, expected format: %s", errorMessages["invalidVar"], yamlReference, expectedVarFormat) } return ref, nil } -func (ref *modReference) validate(depGroups []DeploymentGroup) error { - callingModuleGroupIndex := slices.IndexFunc(depGroups, func(d DeploymentGroup) bool { return d.Name == ref.FromGroupID }) +func (ref modReference) validate(bp Blueprint) error { + callingModuleGroupIndex := slices.IndexFunc(bp.DeploymentGroups, func(d DeploymentGroup) bool { return d.Name == ref.FromGroupID }) if callingModuleGroupIndex == -1 { return fmt.Errorf("%s: %s", errorMessages["groupNotFound"], ref.FromGroupID) } - targetModuleGroupIndex, err := modToGrp(depGroups, ref.ID) + targetModuleGroupIndex, err := modToGrp(bp.DeploymentGroups, ref.ToModuleID) if err != nil { return err } - targetModuleGroupName := depGroups[targetModuleGroupIndex].Name + targetModuleGroupName := bp.DeploymentGroups[targetModuleGroupIndex].Name // Ensure module is from the correct group isInterGroupReference := callingModuleGroupIndex != targetModuleGroupIndex @@ -645,12 +688,12 @@ func (ref *modReference) validate(depGroups []DeploymentGroup) error { if isInterGroupReference { if isRefToLaterGroup { return fmt.Errorf("%s: %s is in a later group", - errorMessages["intergroupOrder"], ref.ID) + errorMessages["intergroupOrder"], ref.ToModuleID) } if !ref.Explicit { return fmt.Errorf("%s: %s must specify a group ID before the module ID", - errorMessages["intergroupImplicit"], ref.ID) + errorMessages["intergroupImplicit"], ref.ToModuleID) } } @@ -659,7 +702,7 @@ func (ref *modReference) validate(depGroups []DeploymentGroup) error { // error after enforcing explicitness of intergroup references if !isCorrectToGroup { return fmt.Errorf("%s: %s.%s", - errorMessages["referenceWrongGroup"], ref.ToGroupID, ref.ID) + errorMessages["referenceWrongGroup"], ref.ToGroupID, ref.ToModuleID) } return nil @@ -673,26 +716,26 @@ func (ref *modReference) validate(depGroups []DeploymentGroup) error { // ref.ExplicitInterGroup: intergroup references must explicitly identify the // target group ID and intragroup references cannot have an incorrect explicit // group ID -func (ref *varReference) validate(depGroups []DeploymentGroup, vars map[string]interface{}) error { +func (ref *varReference) validate(bp Blueprint) error { // simplest case to evaluate is a deployment variable's existence if ref.ToGroupID == "deployment" { - if ref.ID == "vars" { - if _, ok := vars[ref.Name]; !ok { + if ref.ToModuleID == "vars" { + if _, ok := bp.Vars[ref.Name]; !ok { return fmt.Errorf("%s: %s is not a deployment variable", errorMessages["varNotFound"], ref.Name) } return nil } - return fmt.Errorf("%s: %s", errorMessages["invalidDeploymentRef"], ref.ID) + return fmt.Errorf("%s: %s", errorMessages["invalidDeploymentRef"], ref) } - targetModuleGroupIndex, err := modToGrp(depGroups, ref.ID) + targetModuleGroupIndex, err := modToGrp(bp.DeploymentGroups, ref.ToModuleID) if err != nil { return err } - targetModuleGroup := depGroups[targetModuleGroupIndex] + targetModuleGroup := bp.DeploymentGroups[targetModuleGroupIndex] - callingModuleGroupIndex := slices.IndexFunc(depGroups, func(d DeploymentGroup) bool { return d.Name == ref.FromGroupID }) + callingModuleGroupIndex := slices.IndexFunc(bp.DeploymentGroups, func(d DeploymentGroup) bool { return d.Name == ref.FromGroupID }) if callingModuleGroupIndex == -1 { return fmt.Errorf("%s: %s", errorMessages["groupNotFound"], ref.FromGroupID) } @@ -707,12 +750,12 @@ func (ref *varReference) validate(depGroups []DeploymentGroup, vars map[string]i if isInterGroupReference { if isRefToLaterGroup { return fmt.Errorf("%s: %s is in the later group %s", - errorMessages["intergroupOrder"], ref.ID, ref.ToGroupID) + errorMessages["intergroupOrder"], ref.ToModuleID, ref.ToGroupID) } if !ref.Explicit { return fmt.Errorf("%s: %s must specify the group ID %s before the module ID", - errorMessages["intergroupImplicit"], ref.ID, ref.ToGroupID) + errorMessages["intergroupImplicit"], ref.ToModuleID, ref.ToGroupID) } } @@ -721,15 +764,15 @@ func (ref *varReference) validate(depGroups []DeploymentGroup, vars map[string]i // error after enforcing explicitness of intergroup references if !isCorrectToGroup { return fmt.Errorf("%s: %s.%s should be %s.%s", - errorMessages["referenceWrongGroup"], ref.ToGroupID, ref.ID, targetModuleGroup.Name, ref.ID) + errorMessages["referenceWrongGroup"], ref.ToGroupID, ref.ToModuleID, targetModuleGroup.Name, ref.ToModuleID) } // at this point, we have a valid intragroup or intergroup references to a // module. must now determine whether the output value actually exists in // the module. - refModIndex := slices.IndexFunc(targetModuleGroup.Modules, func(m Module) bool { return m.ID == ref.ID }) + refModIndex := slices.IndexFunc(targetModuleGroup.Modules, func(m Module) bool { return m.ID == ref.ToModuleID }) if refModIndex == -1 { - log.Fatalf("Could not find module %s", ref.ID) + log.Fatalf("Could not find module %s", ref.ToModuleID) } refMod := targetModuleGroup.Modules[refModIndex] modInfo, err := modulereader.GetModuleInfo(refMod.Source, refMod.Kind) @@ -765,7 +808,7 @@ func expandSimpleVariable(context varContext) (string, error) { return "", err } - if err := varRef.validate(context.blueprint.DeploymentGroups, context.blueprint.Vars); err != nil { + if err := varRef.validate(context.blueprint); err != nil { return "", err } @@ -776,7 +819,7 @@ func expandSimpleVariable(context varContext) (string, error) { expandedVariable = fmt.Sprintf("((var.%s))", varRef.Name) case varRef.FromGroupID: // intragroup reference can make direct reference to module output - expandedVariable = fmt.Sprintf("((module.%s.%s))", varRef.ID, varRef.Name) + expandedVariable = fmt.Sprintf("((module.%s.%s))", varRef.ToModuleID, varRef.Name) default: // intergroup reference; begin by finding the target module in blueprint @@ -788,9 +831,9 @@ func expandSimpleVariable(context varContext) (string, error) { return "", fmt.Errorf("invalid group reference: %s", varRef.ToGroupID) } toGrp := context.blueprint.DeploymentGroups[toGrpIdx] - toModIdx := slices.IndexFunc(toGrp.Modules, func(m Module) bool { return m.ID == varRef.ID }) + toModIdx := slices.IndexFunc(toGrp.Modules, func(m Module) bool { return m.ID == varRef.ToModuleID }) if toModIdx == -1 { - return "", fmt.Errorf("%s: %s", errorMessages["invalidMod"], varRef.ID) + return "", fmt.Errorf("%s: %s", errorMessages["invalidMod"], varRef.ToModuleID) } toMod := toGrp.Modules[toModIdx] diff --git a/pkg/config/expand_test.go b/pkg/config/expand_test.go index 94f83ab86f..9fdb974567 100644 --- a/pkg/config/expand_test.go +++ b/pkg/config/expand_test.go @@ -555,21 +555,21 @@ func (s *MySuite) TestIdentifyModuleByReference(c *C) { c.Assert(err, IsNil) c.Assert(ref.ToGroupID, Equals, dg.Name) c.Assert(ref.FromGroupID, Equals, dg.Name) - c.Assert(ref.ID, Equals, "module_id") + c.Assert(ref.ToModuleID, Equals, "module_id") c.Assert(ref.Explicit, Equals, false) ref, err = identifyModuleByReference("explicit_group_id.module_id", dg) c.Assert(err, IsNil) c.Assert(ref.ToGroupID, Equals, "explicit_group_id") c.Assert(ref.FromGroupID, Equals, dg.Name) - c.Assert(ref.ID, Equals, "module_id") + c.Assert(ref.ToModuleID, Equals, "module_id") c.Assert(ref.Explicit, Equals, true) ref, err = identifyModuleByReference(fmt.Sprintf("%s.module_id", dg.Name), dg) c.Assert(err, IsNil) c.Assert(ref.ToGroupID, Equals, dg.Name) c.Assert(ref.FromGroupID, Equals, dg.Name) - c.Assert(ref.ID, Equals, "module_id") + c.Assert(ref.ToModuleID, Equals, "module_id") c.Assert(ref.Explicit, Equals, true) ref, err = identifyModuleByReference("explicit_group_id.module_id.output_name", dg) @@ -605,68 +605,79 @@ func (s *MySuite) TestValidateModuleReference(c *C) { }, } + bp := Blueprint{ + DeploymentGroups: dg, + } + // An intragroup reference from group 0 to module B in 0 (good) ref0ToB0 := modReference{ - ID: dg[0].Modules[1].ID, - ToGroupID: dg[0].Name, - FromGroupID: dg[0].Name, - Explicit: false, + ToModuleID: dg[0].Modules[1].ID, + FromModuleID: "", + ToGroupID: dg[0].Name, + FromGroupID: dg[0].Name, + Explicit: false, } - c.Assert(ref0ToB0.validate(dg), IsNil) + c.Assert(ref0ToB0.validate(bp), IsNil) // An explicit intergroup reference from group 1 to module A in 0 (good) xRef1ToA0 := modReference{ - ID: dg[0].Modules[0].ID, - ToGroupID: dg[0].Name, - FromGroupID: dg[1].Name, - Explicit: true, + ToModuleID: dg[0].Modules[0].ID, + FromModuleID: "", + ToGroupID: dg[0].Name, + FromGroupID: dg[1].Name, + Explicit: true, } - c.Assert(xRef1ToA0.validate(dg), IsNil) + c.Assert(xRef1ToA0.validate(bp), IsNil) // An implicit intergroup reference from group 1 to module A in 0 (bad due to implicit) iRef1ToA0 := modReference{ - ID: dg[0].Modules[0].ID, - ToGroupID: dg[0].Name, - FromGroupID: dg[1].Name, - Explicit: false, + ToModuleID: dg[0].Modules[0].ID, + FromModuleID: "", + ToGroupID: dg[0].Name, + FromGroupID: dg[1].Name, + Explicit: false, } - c.Assert(iRef1ToA0.validate(dg), ErrorMatches, fmt.Sprintf("%s: .*", errorMessages["intergroupImplicit"])) + c.Assert(iRef1ToA0.validate(bp), ErrorMatches, fmt.Sprintf("%s: .*", errorMessages["intergroupImplicit"])) // An explicit intergroup reference from group 0 to module 1 in 1 (bad due to group ordering) xRefA0To1 := modReference{ - ID: dg[1].Modules[0].ID, - ToGroupID: dg[1].Name, - FromGroupID: dg[0].Name, - Explicit: true, + ToModuleID: dg[1].Modules[0].ID, + FromModuleID: "", + ToGroupID: dg[1].Name, + FromGroupID: dg[0].Name, + Explicit: true, } - c.Assert(xRefA0To1.validate(dg), ErrorMatches, fmt.Sprintf("%s: .*", errorMessages["intergroupOrder"])) + c.Assert(xRefA0To1.validate(bp), ErrorMatches, fmt.Sprintf("%s: .*", errorMessages["intergroupOrder"])) // An explicit intergroup reference from group 0 to B0 with a bad Group ID badRef0ToB0 := modReference{ - ID: dg[0].Modules[1].ID, - ToGroupID: dg[1].Name, - FromGroupID: dg[0].Name, - Explicit: true, + ToModuleID: dg[0].Modules[1].ID, + FromModuleID: "", + ToGroupID: dg[1].Name, + FromGroupID: dg[0].Name, + Explicit: true, } - c.Assert(badRef0ToB0.validate(dg), ErrorMatches, fmt.Sprintf("%s: .*", errorMessages["referenceWrongGroup"])) + c.Assert(badRef0ToB0.validate(bp), ErrorMatches, fmt.Sprintf("%s: .*", errorMessages["referenceWrongGroup"])) // A target module that doesn't exist (bad) badTargetMod := modReference{ - ID: "bad-module", - ToGroupID: dg[0].Name, - FromGroupID: dg[0].Name, - Explicit: true, + ToModuleID: "bad-module", + FromModuleID: "", + ToGroupID: dg[0].Name, + FromGroupID: dg[0].Name, + Explicit: true, } - c.Assert(badTargetMod.validate(dg), ErrorMatches, fmt.Sprintf("module bad-module was not found")) + c.Assert(badTargetMod.validate(bp), ErrorMatches, "module bad-module was not found") // A source group ID that doesn't exist (bad) badSourceGroup := modReference{ - ID: dg[0].Modules[0].ID, - ToGroupID: dg[0].Name, - FromGroupID: "bad-group", - Explicit: true, + ToModuleID: dg[0].Modules[0].ID, + FromModuleID: "", + ToGroupID: dg[0].Name, + FromGroupID: "bad-group", + Explicit: true, } - c.Assert(badSourceGroup.validate(dg), ErrorMatches, fmt.Sprintf("%s: .*", errorMessages["groupNotFound"])) + c.Assert(badSourceGroup.validate(bp), ErrorMatches, fmt.Sprintf("%s: .*", errorMessages["groupNotFound"])) } func (s *MySuite) TestIdentifySimpleVariable(c *C) { @@ -681,7 +692,7 @@ func (s *MySuite) TestIdentifySimpleVariable(c *C) { c.Assert(err, IsNil) c.Assert(ref.ToGroupID, Equals, "group_id") c.Assert(ref.FromGroupID, Equals, dg.Name) - c.Assert(ref.ID, Equals, "module_id") + c.Assert(ref.ToModuleID, Equals, "module_id") c.Assert(ref.Name, Equals, "output_name") c.Assert(ref.Explicit, Equals, true) @@ -689,7 +700,7 @@ func (s *MySuite) TestIdentifySimpleVariable(c *C) { c.Assert(err, IsNil) c.Assert(ref.ToGroupID, Equals, "calling_group_id") c.Assert(ref.FromGroupID, Equals, "calling_group_id") - c.Assert(ref.ID, Equals, "module_id") + c.Assert(ref.ToModuleID, Equals, "module_id") c.Assert(ref.Name, Equals, "output_name") c.Assert(ref.Explicit, Equals, false) @@ -697,7 +708,7 @@ func (s *MySuite) TestIdentifySimpleVariable(c *C) { c.Assert(err, IsNil) c.Assert(ref.ToGroupID, Equals, "deployment") c.Assert(ref.FromGroupID, Equals, dg.Name) - c.Assert(ref.ID, Equals, "vars") + c.Assert(ref.ToModuleID, Equals, "vars") c.Assert(ref.Name, Equals, "variable_name") c.Assert(ref.Explicit, Equals, false) From 701af72a2dcc3bf1de28b711ee35e97ceae60059 Mon Sep 17 00:00:00 2001 From: Tom Downes Date: Thu, 23 Mar 2023 15:24:02 -0500 Subject: [PATCH 2/2] Address feedback in #1078 --- pkg/config/config.go | 6 +- pkg/config/config_test.go | 30 +++--- pkg/config/expand.go | 200 +++++++++++++++++++------------------- pkg/config/expand_test.go | 124 +++++++++++------------ 4 files changed, 180 insertions(+), 180 deletions(-) diff --git a/pkg/config/config.go b/pkg/config/config.go index 07f6fe1ddb..a8f6bf37c0 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -319,8 +319,8 @@ func (dc *DeploymentConfig) listUnusedModules() map[string][]string { unusedModules := make(map[string][]string) for _, conn := range dc.moduleConnections { if conn.isEmpty() { - fromMod := conn.ref.getFromModuleID() - unusedModules[fromMod] = append(unusedModules[fromMod], conn.ref.getToModuleID()) + fromMod := conn.ref.FromModuleID() + unusedModules[fromMod] = append(unusedModules[fromMod], conn.ref.ToModuleID()) } } return unusedModules @@ -520,7 +520,7 @@ func checkUsedModuleNames(bp Blueprint) error { } // TODO: remove this when support is added! - if ref.FromGroupID != ref.ToGroupID { + if ref.fromGroupID != ref.toGroupID { return fmt.Errorf("%s: %s is an intergroup reference", errorMessages["varInAnotherGroup"], usedMod) } diff --git a/pkg/config/config_test.go b/pkg/config/config_test.go index c30540cdca..ad4880b5f0 100644 --- a/pkg/config/config_test.go +++ b/pkg/config/config_test.go @@ -403,11 +403,11 @@ func (s *MySuite) TestListUnusedModules(c *C) { // test used module with shared variables usedConn := ModConnection{ ref: modReference{ - ToModuleID: "usedModule", - FromModuleID: "usingModule", - ToGroupID: "group1", - FromGroupID: "group1", - Explicit: true, + toModuleID: "usedModule", + fromModuleID: "usingModule", + toGroupID: "group1", + fromGroupID: "group1", + explicit: true, }, kind: useConnection, sharedVariables: []string{"var1"}, @@ -419,11 +419,11 @@ func (s *MySuite) TestListUnusedModules(c *C) { // test used module with no shared variables (i.e. "unused") unusedConn := ModConnection{ ref: modReference{ - ToModuleID: "firstUnusedModule", - FromModuleID: "usingModule", - ToGroupID: "group1", - FromGroupID: "group1", - Explicit: true, + toModuleID: "firstUnusedModule", + fromModuleID: "usingModule", + toGroupID: "group1", + fromGroupID: "group1", + explicit: true, }, kind: useConnection, sharedVariables: []string{}, @@ -435,11 +435,11 @@ func (s *MySuite) TestListUnusedModules(c *C) { // test second used module with no shared variables (i.e. "unused") secondUnusedConn := ModConnection{ ref: modReference{ - ToModuleID: "secondUnusedModule", - FromModuleID: "usingModule", - ToGroupID: "group1", - FromGroupID: "group1", - Explicit: true, + toModuleID: "secondUnusedModule", + fromModuleID: "usingModule", + toGroupID: "group1", + fromGroupID: "group1", + explicit: true, }, kind: useConnection, sharedVariables: []string{}, diff --git a/pkg/config/expand.go b/pkg/config/expand.go index 6554906f13..8518c70010 100644 --- a/pkg/config/expand.go +++ b/pkg/config/expand.go @@ -213,7 +213,7 @@ func useModule( for _, useOutput := range useOutputs { settingName := useOutput.Name - // Explicitly ignore these settings (typically those in blueprint) + // explicitly ignore these settings (typically those in blueprint) if slices.Contains(settingsToIgnore, settingName) { continue } @@ -268,14 +268,14 @@ func (dc *DeploymentConfig) applyUseModules() error { } // to get the module struct, we first needs its group - toGroup, err := dc.getGroupByID(modRef.ToGroupID) + toGroup, err := dc.getGroupByID(modRef.toGroupID) if err != nil { return err } // this module contains information about the target module that // was specified by the user in the blueprint - toMod, err := toGroup.getModuleByID(modRef.ToModuleID) + toMod, err := toGroup.getModuleByID(modRef.toModuleID) if err != nil { return err } @@ -294,7 +294,7 @@ func (dc *DeploymentConfig) applyUseModules() error { // tested but it our unit test infrastructure does not support // running dc.setModulesInfo() on our test configurations toModInfo := dc.ModulesInfo[toGroup.Name][toMod.Source] - usedVars, err := useModule(fromMod, toMod, modRef.ToGroupID, + usedVars, err := useModule(fromMod, toMod, modRef.toGroupID, fromModInfo.Inputs, toModInfo.Outputs, settingsInBlueprint) if err != nil { return err @@ -514,44 +514,44 @@ type varContext struct { type reference interface { validate(Blueprint) error - isIntergroup() bool + IsIntergroup() bool String() string - getFromModuleID() string - getToModuleID() string + FromModuleID() string + ToModuleID() string } /* A module reference is made by the use keyword and is subject to IGC constraints of references (ordering, explicitness). It has the following fields: - - ToModuleID: the target module ID - - FromModuleID: the source module ID - - ToGroupID: the deployment group in which the module is *expected* to be found - - FromGroupID: the deployment group from which the reference is made - - Explicit: a boolean value indicating whether the user made a reference that - explicitly identified ToGroupID rather than inferring it using FromGroupID + - toModuleID: the target module ID + - fromModuleID: the source module ID + - toGroupID: the deployment group in which the module is *expected* to be found + - fromGroupID: the deployment group from which the reference is made + - explicit: a boolean value indicating whether the user made a reference that + explicitly identified toGroupID rather than inferring it using fromGroupID */ type modReference struct { - ToModuleID string - FromModuleID string - ToGroupID string - FromGroupID string - Explicit bool + toModuleID string + fromModuleID string + toGroupID string + fromGroupID string + explicit bool } func (ref modReference) String() string { - return ref.ToGroupID + "." + ref.ToModuleID + return ref.toGroupID + "." + ref.toModuleID } -func (ref modReference) isIntergroup() bool { - return ref.ToGroupID == ref.FromGroupID +func (ref modReference) IsIntergroup() bool { + return ref.toGroupID == ref.fromGroupID } -func (ref modReference) getFromModuleID() string { - return ref.FromModuleID +func (ref modReference) FromModuleID() string { + return ref.fromModuleID } -func (ref modReference) getToModuleID() string { - return ref.FromModuleID +func (ref modReference) ToModuleID() string { + return ref.toModuleID } /* @@ -568,21 +568,21 @@ func identifyModuleByReference(yamlReference string, dg DeploymentGroup) (modRef modComponents := strings.Split(yamlReference, ".") switch len(modComponents) { case 1: - ref.ToModuleID = modComponents[0] - ref.ToGroupID = dg.Name - ref.FromGroupID = dg.Name + ref.toModuleID = modComponents[0] + ref.toGroupID = dg.Name + ref.fromGroupID = dg.Name case 2: - ref.ToGroupID = modComponents[0] - ref.ToModuleID = modComponents[1] - ref.FromGroupID = dg.Name - ref.Explicit = true + ref.toGroupID = modComponents[0] + ref.toModuleID = modComponents[1] + ref.fromGroupID = dg.Name + ref.explicit = true } // should consider more sophisticated definition of valid values here. // for now check that no fields are the empty string; due to the default // zero values for strings in the "ref" struct, this will also cover the // case that modComponents has wrong # of fields - if ref.ToModuleID == "" || ref.ToGroupID == "" || ref.FromGroupID == "" { + if ref.toModuleID == "" || ref.toGroupID == "" || ref.fromGroupID == "" { return ref, fmt.Errorf("%s: %s, expected %s", errorMessages["invalidMod"], yamlReference, expectedModFormat) } @@ -593,36 +593,36 @@ func identifyModuleByReference(yamlReference string, dg DeploymentGroup) (modRef /* A variable reference has the following fields - Name: the name of the module output or deployment variable - - ToModuleID: the target module ID or "vars" if referring to a deployment variable - - FromModuleID: the source module ID - - ToGroupID: the deployment group in which the module is *expected* to be found - - FromGroupID: the deployment group from which the reference is made - - Explicit: a boolean value indicating whether the user made a reference that - explicitly identified ToGroupID rather than inferring it using FromGroupID + - toModuleID: the target module ID or "vars" if referring to a deployment variable + - fromModuleID: the source module ID + - toGroupID: the deployment group in which the module is *expected* to be found + - fromGroupID: the deployment group from which the reference is made + - explicit: a boolean value indicating whether the user made a reference that + explicitly identified toGroupID rather than inferring it using fromGroupID */ type varReference struct { - Name string - ToModuleID string - FromModuleID string - ToGroupID string - FromGroupID string - Explicit bool + name string + toModuleID string + fromModuleID string + toGroupID string + fromGroupID string + explicit bool } func (ref varReference) String() string { - return ref.ToGroupID + "." + ref.ToModuleID + "." + ref.Name + return ref.toGroupID + "." + ref.toModuleID + "." + ref.name } -func (ref varReference) isIntergroup() bool { - return ref.ToGroupID == ref.FromGroupID +func (ref varReference) IsIntergroup() bool { + return ref.toGroupID == ref.fromGroupID } -func (ref varReference) getFromModuleID() string { - return ref.FromModuleID +func (ref varReference) FromModuleID() string { + return ref.fromModuleID } -func (ref varReference) getToModuleID() string { - return ref.FromModuleID +func (ref varReference) ToModuleID() string { + return ref.toModuleID } /* @@ -637,31 +637,31 @@ func identifySimpleVariable(yamlReference string, dg DeploymentGroup) (varRefere // struct defaults: empty strings and false booleans var ref varReference - ref.FromGroupID = dg.Name + ref.fromGroupID = dg.Name // intra-group references length 2 and inter-group references length 3 switch len(varComponents) { case 2: - ref.ToModuleID = varComponents[0] - ref.Name = varComponents[1] + ref.toModuleID = varComponents[0] + ref.name = varComponents[1] - if ref.ToModuleID == "vars" { - ref.ToGroupID = "deployment" + if ref.toModuleID == "vars" { + ref.toGroupID = "deployment" } else { - ref.ToGroupID = dg.Name + ref.toGroupID = dg.Name } case 3: - ref.ToGroupID = varComponents[0] - ref.ToModuleID = varComponents[1] - ref.Name = varComponents[2] - ref.Explicit = true + ref.toGroupID = varComponents[0] + ref.toModuleID = varComponents[1] + ref.name = varComponents[2] + ref.explicit = true } // should consider more sophisticated definition of valid values here. // for now check that source and name are not empty strings; due to the // default zero values for strings in the "ref" struct, this will also // cover the case that varComponents has wrong # of fields - if ref.FromGroupID == "" || ref.ToGroupID == "" || ref.ToModuleID == "" || ref.Name == "" { + if ref.fromGroupID == "" || ref.toGroupID == "" || ref.toModuleID == "" || ref.name == "" { return varReference{}, fmt.Errorf("%s %s, expected format: %s", errorMessages["invalidVar"], yamlReference, expectedVarFormat) } @@ -669,12 +669,12 @@ func identifySimpleVariable(yamlReference string, dg DeploymentGroup) (varRefere } func (ref modReference) validate(bp Blueprint) error { - callingModuleGroupIndex := slices.IndexFunc(bp.DeploymentGroups, func(d DeploymentGroup) bool { return d.Name == ref.FromGroupID }) + callingModuleGroupIndex := slices.IndexFunc(bp.DeploymentGroups, func(d DeploymentGroup) bool { return d.Name == ref.fromGroupID }) if callingModuleGroupIndex == -1 { - return fmt.Errorf("%s: %s", errorMessages["groupNotFound"], ref.FromGroupID) + return fmt.Errorf("%s: %s", errorMessages["groupNotFound"], ref.fromGroupID) } - targetModuleGroupIndex, err := modToGrp(bp.DeploymentGroups, ref.ToModuleID) + targetModuleGroupIndex, err := modToGrp(bp.DeploymentGroups, ref.toModuleID) if err != nil { return err } @@ -683,17 +683,17 @@ func (ref modReference) validate(bp Blueprint) error { // Ensure module is from the correct group isInterGroupReference := callingModuleGroupIndex != targetModuleGroupIndex isRefToLaterGroup := targetModuleGroupIndex > callingModuleGroupIndex - isCorrectToGroup := ref.ToGroupID == targetModuleGroupName + isCorrectToGroup := ref.toGroupID == targetModuleGroupName if isInterGroupReference { if isRefToLaterGroup { return fmt.Errorf("%s: %s is in a later group", - errorMessages["intergroupOrder"], ref.ToModuleID) + errorMessages["intergroupOrder"], ref.toModuleID) } - if !ref.Explicit { + if !ref.explicit { return fmt.Errorf("%s: %s must specify a group ID before the module ID", - errorMessages["intergroupImplicit"], ref.ToModuleID) + errorMessages["intergroupImplicit"], ref.toModuleID) } } @@ -702,7 +702,7 @@ func (ref modReference) validate(bp Blueprint) error { // error after enforcing explicitness of intergroup references if !isCorrectToGroup { return fmt.Errorf("%s: %s.%s", - errorMessages["referenceWrongGroup"], ref.ToGroupID, ref.ToModuleID) + errorMessages["referenceWrongGroup"], ref.toGroupID, ref.toModuleID) } return nil @@ -712,50 +712,50 @@ func (ref modReference) validate(bp Blueprint) error { // the reference must be to the same or earlier group. // ref.GroupID: this group must exist or be the value "deployment" // ref.ID: must be an existing module ID or "vars" (if groupID is "deployment") -// ref.Name: must match a module output name or deployment variable name -// ref.ExplicitInterGroup: intergroup references must explicitly identify the +// ref.name: must match a module output name or deployment variable name +// ref.explicitInterGroup: intergroup references must explicitly identify the // target group ID and intragroup references cannot have an incorrect explicit // group ID func (ref *varReference) validate(bp Blueprint) error { // simplest case to evaluate is a deployment variable's existence - if ref.ToGroupID == "deployment" { - if ref.ToModuleID == "vars" { - if _, ok := bp.Vars[ref.Name]; !ok { + if ref.toGroupID == "deployment" { + if ref.toModuleID == "vars" { + if _, ok := bp.Vars[ref.name]; !ok { return fmt.Errorf("%s: %s is not a deployment variable", - errorMessages["varNotFound"], ref.Name) + errorMessages["varNotFound"], ref.name) } return nil } return fmt.Errorf("%s: %s", errorMessages["invalidDeploymentRef"], ref) } - targetModuleGroupIndex, err := modToGrp(bp.DeploymentGroups, ref.ToModuleID) + targetModuleGroupIndex, err := modToGrp(bp.DeploymentGroups, ref.toModuleID) if err != nil { return err } targetModuleGroup := bp.DeploymentGroups[targetModuleGroupIndex] - callingModuleGroupIndex := slices.IndexFunc(bp.DeploymentGroups, func(d DeploymentGroup) bool { return d.Name == ref.FromGroupID }) + callingModuleGroupIndex := slices.IndexFunc(bp.DeploymentGroups, func(d DeploymentGroup) bool { return d.Name == ref.fromGroupID }) if callingModuleGroupIndex == -1 { - return fmt.Errorf("%s: %s", errorMessages["groupNotFound"], ref.FromGroupID) + return fmt.Errorf("%s: %s", errorMessages["groupNotFound"], ref.fromGroupID) } // at this point, we know the target module exists. now record whether it // is intergroup and whether it comes in a (disallowed) later group isInterGroupReference := targetModuleGroupIndex != callingModuleGroupIndex isRefToLaterGroup := targetModuleGroupIndex > callingModuleGroupIndex - isCorrectToGroup := ref.ToGroupID == targetModuleGroup.Name + isCorrectToGroup := ref.toGroupID == targetModuleGroup.Name // intergroup references must be explicit about group and refer to an earlier group; if isInterGroupReference { if isRefToLaterGroup { return fmt.Errorf("%s: %s is in the later group %s", - errorMessages["intergroupOrder"], ref.ToModuleID, ref.ToGroupID) + errorMessages["intergroupOrder"], ref.toModuleID, ref.toGroupID) } - if !ref.Explicit { + if !ref.explicit { return fmt.Errorf("%s: %s must specify the group ID %s before the module ID", - errorMessages["intergroupImplicit"], ref.ToModuleID, ref.ToGroupID) + errorMessages["intergroupImplicit"], ref.toModuleID, ref.toGroupID) } } @@ -764,15 +764,15 @@ func (ref *varReference) validate(bp Blueprint) error { // error after enforcing explicitness of intergroup references if !isCorrectToGroup { return fmt.Errorf("%s: %s.%s should be %s.%s", - errorMessages["referenceWrongGroup"], ref.ToGroupID, ref.ToModuleID, targetModuleGroup.Name, ref.ToModuleID) + errorMessages["referenceWrongGroup"], ref.toGroupID, ref.toModuleID, targetModuleGroup.Name, ref.toModuleID) } // at this point, we have a valid intragroup or intergroup references to a // module. must now determine whether the output value actually exists in // the module. - refModIndex := slices.IndexFunc(targetModuleGroup.Modules, func(m Module) bool { return m.ID == ref.ToModuleID }) + refModIndex := slices.IndexFunc(targetModuleGroup.Modules, func(m Module) bool { return m.ID == ref.toModuleID }) if refModIndex == -1 { - log.Fatalf("Could not find module %s", ref.ToModuleID) + log.Fatalf("Could not find module %s", ref.toModuleID) } refMod := targetModuleGroup.Modules[refModIndex] modInfo, err := modulereader.GetModuleInfo(refMod.Source, refMod.Kind) @@ -781,10 +781,10 @@ func (ref *varReference) validate(bp Blueprint) error { "failed to get info for module at %s while expanding variables: %e", refMod.Source, err) } - found := slices.ContainsFunc(modInfo.Outputs, func(o modulereader.VarInfo) bool { return o.Name == ref.Name }) + found := slices.ContainsFunc(modInfo.Outputs, func(o modulereader.VarInfo) bool { return o.Name == ref.name }) if !found { return fmt.Errorf("%s: module %s did not have output %s", - errorMessages["noOutput"], refMod.ID, ref.Name) + errorMessages["noOutput"], refMod.ID, ref.name) } return nil @@ -813,37 +813,37 @@ func expandSimpleVariable(context varContext) (string, error) { } var expandedVariable string - switch varRef.ToGroupID { + switch varRef.toGroupID { case "deployment": // deployment variables - expandedVariable = fmt.Sprintf("((var.%s))", varRef.Name) - case varRef.FromGroupID: + expandedVariable = fmt.Sprintf("((var.%s))", varRef.name) + case varRef.fromGroupID: // intragroup reference can make direct reference to module output - expandedVariable = fmt.Sprintf("((module.%s.%s))", varRef.ToModuleID, varRef.Name) + expandedVariable = fmt.Sprintf("((module.%s.%s))", varRef.toModuleID, varRef.name) default: // intergroup reference; begin by finding the target module in blueprint toGrpIdx := slices.IndexFunc( context.blueprint.DeploymentGroups, - func(g DeploymentGroup) bool { return g.Name == varRef.ToGroupID }) + func(g DeploymentGroup) bool { return g.Name == varRef.toGroupID }) if toGrpIdx == -1 { - return "", fmt.Errorf("invalid group reference: %s", varRef.ToGroupID) + return "", fmt.Errorf("invalid group reference: %s", varRef.toGroupID) } toGrp := context.blueprint.DeploymentGroups[toGrpIdx] - toModIdx := slices.IndexFunc(toGrp.Modules, func(m Module) bool { return m.ID == varRef.ToModuleID }) + toModIdx := slices.IndexFunc(toGrp.Modules, func(m Module) bool { return m.ID == varRef.toModuleID }) if toModIdx == -1 { - return "", fmt.Errorf("%s: %s", errorMessages["invalidMod"], varRef.ToModuleID) + return "", fmt.Errorf("%s: %s", errorMessages["invalidMod"], varRef.toModuleID) } toMod := toGrp.Modules[toModIdx] // ensure that the target module outputs the value in the root module // state and not just internally within its deployment group - if !slices.Contains(toMod.Outputs, varRef.Name) { - toMod.Outputs = append(toMod.Outputs, varRef.Name) + if !slices.Contains(toMod.Outputs, varRef.name) { + toMod.Outputs = append(toMod.Outputs, varRef.name) } - // TODO: expandedVariable = fmt.Sprintf("((var.%s_%s))", ref.Name, ref.ID) + // TODO: expandedVariable = fmt.Sprintf("((var.%s_%s))", ref.name, ref.ID) return "", fmt.Errorf("%s: %s is an intergroup reference", errorMessages["varInAnotherGroup"], context.varString) } diff --git a/pkg/config/expand_test.go b/pkg/config/expand_test.go index 9fdb974567..b7f4f7be1e 100644 --- a/pkg/config/expand_test.go +++ b/pkg/config/expand_test.go @@ -553,24 +553,24 @@ func (s *MySuite) TestIdentifyModuleByReference(c *C) { ref, err = identifyModuleByReference("module_id", dg) c.Assert(err, IsNil) - c.Assert(ref.ToGroupID, Equals, dg.Name) - c.Assert(ref.FromGroupID, Equals, dg.Name) - c.Assert(ref.ToModuleID, Equals, "module_id") - c.Assert(ref.Explicit, Equals, false) + c.Assert(ref.toGroupID, Equals, dg.Name) + c.Assert(ref.fromGroupID, Equals, dg.Name) + c.Assert(ref.toModuleID, Equals, "module_id") + c.Assert(ref.explicit, Equals, false) ref, err = identifyModuleByReference("explicit_group_id.module_id", dg) c.Assert(err, IsNil) - c.Assert(ref.ToGroupID, Equals, "explicit_group_id") - c.Assert(ref.FromGroupID, Equals, dg.Name) - c.Assert(ref.ToModuleID, Equals, "module_id") - c.Assert(ref.Explicit, Equals, true) + c.Assert(ref.toGroupID, Equals, "explicit_group_id") + c.Assert(ref.fromGroupID, Equals, dg.Name) + c.Assert(ref.toModuleID, Equals, "module_id") + c.Assert(ref.explicit, Equals, true) ref, err = identifyModuleByReference(fmt.Sprintf("%s.module_id", dg.Name), dg) c.Assert(err, IsNil) - c.Assert(ref.ToGroupID, Equals, dg.Name) - c.Assert(ref.FromGroupID, Equals, dg.Name) - c.Assert(ref.ToModuleID, Equals, "module_id") - c.Assert(ref.Explicit, Equals, true) + c.Assert(ref.toGroupID, Equals, dg.Name) + c.Assert(ref.fromGroupID, Equals, dg.Name) + c.Assert(ref.toModuleID, Equals, "module_id") + c.Assert(ref.explicit, Equals, true) ref, err = identifyModuleByReference("explicit_group_id.module_id.output_name", dg) c.Assert(err, ErrorMatches, fmt.Sprintf("%s: .*", errorMessages["invalidMod"])) @@ -611,71 +611,71 @@ func (s *MySuite) TestValidateModuleReference(c *C) { // An intragroup reference from group 0 to module B in 0 (good) ref0ToB0 := modReference{ - ToModuleID: dg[0].Modules[1].ID, - FromModuleID: "", - ToGroupID: dg[0].Name, - FromGroupID: dg[0].Name, - Explicit: false, + toModuleID: dg[0].Modules[1].ID, + fromModuleID: "", + toGroupID: dg[0].Name, + fromGroupID: dg[0].Name, + explicit: false, } c.Assert(ref0ToB0.validate(bp), IsNil) // An explicit intergroup reference from group 1 to module A in 0 (good) xRef1ToA0 := modReference{ - ToModuleID: dg[0].Modules[0].ID, - FromModuleID: "", - ToGroupID: dg[0].Name, - FromGroupID: dg[1].Name, - Explicit: true, + toModuleID: dg[0].Modules[0].ID, + fromModuleID: "", + toGroupID: dg[0].Name, + fromGroupID: dg[1].Name, + explicit: true, } c.Assert(xRef1ToA0.validate(bp), IsNil) // An implicit intergroup reference from group 1 to module A in 0 (bad due to implicit) iRef1ToA0 := modReference{ - ToModuleID: dg[0].Modules[0].ID, - FromModuleID: "", - ToGroupID: dg[0].Name, - FromGroupID: dg[1].Name, - Explicit: false, + toModuleID: dg[0].Modules[0].ID, + fromModuleID: "", + toGroupID: dg[0].Name, + fromGroupID: dg[1].Name, + explicit: false, } c.Assert(iRef1ToA0.validate(bp), ErrorMatches, fmt.Sprintf("%s: .*", errorMessages["intergroupImplicit"])) // An explicit intergroup reference from group 0 to module 1 in 1 (bad due to group ordering) xRefA0To1 := modReference{ - ToModuleID: dg[1].Modules[0].ID, - FromModuleID: "", - ToGroupID: dg[1].Name, - FromGroupID: dg[0].Name, - Explicit: true, + toModuleID: dg[1].Modules[0].ID, + fromModuleID: "", + toGroupID: dg[1].Name, + fromGroupID: dg[0].Name, + explicit: true, } c.Assert(xRefA0To1.validate(bp), ErrorMatches, fmt.Sprintf("%s: .*", errorMessages["intergroupOrder"])) // An explicit intergroup reference from group 0 to B0 with a bad Group ID badRef0ToB0 := modReference{ - ToModuleID: dg[0].Modules[1].ID, - FromModuleID: "", - ToGroupID: dg[1].Name, - FromGroupID: dg[0].Name, - Explicit: true, + toModuleID: dg[0].Modules[1].ID, + fromModuleID: "", + toGroupID: dg[1].Name, + fromGroupID: dg[0].Name, + explicit: true, } c.Assert(badRef0ToB0.validate(bp), ErrorMatches, fmt.Sprintf("%s: .*", errorMessages["referenceWrongGroup"])) // A target module that doesn't exist (bad) badTargetMod := modReference{ - ToModuleID: "bad-module", - FromModuleID: "", - ToGroupID: dg[0].Name, - FromGroupID: dg[0].Name, - Explicit: true, + toModuleID: "bad-module", + fromModuleID: "", + toGroupID: dg[0].Name, + fromGroupID: dg[0].Name, + explicit: true, } c.Assert(badTargetMod.validate(bp), ErrorMatches, "module bad-module was not found") // A source group ID that doesn't exist (bad) badSourceGroup := modReference{ - ToModuleID: dg[0].Modules[0].ID, - FromModuleID: "", - ToGroupID: dg[0].Name, - FromGroupID: "bad-group", - Explicit: true, + toModuleID: dg[0].Modules[0].ID, + fromModuleID: "", + toGroupID: dg[0].Name, + fromGroupID: "bad-group", + explicit: true, } c.Assert(badSourceGroup.validate(bp), ErrorMatches, fmt.Sprintf("%s: .*", errorMessages["groupNotFound"])) } @@ -690,27 +690,27 @@ func (s *MySuite) TestIdentifySimpleVariable(c *C) { ref, err = identifySimpleVariable("group_id.module_id.output_name", dg) c.Assert(err, IsNil) - c.Assert(ref.ToGroupID, Equals, "group_id") - c.Assert(ref.FromGroupID, Equals, dg.Name) - c.Assert(ref.ToModuleID, Equals, "module_id") - c.Assert(ref.Name, Equals, "output_name") - c.Assert(ref.Explicit, Equals, true) + c.Assert(ref.toGroupID, Equals, "group_id") + c.Assert(ref.fromGroupID, Equals, dg.Name) + c.Assert(ref.toModuleID, Equals, "module_id") + c.Assert(ref.name, Equals, "output_name") + c.Assert(ref.explicit, Equals, true) ref, err = identifySimpleVariable("module_id.output_name", dg) c.Assert(err, IsNil) - c.Assert(ref.ToGroupID, Equals, "calling_group_id") - c.Assert(ref.FromGroupID, Equals, "calling_group_id") - c.Assert(ref.ToModuleID, Equals, "module_id") - c.Assert(ref.Name, Equals, "output_name") - c.Assert(ref.Explicit, Equals, false) + c.Assert(ref.toGroupID, Equals, "calling_group_id") + c.Assert(ref.fromGroupID, Equals, "calling_group_id") + c.Assert(ref.toModuleID, Equals, "module_id") + c.Assert(ref.name, Equals, "output_name") + c.Assert(ref.explicit, Equals, false) ref, err = identifySimpleVariable("vars.variable_name", dg) c.Assert(err, IsNil) - c.Assert(ref.ToGroupID, Equals, "deployment") - c.Assert(ref.FromGroupID, Equals, dg.Name) - c.Assert(ref.ToModuleID, Equals, "vars") - c.Assert(ref.Name, Equals, "variable_name") - c.Assert(ref.Explicit, Equals, false) + c.Assert(ref.toGroupID, Equals, "deployment") + c.Assert(ref.fromGroupID, Equals, dg.Name) + c.Assert(ref.toModuleID, Equals, "vars") + c.Assert(ref.name, Equals, "variable_name") + c.Assert(ref.explicit, Equals, false) ref, err = identifySimpleVariable("foo", dg) c.Assert(err, NotNil)