Skip to content

Commit

Permalink
Merge pull request #396 from go-kivik/rd3
Browse files Browse the repository at this point in the history
More updates to RevsDiff() method
  • Loading branch information
flimzy committed Jun 24, 2019
2 parents 015bb12 + 8060b9f commit 17e1958
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 12 deletions.
9 changes: 3 additions & 6 deletions db.go
Expand Up @@ -645,10 +645,6 @@ func (db *DB) Close(ctx context.Context) error {
return nil
}

// RevLookup represents a rev lookup request, as sent to RevsDiff. The map
// key is the document id, and the value is a slice of revisions.
type RevLookup map[string][]string

// RevDiff represents a rev diff for a single document, as returned by the
// RevsDiff method.
type RevDiff struct {
Expand All @@ -662,10 +658,11 @@ type Diffs map[string]RevDiff

// RevsDiff the subset of document/revision IDs that do not correspond to
// revisions stored in the database. This is used by the replication protocol,
// and is normally never needed otherwise.
// and is normally never needed otherwise. revMap must marshal to the expected
// format.
//
// See http://docs.couchdb.org/en/stable/api/database/misc.html#db-revs-diff
func (db *DB) RevsDiff(ctx context.Context, revMap RevLookup) (Diffs, error) {
func (db *DB) RevsDiff(ctx context.Context, revMap interface{}) (Diffs, error) {
if rd, ok := db.driverDB.(driver.RevsDiffer); ok {
result, err := rd.RevsDiff(ctx, revMap)
if err != nil {
Expand Down
6 changes: 3 additions & 3 deletions db_test.go
Expand Up @@ -1965,7 +1965,7 @@ func TestClientClose(t *testing.T) {
func TestRevsDiff(t *testing.T) {
type tt struct {
db *DB
revMap RevLookup
revMap interface{}
status int
err string
}
Expand All @@ -1977,7 +1977,7 @@ func TestRevsDiff(t *testing.T) {
})
tests.Add("network error", tt{
db: &DB{driverDB: &mock.RevsDiffer{
RevsDiffFunc: func(_ context.Context, revMap map[string][]string) (map[string]driver.RevDiff, error) {
RevsDiffFunc: func(_ context.Context, revMap interface{}) (map[string]driver.RevDiff, error) {
return nil, errors.New("net error")
},
}},
Expand All @@ -1986,7 +1986,7 @@ func TestRevsDiff(t *testing.T) {
})
tests.Add("success", tt{
db: &DB{driverDB: &mock.RevsDiffer{
RevsDiffFunc: func(_ context.Context, revMap map[string][]string) (map[string]driver.RevDiff, error) {
RevsDiffFunc: func(_ context.Context, revMap interface{}) (map[string]driver.RevDiff, error) {
return map[string]driver.RevDiff{
"foo": {Missing: []string{"1", "2"}},
"bar": {PossibleAncestors: []string{"3", "4"}},
Expand Down
2 changes: 1 addition & 1 deletion driver/driver.go
Expand Up @@ -403,5 +403,5 @@ type RevDiff struct {

// RevsDiffer is an optional interface that may be implemented by a DB.
type RevsDiffer interface {
RevsDiff(ctx context.Context, revMap map[string][]string) (map[string]RevDiff, error)
RevsDiff(ctx context.Context, revMap interface{}) (map[string]RevDiff, error)
}
4 changes: 2 additions & 2 deletions mock/db.go
Expand Up @@ -267,12 +267,12 @@ func (db *DBCloser) Close(ctx context.Context) error {
// RevsDiffer mocks a driver.DB and driver.RevsDiffer.
type RevsDiffer struct {
*BulkDocer
RevsDiffFunc func(context.Context, map[string][]string) (map[string]driver.RevDiff, error)
RevsDiffFunc func(context.Context, interface{}) (map[string]driver.RevDiff, error)
}

var _ driver.RevsDiffer = &RevsDiffer{}

// RevsDiff calls db.RevsDiffFunc
func (db *RevsDiffer) RevsDiff(ctx context.Context, revMap map[string][]string) (map[string]driver.RevDiff, error) {
func (db *RevsDiffer) RevsDiff(ctx context.Context, revMap interface{}) (map[string]driver.RevDiff, error) {
return db.RevsDiffFunc(ctx, revMap)
}

0 comments on commit 17e1958

Please sign in to comment.