...

Source file src/github.com/go-kivik/kivik/v4/kiviktest/client/version.go

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

     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  	"regexp"
    18  
    19  	kivik "github.com/go-kivik/kivik/v4"
    20  	"github.com/go-kivik/kivik/v4/kiviktest/kt"
    21  )
    22  
    23  func init() {
    24  	kt.Register("Version", version)
    25  }
    26  
    27  func version(ctx *kt.Context) {
    28  	ctx.RunAdmin(func(ctx *kt.Context) {
    29  		testServerInfo(ctx, ctx.Admin)
    30  	})
    31  	ctx.RunNoAuth(func(ctx *kt.Context) {
    32  		testServerInfo(ctx, ctx.NoAuth)
    33  	})
    34  }
    35  
    36  func testServerInfo(ctx *kt.Context, client *kivik.Client) {
    37  	ctx.Parallel()
    38  	info, err := client.Version(context.Background())
    39  	if !ctx.IsExpectedSuccess(err) {
    40  		return
    41  	}
    42  	version := regexp.MustCompile(ctx.MustString("version"))
    43  	vendor := regexp.MustCompile(ctx.MustString("vendor"))
    44  	if !version.MatchString(info.Version) {
    45  		ctx.Errorf("Version '%s' does not match /%s/", info.Version, version)
    46  	}
    47  	if !vendor.MatchString(info.Vendor) {
    48  		ctx.Errorf("Vendor '%s' does not match /%s/", info.Vendor, vendor)
    49  	}
    50  }
    51  

View as plain text