Skip to content

Commit c848651

Browse files
committed
improve check logic
1 parent b8d45e3 commit c848651

File tree

2 files changed

+58
-5
lines changed

2 files changed

+58
-5
lines changed

input/input_test.go

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1244,13 +1244,59 @@ func TestModuleParams_GetUndefinedModulesInOrder(t *testing.T) {
12441244
expected: []string{},
12451245
},
12461246
{
1247-
name: "base module covers indexed",
1247+
name: "base module defined but indexed module in order is undefined",
12481248
params: ModuleParams{
12491249
Order: []string{"topoaa", "topoaa.1"},
12501250
Topoaa: map[string]any{
12511251
"param1": "value1",
12521252
},
12531253
},
1254+
expected: []string{"topoaa.1"},
1255+
},
1256+
{
1257+
name: "indexed module defined but base module in order is undefined",
1258+
params: ModuleParams{
1259+
Order: []string{"topoaa", "topoaa.1"},
1260+
Topoaa_1: map[string]any{
1261+
"param1": "value1",
1262+
},
1263+
},
1264+
expected: []string{"topoaa"},
1265+
},
1266+
{
1267+
name: "mixed scenario",
1268+
params: ModuleParams{
1269+
Order: []string{"topoaa", "topoaa.1", "rigidbody.2", "caprieval"},
1270+
Topoaa: map[string]any{
1271+
"param1": "value1",
1272+
},
1273+
Topoaa_1: map[string]any{
1274+
"param2": "value2",
1275+
},
1276+
Rigidbody_2: map[string]any{
1277+
"param3": "value3",
1278+
},
1279+
},
1280+
expected: []string{"caprieval"},
1281+
},
1282+
{
1283+
name: "only base module defined and in order",
1284+
params: ModuleParams{
1285+
Order: []string{"topoaa"},
1286+
Topoaa: map[string]any{
1287+
"param1": "value1",
1288+
},
1289+
},
1290+
expected: []string{},
1291+
},
1292+
{
1293+
name: "only indexed module defined and in order",
1294+
params: ModuleParams{
1295+
Order: []string{"topoaa.1"},
1296+
Topoaa_1: map[string]any{
1297+
"param1": "value1",
1298+
},
1299+
},
12541300
expected: []string{},
12551301
},
12561302
}

input/module-struct.go

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -783,13 +783,20 @@ func (mp ModuleParams) GetUndefinedModulesInOrder() []string {
783783
for _, moduleInOrder := range mp.Order {
784784
found := false
785785
for definedModule := range definedModules {
786-
// Check exact match or base module match (e.g., "alascan.1" vs "alascan")
787-
if definedModule == moduleInOrder ||
788-
strings.HasPrefix(definedModule, moduleInOrder+".") ||
789-
strings.HasPrefix(moduleInOrder, definedModule+".") {
786+
// Check exact match only
787+
if definedModule == moduleInOrder {
790788
found = true
791789
break
792790
}
791+
// Check if this is an indexed version and the exact indexed module is defined
792+
// For example: if moduleInOrder is "topoaa.1" and "topoaa.1" is explicitly defined
793+
if strings.Contains(moduleInOrder, ".") {
794+
// Only match if the exact indexed module is defined
795+
if definedModule == moduleInOrder {
796+
found = true
797+
break
798+
}
799+
}
793800
}
794801
if !found {
795802
undefined = append(undefined, moduleInOrder)

0 commit comments

Comments
 (0)