github.com/go-kivik/kivik/v4@v4.3.2/x/fsdb/cdb/attachments_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 cdb 14 15 import ( 16 "net/http" 17 "testing" 18 19 "gitlab.com/flimzy/testy" 20 21 internal "github.com/go-kivik/kivik/v4/int/errors" 22 "github.com/go-kivik/kivik/v4/x/fsdb/filesystem" 23 ) 24 25 func TestAttachmentsIterator(t *testing.T) { 26 type tt struct { 27 r *Revision 28 status int 29 err string 30 } 31 tests := testy.NewTable() 32 tests.Add("missing attachment", tt{ 33 r: &Revision{ 34 options: map[string]interface{}{ 35 "attachments": true, 36 }, 37 RevMeta: RevMeta{ 38 Attachments: map[string]*Attachment{ 39 "notfound.txt": { 40 fs: filesystem.Default(), 41 path: "/somewhere/notfound.txt", 42 }, 43 }, 44 }, 45 }, 46 status: http.StatusInternalServerError, 47 err: "open /somewhere/notfound.txt: [Nn]o such file or directory", 48 }) 49 tests.Run(t, func(t *testing.T, tt tt) { 50 _, err := tt.r.AttachmentsIterator() 51 if d := internal.StatusErrorDiffRE(tt.err, tt.status, err); d != "" { 52 t.Error(d) 53 } 54 }) 55 }