github.com/go-kivik/kivik/v4@v4.3.2/common_test.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 kivik 14 15 import ( 16 "errors" 17 "io" 18 "strings" 19 "testing" 20 "time" 21 ) 22 23 var testOptions = map[string]interface{}{"foo": 123} 24 25 func parseTime(t *testing.T, str string) time.Time { 26 t.Helper() 27 ts, err := time.Parse(time.RFC3339, str) 28 if err != nil { 29 t.Fatal(err) 30 } 31 return ts 32 } 33 34 type errReader string 35 36 var _ io.ReadCloser = errReader("") 37 38 func (r errReader) Close() error { 39 return nil 40 } 41 42 func (r errReader) Read(_ []byte) (int, error) { 43 return 0, errors.New(string(r)) 44 } 45 46 func body(s string) io.ReadCloser { 47 return io.NopCloser(strings.NewReader(s)) 48 } 49 50 type mockIterator struct { 51 NextFunc func(interface{}) error 52 CloseFunc func() error 53 } 54 55 var _ iterator = &mockIterator{} 56 57 func (i *mockIterator) Next(ifce interface{}) error { 58 return i.NextFunc(ifce) 59 } 60 61 func (i *mockIterator) Close() error { 62 return i.CloseFunc() 63 }