...
1 package mapfs_test
2
3 import (
4 "io/fs"
5 "testing"
6
7 "oss.terrastruct.com/util-go/assert"
8 "oss.terrastruct.com/util-go/mapfs"
9 )
10
11 func TestMapFS(t *testing.T) {
12 t.Parallel()
13
14 m := map[string]string{
15 "index": "<Espy_on_crack> I installed 'Linux 6.1', doesn't that make me a unix",
16 "d2/imports": "Do your part to help preserve life on Earth -- by trying to preserve your own.",
17 "d2/globs": "I'm going to raise an issue and stick it in your ear.",
18 "nested/nested/nested/nested": "Yuppie Wannabes",
19 }
20
21 mapfs, err := mapfs.New(m)
22 assert.Success(t, err)
23 t.Cleanup(func() {
24 err := mapfs.Close()
25 assert.Success(t, err)
26 })
27
28 for p, s := range m {
29 b, err := fs.ReadFile(mapfs, p)
30 assert.Success(t, err)
31 assert.Equal(t, s, string(b))
32 }
33
34 _, err = fs.ReadFile(mapfs, "../escape")
35 assert.ErrorString(t, err, "stat ../escape: invalid argument")
36 _, err = fs.ReadFile(mapfs, "/root")
37 assert.ErrorString(t, err, "stat /root: invalid argument")
38 }
39
View as plain text