...
1
2
3
4
5
6
7
8
9
10
11
12
13 package fs
14
15 import (
16 "context"
17 "testing"
18
19 "gitlab.com/flimzy/testy"
20
21 internal "github.com/go-kivik/kivik/v4/int/errors"
22 "github.com/go-kivik/kivik/v4/x/fsdb/filesystem"
23 )
24
25 func TestSecurity(t *testing.T) {
26 type tt struct {
27 fs filesystem.Filesystem
28 path, dbname string
29 status int
30 err string
31 }
32 tests := testy.NewTable()
33 tests.Add("no security object", tt{
34 dbname: "foo",
35 })
36 tests.Add("json security obj", tt{
37 path: "testdata",
38 dbname: "db_foo",
39 })
40 tests.Add("yaml security obj", tt{
41 path: "testdata",
42 dbname: "db_bar",
43 })
44
45 tests.Run(t, func(t *testing.T, tt tt) {
46 dir := tt.path
47 if dir == "" {
48 dir = tempDir(t)
49 t.Cleanup(func() {
50 rmdir(t, dir)
51 })
52 }
53 fs := tt.fs
54 if fs == nil {
55 fs = filesystem.Default()
56 }
57 c := &client{root: dir, fs: fs}
58 db, err := c.newDB(tt.dbname)
59 if err != nil {
60 t.Fatal(err)
61 }
62 sec, err := db.Security(context.Background())
63 if d := internal.StatusErrorDiffRE(tt.err, tt.status, err); d != "" {
64 t.Error(d)
65 }
66 if d := testy.DiffAsJSON(testy.Snapshot(t), sec); d != nil {
67 t.Error(d)
68 }
69 })
70 }
71
View as plain text