Skip to content

Commit

Permalink
more generic HasVSIHandler
Browse files Browse the repository at this point in the history
it covers the case where prefix is in handlers but handler is nil

Co-authored-by: Thomas Bonfort <thomas.bonfort@airbus.com>
  • Loading branch information
vincentvaroquauxads and tbonfort committed Sep 11, 2024
1 parent 89f29df commit d257757
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
4 changes: 2 additions & 2 deletions godal.go
Original file line number Diff line number Diff line change
Expand Up @@ -3903,8 +3903,8 @@ func HasVSIHandler(prefix string) bool {
if handlers == nil {
return false
}
_, ok := handlers[prefix]
return ok
handler, ok := handlers[prefix]
return ok && handler.KeySizerReaderAt != nil
}

// BuildVRT runs the GDALBuildVRT function and creates a VRT dataset from a list of datasets
Expand Down
18 changes: 16 additions & 2 deletions godal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3459,17 +3459,31 @@ func (mvp mvpHandler) ReadAtMulti(k string, buf [][]byte, off []int64) ([]int, e
}
return b.(KeyMultiReader).ReadAtMulti(k, buf, off)
}
func TestHasVSIHandler(t *testing.T) { // stripPrefix false
assert.False(t, HasVSIHandler("prefix://"))

vpa := vpHandler{datas: make(map[string]KeySizerReaderAt)}
err := RegisterVSIHandler("prefix://", vpa, VSIHandlerStripPrefix(false))
assert.NoError(t, err)
assert.True(t, HasVSIHandler("prefix://"))

// nil handler
err = RegisterVSIHandler("nil_prefix://", nil)
assert.NoError(t, err)
assert.False(t, HasVSIHandler("nil_prefix://"))

// unregistered_prefix
assert.False(t, HasVSIHandler("unregistered_prefix://"))
}

func TestVSIPrefix(t *testing.T) {
tifdat, _ := ioutil.ReadFile("testdata/test.tif")

assert.False(t, HasVSIHandler("prefix://"))
// stripPrefix false
vpa := vpHandler{datas: make(map[string]KeySizerReaderAt)}
vpa.datas["prefix://test.tif"] = mbufHandler{tifdat}
err := RegisterVSIHandler("prefix://", vpa, VSIHandlerStripPrefix(false))
assert.NoError(t, err)
assert.True(t, HasVSIHandler("prefix://"))

ds, err := Open("prefix://test.tif")
if err != nil {
Expand Down

0 comments on commit d257757

Please sign in to comment.