-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
file_test.go
51 lines (39 loc) · 1.05 KB
/
file_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package glfw
import (
"io/ioutil"
"os"
"path/filepath"
"testing"
"github.com/stretchr/testify/assert"
"fyne.io/fyne"
"fyne.io/fyne/storage"
)
func TestGLDriver_FileReaderForURI(t *testing.T) {
uri, _ := testURI("text.txt")
read, err := NewGLDriver().FileReaderForURI(uri)
defer read.Close()
assert.Nil(t, err)
assert.Equal(t, uri, read.URI())
data, err := ioutil.ReadAll(read)
assert.Nil(t, err)
assert.Equal(t, "content", string(data))
}
func TestGLDriver_FileReaderForURI_Again(t *testing.T) { // a bug blanked files
TestGLDriver_FileReaderForURI(t)
}
func TestGLDriver_FileWriterForURI(t *testing.T) {
uri, path := testURI("text2.txt")
defer os.Remove(path)
write, err := NewGLDriver().FileWriterForURI(uri)
defer write.Close()
assert.Nil(t, err)
assert.Equal(t, uri, write.URI())
count, err := write.Write([]byte("another"))
assert.Equal(t, 7, count)
assert.Nil(t, err)
}
func testURI(file string) (fyne.URI, string) {
path, _ := filepath.Abs(filepath.Join("testdata", file))
uri := storage.NewURI("file://" + path)
return uri, path
}