Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions internal/test/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -550,11 +550,17 @@ func fileResolver(scriptPath string, state *flowkit.State) cdcTests.FileResolver
importFilePath := util.AbsolutePath(scriptPath, path)

content, err := state.ReadFile(importFilePath)
if err != nil {
if err == nil {
return string(content), nil
}

// Fall back to resolving relative to the project root (CWD, where flow.json lives).
projectContent, projectErr := state.ReadFile(filepath.Clean(path))
if projectErr != nil {
return "", err
}

return string(content), nil
return string(projectContent), nil
}
}

Expand Down
23 changes: 23 additions & 0 deletions internal/test/test_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,29 @@ func TestExecutingTests(t *testing.T) {
assert.NoError(t, result.Results[script.Filename][0].Error)
})

t.Run("with file read from project root when not found relative to test file", func(t *testing.T) {
_, state, rw := util.TestMocks(t)
_ = rw.WriteFile(
tests.SomeFile.Filename,
tests.SomeFile.Source,
os.ModeTemporary,
)
t.Parallel()
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you move this to the top of the function?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure but all of the tests have same setup, I just copied it, would rather leave this consistent.


// Place the test script in a subdirectory. SomeFile only exists at the
// project root, so the first lookup (relative to the script) will fail
// and the resolver must fall back to the project root.
script := tests.TestScriptWithFileRead
testFiles := map[string][]byte{
"subdir/" + script.Filename: script.Source,
}
result, err := testCode(testFiles, state, flagsTests{})

require.NoError(t, err)
require.Len(t, result.Results, 1)
assert.NoError(t, result.Results["subdir/"+script.Filename][0].Error)
})

t.Run("with code coverage", func(t *testing.T) {
// Setup
_, state, _ := util.TestMocks(t)
Expand Down
Loading