Skip to content

Commit

Permalink
remove copied code from testfile
Browse files Browse the repository at this point in the history
Because the test file driver only had ListerForURI() so it would satisfy
the driver interface, but this code was not actually used, it has been
removed and replaced with a stub that returns an error message, similar
to the mobile driver.
  • Loading branch information
charlesdaniels committed Aug 26, 2020
1 parent b321da9 commit 72df8e3
Showing 1 changed file with 1 addition and 47 deletions.
48 changes: 1 addition & 47 deletions test/testfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package test
import (
"fmt"
"io"
"io/ioutil"
"os"
"path/filepath"

Expand Down Expand Up @@ -57,51 +56,6 @@ func (d *testDriver) FileWriterForURI(uri fyne.URI) (fyne.URIWriteCloser, error)
return openFile(uri, true)
}

// lazily copied over from the glfw driver, should be good enough for testing
// purposes

type directory struct {
fyne.URI
}

// Declare conformity to the ListableURI interface
var _ fyne.ListableURI = (*directory)(nil)

func (d *directory) List() ([]fyne.URI, error) {
if d.Scheme() != "file" {
return nil, fmt.Errorf("unsupported URL protocol")
}

path := d.String()[len(d.Scheme())+3 : len(d.String())]
files, err := ioutil.ReadDir(path)
if err != nil {
return nil, err
}

urilist := []fyne.URI{}

for _, f := range files {
uri := storage.NewURI("file://" + filepath.Join(path, f.Name()))
urilist = append(urilist, uri)
}

return urilist, nil
}

func (d *testDriver) ListerForURI(uri fyne.URI) (fyne.ListableURI, error) {
if uri.Scheme() != "file" {
return nil, fmt.Errorf("unsupported URL protocol")
}

path := uri.String()[len(uri.Scheme())+3 : len(uri.String())]
s, err := os.Stat(path)
if err != nil {
return nil, err
}

if !s.IsDir() {
return nil, fmt.Errorf("Path '%s' is not a directory, cannot convert to listable URI", path)
}

return &directory{URI: uri}, nil
return nil, fmt.Errorf("test driver does support creating listable URIs yet")
}

0 comments on commit 72df8e3

Please sign in to comment.