github.com/go-kivik/kivik/v4@v4.3.2/kiviktest/client/alldbsstats.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 14 15 import ( 16 "context" 17 18 "github.com/google/go-cmp/cmp" 19 20 kivik "github.com/go-kivik/kivik/v4" 21 "github.com/go-kivik/kivik/v4/kiviktest/kt" 22 ) 23 24 func init() { 25 kt.Register("AllDBsStats", allDBsStats) 26 } 27 28 func allDBsStats(ctx *kt.Context) { 29 ctx.RunAdmin(func(ctx *kt.Context) { 30 testAllDBsStats(ctx, ctx.Admin) 31 }) 32 ctx.RunNoAuth(func(ctx *kt.Context) { 33 testAllDBsStats(ctx, ctx.NoAuth) 34 }) 35 } 36 37 func testAllDBsStats(ctx *kt.Context, client *kivik.Client) { 38 stats, err := client.AllDBsStats(context.Background()) 39 if !ctx.IsExpectedSuccess(err) { 40 return 41 } 42 if wantStats, ok := ctx.Interface("expected").([]*kivik.DBStats); ok { 43 if d := cmp.Diff(wantStats, stats); d != "" { 44 ctx.Errorf("Unexpected database stats: %s", d) 45 } 46 } else { 47 const wantResults = 3 48 if len(stats) != wantResults { 49 ctx.Errorf("Expected 2 database stats, got %d", len(stats)) 50 } 51 } 52 }