...

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

Documentation: github.com/go-kivik/kivik/v4/mockdb

     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 mockdb
    14  
    15  import (
    16  	"context"
    17  	"errors"
    18  	"time"
    19  
    20  	"github.com/go-kivik/kivik/v4/driver"
    21  )
    22  
    23  type driverClient struct {
    24  	*Client
    25  }
    26  
    27  var (
    28  	_ driver.Client        = &driverClient{}
    29  	_ driver.ClientCloser  = &driverClient{}
    30  	_ driver.Cluster       = &driverClient{}
    31  	_ driver.DBsStatser    = &driverClient{}
    32  	_ driver.Pinger        = &driverClient{}
    33  	_ driver.Sessioner     = &driverClient{}
    34  	_ driver.Configer      = &driverClient{}
    35  	_ driver.AllDBsStatser = &driverClient{}
    36  )
    37  
    38  func (c *driverClient) CreateDB(ctx context.Context, name string, options driver.Options) error {
    39  	expected := &ExpectedCreateDB{
    40  		arg0: name,
    41  		commonExpectation: commonExpectation{
    42  			options: options,
    43  		},
    44  	}
    45  	if err := c.nextExpectation(expected); err != nil {
    46  		return err
    47  	}
    48  	if expected.callback != nil {
    49  		return expected.callback(ctx, name, options)
    50  	}
    51  	return expected.wait(ctx)
    52  }
    53  
    54  type driverReplication struct {
    55  	*Replication
    56  }
    57  
    58  var _ driver.Replication = &driverReplication{}
    59  
    60  func (r *driverReplication) ReplicationID() string {
    61  	return r.Replication.id
    62  }
    63  
    64  func (r *driverReplication) Source() string {
    65  	return r.Replication.source
    66  }
    67  
    68  func (r *driverReplication) Target() string {
    69  	return r.Replication.target
    70  }
    71  
    72  func (r *driverReplication) StartTime() time.Time {
    73  	return r.Replication.startTime
    74  }
    75  
    76  func (r *driverReplication) EndTime() time.Time {
    77  	return r.Replication.endTime
    78  }
    79  
    80  func (r *driverReplication) State() string {
    81  	return r.Replication.state
    82  }
    83  
    84  func (r *driverReplication) Err() error {
    85  	return r.Replication.err
    86  }
    87  
    88  func (r *driverReplication) Delete(context.Context) error {
    89  	return errors.New("not implemented")
    90  }
    91  
    92  func (r *driverReplication) Update(context.Context, *driver.ReplicationInfo) error {
    93  	return errors.New("not implemented")
    94  }
    95  
    96  func driverReplications(in []*Replication) []driver.Replication {
    97  	out := make([]driver.Replication, len(in))
    98  	for i, r := range in {
    99  		out[i] = &driverReplication{r}
   100  	}
   101  	return out
   102  }
   103  

View as plain text