...

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

Documentation: github.com/go-kivik/kivik/v4/int/mock

     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 mock
    14  
    15  import (
    16  	"context"
    17  
    18  	"github.com/go-kivik/kivik/v4/driver"
    19  )
    20  
    21  // Client mocks driver.Client
    22  type Client struct {
    23  	// ID identifies a specific Client instance
    24  	ID            string
    25  	AllDBsFunc    func(context.Context, driver.Options) ([]string, error)
    26  	CreateDBFunc  func(context.Context, string, driver.Options) error
    27  	DBFunc        func(string, driver.Options) (driver.DB, error)
    28  	DBExistsFunc  func(context.Context, string, driver.Options) (bool, error)
    29  	DestroyDBFunc func(context.Context, string, driver.Options) error
    30  	VersionFunc   func(context.Context) (*driver.Version, error)
    31  }
    32  
    33  var _ driver.Client = &Client{}
    34  
    35  // AllDBs calls c.AllDBsFunc
    36  func (c *Client) AllDBs(ctx context.Context, opts driver.Options) ([]string, error) {
    37  	return c.AllDBsFunc(ctx, opts)
    38  }
    39  
    40  // CreateDB calls c.CreateDBFunc
    41  func (c *Client) CreateDB(ctx context.Context, dbname string, opts driver.Options) error {
    42  	return c.CreateDBFunc(ctx, dbname, opts)
    43  }
    44  
    45  // DB calls c.DBFunc
    46  func (c *Client) DB(dbname string, opts driver.Options) (driver.DB, error) {
    47  	return c.DBFunc(dbname, opts)
    48  }
    49  
    50  // DBExists calls c.DBExistsFunc
    51  func (c *Client) DBExists(ctx context.Context, dbname string, opts driver.Options) (bool, error) {
    52  	return c.DBExistsFunc(ctx, dbname, opts)
    53  }
    54  
    55  // DestroyDB calls c.DestroyDBFunc
    56  func (c *Client) DestroyDB(ctx context.Context, dbname string, opts driver.Options) error {
    57  	return c.DestroyDBFunc(ctx, dbname, opts)
    58  }
    59  
    60  // Version calls c.VersionFunc
    61  func (c *Client) Version(ctx context.Context) (*driver.Version, error) {
    62  	return c.VersionFunc(ctx)
    63  }
    64  
    65  // ClientReplicator mocks driver.Client and driver.ClientReplicator
    66  type ClientReplicator struct {
    67  	*Client
    68  	GetReplicationsFunc func(context.Context, driver.Options) ([]driver.Replication, error)
    69  	ReplicateFunc       func(context.Context, string, string, driver.Options) (driver.Replication, error)
    70  }
    71  
    72  var _ driver.ClientReplicator = &ClientReplicator{}
    73  
    74  // GetReplications calls c.GetReplicationsFunc
    75  func (c *ClientReplicator) GetReplications(ctx context.Context, opts driver.Options) ([]driver.Replication, error) {
    76  	return c.GetReplicationsFunc(ctx, opts)
    77  }
    78  
    79  // Replicate calls c.ReplicateFunc
    80  func (c *ClientReplicator) Replicate(ctx context.Context, target, source string, opts driver.Options) (driver.Replication, error) {
    81  	return c.ReplicateFunc(ctx, target, source, opts)
    82  }
    83  
    84  // DBUpdater mocks driver.Client and driver.DBUpdater
    85  type DBUpdater struct {
    86  	*Client
    87  	DBUpdatesFunc func(context.Context, driver.Options) (driver.DBUpdates, error)
    88  }
    89  
    90  var _ driver.DBUpdater = &DBUpdater{}
    91  
    92  // DBUpdates calls c.DBUpdatesFunc
    93  func (c *DBUpdater) DBUpdates(ctx context.Context, options driver.Options) (driver.DBUpdates, error) {
    94  	return c.DBUpdatesFunc(ctx, options)
    95  }
    96  
    97  // DBsStatser mocks driver.Client and driver.DBsStatser
    98  type DBsStatser struct {
    99  	*Client
   100  	DBsStatsFunc func(context.Context, []string) ([]*driver.DBStats, error)
   101  }
   102  
   103  var _ driver.DBsStatser = &DBsStatser{}
   104  
   105  // DBsStats calls c.DBsStatsFunc
   106  func (c *DBsStatser) DBsStats(ctx context.Context, dbnames []string) ([]*driver.DBStats, error) {
   107  	return c.DBsStatsFunc(ctx, dbnames)
   108  }
   109  
   110  // Pinger mocks driver.Client and driver.Pinger
   111  type Pinger struct {
   112  	*Client
   113  	PingFunc func(context.Context) (bool, error)
   114  }
   115  
   116  var _ driver.Pinger = &Pinger{}
   117  
   118  // Ping calls c.PingFunc
   119  func (c *Pinger) Ping(ctx context.Context) (bool, error) {
   120  	return c.PingFunc(ctx)
   121  }
   122  
   123  // Cluster mocks driver.Client and driver.Cluster
   124  type Cluster struct {
   125  	*Client
   126  	ClusterStatusFunc func(context.Context, driver.Options) (string, error)
   127  	ClusterSetupFunc  func(context.Context, interface{}) error
   128  	MembershipFunc    func(context.Context) (*driver.ClusterMembership, error)
   129  }
   130  
   131  var _ driver.Cluster = &Cluster{}
   132  
   133  // ClusterStatus calls c.ClusterStatusFunc
   134  func (c *Cluster) ClusterStatus(ctx context.Context, options driver.Options) (string, error) {
   135  	return c.ClusterStatusFunc(ctx, options)
   136  }
   137  
   138  // ClusterSetup calls c.ClusterSetupFunc
   139  func (c *Cluster) ClusterSetup(ctx context.Context, action interface{}) error {
   140  	return c.ClusterSetupFunc(ctx, action)
   141  }
   142  
   143  // Membership calls c.MembershipFunc
   144  func (c *Cluster) Membership(ctx context.Context) (*driver.ClusterMembership, error) {
   145  	return c.MembershipFunc(ctx)
   146  }
   147  
   148  // ClientCloser mocks driver.Client and driver.ClientCloser
   149  type ClientCloser struct {
   150  	*Client
   151  	CloseFunc func() error
   152  }
   153  
   154  var _ driver.ClientCloser = &ClientCloser{}
   155  
   156  // Close calls c.CloseFunc
   157  func (c *ClientCloser) Close() error {
   158  	return c.CloseFunc()
   159  }
   160  
   161  // Configer mocks driver.Client and driver.Configer
   162  type Configer struct {
   163  	*Client
   164  	ConfigFunc          func(context.Context, string) (driver.Config, error)
   165  	ConfigSectionFunc   func(context.Context, string, string) (driver.ConfigSection, error)
   166  	ConfigValueFunc     func(context.Context, string, string, string) (string, error)
   167  	SetConfigValueFunc  func(context.Context, string, string, string, string) (string, error)
   168  	DeleteConfigKeyFunc func(context.Context, string, string, string) (string, error)
   169  }
   170  
   171  var _ driver.Configer = &Configer{}
   172  
   173  // Config calls c.ConfigFunc
   174  func (c *Configer) Config(ctx context.Context, node string) (driver.Config, error) {
   175  	return c.ConfigFunc(ctx, node)
   176  }
   177  
   178  // ConfigSection calls c.ConfSectionFunc
   179  func (c *Configer) ConfigSection(ctx context.Context, node, section string) (driver.ConfigSection, error) {
   180  	return c.ConfigSectionFunc(ctx, node, section)
   181  }
   182  
   183  // ConfigValue calls c.ConfigValueFunc
   184  func (c *Configer) ConfigValue(ctx context.Context, node, section, key string) (string, error) {
   185  	return c.ConfigValueFunc(ctx, node, section, key)
   186  }
   187  
   188  // SetConfigValue calls c.SetConfigValueFunc
   189  func (c *Configer) SetConfigValue(ctx context.Context, node, section, key, value string) (string, error) {
   190  	return c.SetConfigValueFunc(ctx, node, section, key, value)
   191  }
   192  
   193  // DeleteConfigKey calls c.DeleteConfigKeyFunc
   194  func (c *Configer) DeleteConfigKey(ctx context.Context, node, section, key string) (string, error) {
   195  	return c.DeleteConfigKeyFunc(ctx, node, section, key)
   196  }
   197  

View as plain text