add URI.FindIn(SearchPath) to resolve relative paths
Some checks failed
Lint / golangci-lint (push) Failing after 10m3s
Declarative Tests / test (push) Failing after 19s

This commit is contained in:
Matthew Rich 2025-07-25 07:08:40 +00:00
parent 35899c86a5
commit 1b0cd57284
2 changed files with 17 additions and 0 deletions

View File

@ -57,6 +57,13 @@ func (u URI) Parse() data.URIParser {
return nil
}
func (u *URI) FindIn(s *SearchPath) {
if s == nil {
s = NewSearchPath(ConfigKey("system.importpath").GetStringSlice())
}
*u = s.FindURI(*u)
}
func (u URI) Exists() bool {
return transport.ExistsURI(string(u))
}

View File

@ -37,3 +37,13 @@ func TestURINewResource(t *testing.T) {
}
func TestURIFindIn(t *testing.T) {
searchPath := NewSearchPath(ConfigKey("system.importpath").GetStringSlice())
assert.Nil(t, searchPath.AddPath(string(TempDir)))
assert.Nil(t, TempDir.CreateFile("bar", "testdata"))
var file URI = "file://bar"
file.FindIn(searchPath)
assert.True(t, file.Exists())
assert.Equal(t, string(file), fmt.Sprintf("file://%s/bar", TempDir))
}