github.com/go-kivik/kivik/v4@v4.3.2/kiviktest/client/destroydb.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 kivik "github.com/go-kivik/kivik/v4" 19 "github.com/go-kivik/kivik/v4/kiviktest/kt" 20 ) 21 22 func init() { 23 kt.Register("DestroyDB", destroyDB) 24 } 25 26 func destroyDB(ctx *kt.Context) { 27 // All DestroyDB tests are RW by nature. 28 ctx.RunRW(func(ctx *kt.Context) { 29 ctx.RunAdmin(func(ctx *kt.Context) { 30 ctx.Parallel() 31 testDestroy(ctx, ctx.Admin) 32 }) 33 ctx.RunNoAuth(func(ctx *kt.Context) { 34 ctx.Parallel() 35 testDestroy(ctx, ctx.NoAuth) 36 }) 37 }) 38 } 39 40 func testDestroy(ctx *kt.Context, client *kivik.Client) { 41 ctx.Run("ExistingDB", func(ctx *kt.Context) { 42 ctx.Parallel() 43 dbName := ctx.TestDB() 44 ctx.CheckError(client.DestroyDB(context.Background(), dbName, ctx.Options("db"))) 45 }) 46 ctx.Run("NonExistantDB", func(ctx *kt.Context) { 47 ctx.Parallel() 48 ctx.CheckError(client.DestroyDB(context.Background(), ctx.TestDBName(), ctx.Options("db"))) 49 }) 50 }