github.com/go-kivik/kivik/v4@v4.3.2/kiviktest/client/alldbs.go (about) 1 // Licensed under the Apache License, Version 2.0 (the "License"); you may not 2 // use this file except in compliance with the License. You may obtain a copy of 3 // the License at 4 // 5 // http://www.apache.org/licenses/LICENSE-2.0 6 // 7 // Unless required by applicable law or agreed to in writing, software 8 // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 9 // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 10 // License for the specific language governing permissions and limitations under 11 // the License. 12 13 // Package client provides integration tests for the kivik client. 14 package client 15 16 import ( 17 "context" 18 "sort" 19 20 "gitlab.com/flimzy/testy" 21 22 kivik "github.com/go-kivik/kivik/v4" 23 "github.com/go-kivik/kivik/v4/kiviktest/kt" 24 ) 25 26 func init() { 27 kt.Register("AllDBs", allDBs) 28 } 29 30 func allDBs(ctx *kt.Context) { 31 ctx.RunAdmin(func(ctx *kt.Context) { 32 testAllDBs(ctx, ctx.Admin, ctx.StringSlice("expected")) 33 }) 34 ctx.RunNoAuth(func(ctx *kt.Context) { 35 testAllDBs(ctx, ctx.NoAuth, ctx.StringSlice("expected")) 36 }) 37 if ctx.RW && ctx.Admin != nil { 38 ctx.Run("RW", func(ctx *kt.Context) { 39 testAllDBsRW(ctx) 40 }) 41 } 42 } 43 44 func testAllDBsRW(ctx *kt.Context) { 45 dbName := ctx.TestDB() 46 expected := append(ctx.StringSlice("expected"), dbName) 47 ctx.Run("group", func(ctx *kt.Context) { 48 ctx.RunAdmin(func(ctx *kt.Context) { 49 testAllDBs(ctx, ctx.Admin, expected) 50 }) 51 ctx.RunNoAuth(func(ctx *kt.Context) { 52 testAllDBs(ctx, ctx.NoAuth, expected) 53 }) 54 }) 55 } 56 57 func testAllDBs(ctx *kt.Context, client *kivik.Client, expected []string) { 58 ctx.Parallel() 59 allDBs, err := client.AllDBs(context.Background()) 60 if !ctx.IsExpectedSuccess(err) { 61 return 62 } 63 sort.Strings(expected) 64 sort.Strings(allDBs) 65 if d := testy.DiffTextSlices(expected, allDBs); d != nil { 66 ctx.Errorf("AllDBs() returned unexpected list:\n%s\n", d) 67 } 68 }