-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfsgraph_test.go
61 lines (54 loc) · 1.57 KB
/
fsgraph_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
52
53
54
55
56
57
58
59
60
61
package fsgraph
import (
"io/ioutil"
"net/http/httptest"
"os"
"testing"
"github.com/99designs/gqlgen/client"
"github.com/99designs/gqlgen/handler"
"github.com/spf13/afero"
"github.com/stretchr/testify/require"
)
func TestFSGraph(t *testing.T) {
//rootfs := afero.NewMemMapFs()
tempdir, err := ioutil.TempDir("", "fsgraph-test")
if err != nil {
t.Error(err)
return
}
defer os.RemoveAll(tempdir)
rootfs := afero.NewBasePathFs(afero.NewOsFs(), tempdir)
// setup some files, dirs and data:
file1path := "/file1"
file1content := []byte(`File one.`)
afero.WriteFile(rootfs, file1path, file1content, 0666)
file2path := "/file2"
file2content := []byte(`File two.`)
afero.WriteFile(rootfs, file2path, file2content, 0666)
rootfs.MkdirAll("a/b/c", 0777)
file3path := "/a/b/c/file3"
file3content := []byte(`File three.`)
afero.WriteFile(rootfs, file3path, file3content, 0666)
srv := httptest.NewServer(handler.GraphQL(NewExecutableSchema(Config{
Resolvers: &Resolver{
RootFS: FS{Fs: rootfs},
},
})))
c := client.New(srv.URL)
var resp struct {
Root struct {
Path string `json:"path"`
Children []struct {
Path string `json:"path"`
Mode struct {
Type string `json:"type"`
} `json:"mode"`
} `json:"children"`
} `json:"root"`
}
c.MustPost(`query { root { path, children { path, mode{type} } } }`, &resp)
//t.Log(spew.Sdump(resp))
require.Equal(t, "/", resp.Root.Path, "root path")
// NOTE: afero.NewMemMapFs() is showing "/a" twice, both as a regular file...
require.Equal(t, 3, len(resp.Root.Children), "length of root's children")
}