...

Source file src/github.com/go-kivik/kivik/v4/x/fsdb/cdb/revision_test.go

Documentation: github.com/go-kivik/kivik/v4/x/fsdb/cdb

     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  	"testing"
    17  
    18  	"gitlab.com/flimzy/testy"
    19  
    20  	internal "github.com/go-kivik/kivik/v4/int/errors"
    21  )
    22  
    23  func TestNewRevision(t *testing.T) {
    24  	type tt struct {
    25  		i      interface{}
    26  		status int
    27  		err    string
    28  	}
    29  	tests := testy.NewTable()
    30  	tests.Add("simple", tt{
    31  		i: map[string]interface{}{
    32  			"_rev":  "1-xxx",
    33  			"value": "foo",
    34  		},
    35  	})
    36  	tests.Add("with attachments", tt{
    37  		i: map[string]interface{}{
    38  			"_rev": "3-asdf",
    39  			"_attachments": map[string]interface{}{
    40  				"foo.txt": map[string]interface{}{
    41  					"content_type": "text/plain",
    42  					"data":         []byte("This is some content"),
    43  				},
    44  			},
    45  		},
    46  	})
    47  
    48  	tests.Run(t, func(t *testing.T, tt tt) {
    49  		fs := &FS{}
    50  		rev, err := fs.NewRevision(tt.i)
    51  		if d := internal.StatusErrorDiff(tt.err, tt.status, err); d != "" {
    52  			t.Error(d)
    53  		}
    54  		rev.options = map[string]interface{}{
    55  			"revs":          true,
    56  			"attachments":   true,
    57  			"header:accept": "application/json",
    58  		}
    59  		if d := testy.DiffAsJSON(testy.Snapshot(t), rev); d != nil {
    60  			t.Error(d)
    61  		}
    62  	})
    63  }
    64  

View as plain text