...
1
2
3
4
5
6
7
8
9
10
11
12
13 package kt
14
15 import (
16 "strings"
17 "testing"
18
19 kivik "github.com/go-kivik/kivik/v4"
20 )
21
22
23 var AllDocsIndex = kivik.Index{
24 Name: "_all_docs", Type: "special",
25 Definition: map[string]interface{}{"fields": []map[string]string{{"_id": "asc"}}},
26 }
27
28
29 type SuiteConfig map[string]interface{}
30
31 func name(t *testing.T) string {
32 t.Helper()
33 name := t.Name()
34 return name[strings.Index(name, "/")+1:]
35 }
36
37
38
39 func (c SuiteConfig) get(name, key string) interface{} {
40 var k string
41 if name == "" {
42 k = key
43 } else {
44 k = name + "." + key
45 }
46 v, ok := c[k]
47 if ok {
48 return v
49 }
50 if name == "" {
51 return nil
52 }
53 if !strings.Contains(name, "/") {
54 return c.get("", key)
55 }
56
57 return c.get(name[0:strings.LastIndex(name, "/")], key)
58 }
59
60
61 func (c SuiteConfig) Interface(t *testing.T, key string) interface{} {
62 t.Helper()
63 return c.get(name(t), key)
64 }
65
66
67 func (c SuiteConfig) Bool(t *testing.T, key string) bool {
68 t.Helper()
69 b, _ := c.Interface(t, key).(bool)
70 return b
71 }
72
73
74 func (c SuiteConfig) Skip(t *testing.T) {
75 t.Helper()
76 if c.Bool(t, "skip") {
77 t.Skip("Test skipped by suite configuration")
78 }
79 }
80
81
82 func (c SuiteConfig) StringSlice(t *testing.T, key string) []string {
83 t.Helper()
84 v, _ := c.Interface(t, key).([]string)
85 return v
86 }
87
88
89 func (c SuiteConfig) Int(t *testing.T, key string) int {
90 t.Helper()
91 v, _ := c.Interface(t, key).(int)
92 return v
93 }
94
95
96 func (c SuiteConfig) String(t *testing.T, key string) string {
97 t.Helper()
98 v, _ := c.Interface(t, key).(string)
99 return v
100 }
101
View as plain text