...
1
2
3
4
5
6
7
8
9
10
11
12
13 package fs
14
15 import (
16 "context"
17 "net/http"
18 "testing"
19
20 "github.com/google/go-cmp/cmp"
21 "gitlab.com/flimzy/testy"
22
23 "github.com/go-kivik/kivik/v4"
24 "github.com/go-kivik/kivik/v4/driver"
25 "github.com/go-kivik/kivik/v4/x/fsdb/filesystem"
26 )
27
28 func Test_db_Stats(t *testing.T) {
29 tests := []struct {
30 name string
31 path, dbname string
32 wantStatus int
33 wantErr string
34 want *driver.DBStats
35 }{
36 {
37 name: "success",
38 path: "testdata",
39 dbname: "db_att",
40 want: &driver.DBStats{
41 Name: "db_att",
42 },
43 },
44 {
45 name: "not found",
46 path: "testdata",
47 dbname: "notfound",
48 wantStatus: http.StatusNotFound,
49 wantErr: `[Nn]o such file or directory`,
50 },
51 }
52
53 for _, tt := range tests {
54 t.Run(tt.name, func(t *testing.T) {
55 c := &client{root: tt.path, fs: filesystem.Default()}
56 db, err := c.newDB(tt.dbname)
57 if err != nil {
58 t.Fatal(err)
59 }
60
61 stats, err := db.Stats(context.Background())
62 if !testy.ErrorMatchesRE(tt.wantErr, err) {
63 t.Errorf("error = %v, wantErr %v", err, tt.wantErr)
64 return
65 }
66 if status := kivik.HTTPStatus(err); status != tt.wantStatus {
67 t.Errorf("status = %v, wantStatus %v", status, tt.wantStatus)
68 }
69 if d := cmp.Diff(tt.want, stats); d != "" {
70 t.Errorf("Unexpected stats:\n%s\n", d)
71 }
72 })
73 }
74 }
75
View as plain text