github.com/go-kivik/kivik/v4@v4.3.2/int/mock/changes.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 mock 14 15 import ( 16 "io" 17 18 "github.com/go-kivik/kivik/v4/driver" 19 ) 20 21 // Changes mocks driver.Changes 22 type Changes struct { 23 NextFunc func(*driver.Change) error 24 CloseFunc func() error 25 LastSeqFunc func() string 26 PendingFunc func() int64 27 ETagFunc func() string 28 } 29 30 var _ driver.Changes = &Changes{} 31 32 // Next calls c.NextFunc 33 func (c *Changes) Next(change *driver.Change) error { 34 if c.NextFunc == nil { 35 return io.EOF 36 } 37 return c.NextFunc(change) 38 } 39 40 // Close calls c.CloseFunc 41 func (c *Changes) Close() error { 42 if c.CloseFunc == nil { 43 return nil 44 } 45 return c.CloseFunc() 46 } 47 48 // LastSeq calls c.LastSeqFunc 49 func (c *Changes) LastSeq() string { 50 if c.LastSeqFunc != nil { 51 return c.LastSeqFunc() 52 } 53 return "" 54 } 55 56 // Pending calls c.PendingFunc 57 func (c *Changes) Pending() int64 { 58 if c.PendingFunc != nil { 59 return c.PendingFunc() 60 } 61 return 0 62 } 63 64 // ETag calls c.ETagFunc 65 func (c *Changes) ETag() string { 66 return c.ETagFunc() 67 }