From 82da0f9e403fa4f4d3e92b8f16255ef88c501fdd Mon Sep 17 00:00:00 2001 From: William Dumont Date: Thu, 21 Dec 2023 10:33:56 +0100 Subject: [PATCH] add import tests --- .../internal/controller/module_references.go | 8 +- pkg/flow/module_import_test.go | 87 ++++++++++++++++++- 2 files changed, 93 insertions(+), 2 deletions(-) diff --git a/pkg/flow/internal/controller/module_references.go b/pkg/flow/internal/controller/module_references.go index 69b4dbb562e7..338203b05a14 100644 --- a/pkg/flow/internal/controller/module_references.go +++ b/pkg/flow/internal/controller/module_references.go @@ -61,7 +61,13 @@ func getModuleReferences( default: parts := strings.Split(fullName, ".") namespace := parts[0] - scopedName := parts[len(parts)-1] + var scopedName string + if len(parts) > 1 { + scopedName = strings.Join(parts[1:], ".") + } else { + scopedName = parts[len(parts)-1] + } + if declareNode, ok := declareNodes[namespace]; ok { uniqueReferences[fullName] = ModuleReference{fullName: fullName, scopedName: scopedName, moduleContentProvider: declareNode} } else if importNode, ok := importNodes[namespace]; ok { diff --git a/pkg/flow/module_import_test.go b/pkg/flow/module_import_test.go index 2a676b03b6b3..0637059ce610 100644 --- a/pkg/flow/module_import_test.go +++ b/pkg/flow/module_import_test.go @@ -213,6 +213,11 @@ func TestImportModule(t *testing.T) { } declare "anotherModule" { + testcomponents.count "inc" { + frequency = "10ms" + max = 10 + } + testImport.otherModule.test "myModule" { input = testcomponents.count.inc.count } @@ -240,6 +245,87 @@ func TestImportModule(t *testing.T) { lag = "1ms" } + export "output" { + value = -10 + } + } + ` + }, + updateFile: "other_module", + }, + { + name: "TestImportModuleDepth2", + module: ` + import.file "otherModule" { + filename = "other_module" + } + `, + otherModule: ` + declare "test" { + argument "input" { + optional = false + } + + testcomponents.passthrough "pt" { + input = argument.input.value + lag = "1ms" + } + + export "output" { + value = testcomponents.passthrough.pt.output + } + } + `, + config: ` + testcomponents.count "inc" { + frequency = "10ms" + max = 10 + } + + import.file "testImport" { + filename = "my_module" + } + + declare "yetAgainAnotherModule" { + declare "anotherModule" { + testcomponents.count "inc" { + frequency = "10ms" + max = 10 + } + + testImport.otherModule.test "myModule" { + input = testcomponents.count.inc.count + } + + export "output" { + value = testImport.otherModule.test.myModule.output + } + } + anotherModule "myOtherModule" {} + + export "output" { + value = anotherModule.myOtherModule.output + } + } + + yetAgainAnotherModule "default" {} + + testcomponents.summation "sum" { + input = yetAgainAnotherModule.default.output + } + `, + updateModule: func(filename string) string { + return ` + declare "test" { + argument "input" { + optional = false + } + + testcomponents.passthrough "pt" { + input = argument.input.value + lag = "1ms" + } + export "output" { value = -10 } @@ -262,7 +348,6 @@ func TestImportModule(t *testing.T) { defer os.Remove(otherFilename) } - // Setup and run controller ctrl := flow.New(testOptions(t)) f, err := flow.ParseSource(t.Name(), []byte(tc.config)) require.NoError(t, err)