...

Source file src/github.com/go-kivik/kivik/v4/kiviktest/db/flush.go

Documentation: github.com/go-kivik/kivik/v4/kiviktest/db

     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 db
    14  
    15  import (
    16  	"context"
    17  
    18  	"github.com/go-kivik/kivik/v4"
    19  	"github.com/go-kivik/kivik/v4/kiviktest/kt"
    20  )
    21  
    22  func init() {
    23  	kt.Register("Flush", flush)
    24  }
    25  
    26  func flush(ctx *kt.Context) {
    27  	ctx.RunAdmin(func(ctx *kt.Context) {
    28  		flushTest(ctx, ctx.Admin)
    29  	})
    30  	ctx.RunNoAuth(func(ctx *kt.Context) {
    31  		flushTest(ctx, ctx.NoAuth)
    32  	})
    33  }
    34  
    35  func flushTest(ctx *kt.Context, client *kivik.Client) {
    36  	ctx.Parallel()
    37  	for _, dbName := range ctx.MustStringSlice("databases") {
    38  		ctx.Run(dbName, func(ctx *kt.Context) {
    39  			db := client.DB(dbName, ctx.Options("db"))
    40  			if err := db.Err(); !ctx.IsExpectedSuccess(err) {
    41  				return
    42  			}
    43  			ctx.Run("DoFlush", func(ctx *kt.Context) {
    44  				err := db.Flush(context.Background())
    45  				if !ctx.IsExpectedSuccess(err) {
    46  					return
    47  				}
    48  			})
    49  		})
    50  	}
    51  }
    52  

View as plain text