Skip to content

Commit

Permalink
add import tests
Browse files Browse the repository at this point in the history
  • Loading branch information
wildum committed Dec 21, 2023
1 parent 9a80ebf commit 82da0f9
Show file tree
Hide file tree
Showing 2 changed files with 93 additions and 2 deletions.
8 changes: 7 additions & 1 deletion pkg/flow/internal/controller/module_references.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
87 changes: 86 additions & 1 deletion pkg/flow/module_import_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}
Expand All @@ -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)
Expand Down

0 comments on commit 82da0f9

Please sign in to comment.