...
1
2
3
4
5
6
7
8
9
10
11
12
13 package client
14
15 import (
16 "context"
17
18 kivik "github.com/go-kivik/kivik/v4"
19 "github.com/go-kivik/kivik/v4/kiviktest/kt"
20 )
21
22 func init() {
23 kt.Register("DBExists", dbExists)
24 }
25
26 func dbExists(ctx *kt.Context) {
27 ctx.RunAdmin(func(ctx *kt.Context) {
28 for _, dbName := range ctx.MustStringSlice("databases") {
29 checkDBExists(ctx, ctx.Admin, dbName)
30 }
31 })
32 ctx.RunNoAuth(func(ctx *kt.Context) {
33 for _, dbName := range ctx.MustStringSlice("databases") {
34 checkDBExists(ctx, ctx.NoAuth, dbName)
35 }
36 })
37 ctx.RunRW(func(ctx *kt.Context) {
38 dbName := ctx.TestDB()
39 ctx.Run("group", func(ctx *kt.Context) {
40 ctx.RunAdmin(func(ctx *kt.Context) {
41 checkDBExists(ctx, ctx.Admin, dbName)
42 })
43 ctx.RunNoAuth(func(ctx *kt.Context) {
44 checkDBExists(ctx, ctx.NoAuth, dbName)
45 })
46 })
47 })
48 }
49
50 func checkDBExists(ctx *kt.Context, client *kivik.Client, dbName string) {
51 ctx.Run(dbName, func(ctx *kt.Context) {
52 ctx.Parallel()
53 exists, err := client.DBExists(context.Background(), dbName)
54 if !ctx.IsExpectedSuccess(err) {
55 return
56 }
57 if ctx.MustBool("exists") != exists {
58 ctx.Errorf("Expected: %t, actual: %t", ctx.Bool("exists"), exists)
59 }
60 })
61 }
62
View as plain text