Re-apply one of the conflicting changes to make sure that PutExistingRevWithBody() treats it as a no-op (SG Issue #3048)
(t *testing.T)
| 1988 | |
| 1989 | // Re-apply one of the conflicting changes to make sure that PutExistingRevWithBody() treats it as a no-op (SG Issue #3048) |
| 1990 | func TestRepeatedConflict(t *testing.T) { |
| 1991 | |
| 1992 | db, ctx := setupTestDBAllowConflicts(t) |
| 1993 | defer db.Close(ctx) |
| 1994 | collection, ctx := GetSingleDatabaseCollectionWithUser(ctx, t, db) |
| 1995 | |
| 1996 | // Create rev 1 of "doc": |
| 1997 | body := Body{"n": 1, "channels": []string{"all", "1"}} |
| 1998 | _, _, err := collection.PutExistingRevWithBody(ctx, "doc", body, []string{"1-a"}, false, ExistingVersionWithUpdateToHLV) |
| 1999 | assert.NoError(t, err, "add 1-a") |
| 2000 | |
| 2001 | // Create two conflicting changes: |
| 2002 | body["n"] = 2 |
| 2003 | body["channels"] = []string{"all", "2b"} |
| 2004 | _, _, err = collection.PutExistingRevWithBody(ctx, "doc", body, []string{"2-b", "1-a"}, false, ExistingVersionWithUpdateToHLV) |
| 2005 | assert.NoError(t, err, "add 2-b") |
| 2006 | |
| 2007 | body["n"] = 3 |
| 2008 | body["channels"] = []string{"all", "2a"} |
| 2009 | _, newRev, err := collection.PutExistingRevWithBody(ctx, "doc", body, []string{"2-a", "1-a"}, false, ExistingVersionWithUpdateToHLV) |
| 2010 | assert.NoError(t, err, "add 2-a") |
| 2011 | |
| 2012 | // Get the _rev that was set in the body by PutExistingRevWithBody() and make assertions on it |
| 2013 | revGen, _ := ParseRevID(ctx, newRev) |
| 2014 | assert.Equal(t, 2, revGen) |
| 2015 | |
| 2016 | // Remove the _rev key from the body, and call PutExistingRevWithBody() again, which should re-add it |
| 2017 | delete(body, BodyRev) |
| 2018 | _, newRev, err = collection.PutExistingRevWithBody(ctx, "doc", body, []string{"2-a", "1-a"}, false, ExistingVersionWithUpdateToHLV) |
| 2019 | assert.NoError(t, err) |
| 2020 | |
| 2021 | // The _rev should pass the same assertions as before, since PutExistingRevWithBody() should re-add it |
| 2022 | revGen, _ = ParseRevID(ctx, newRev) |
| 2023 | assert.Equal(t, 2, revGen) |
| 2024 | |
| 2025 | } |
| 2026 | |
| 2027 | func TestConflicts(t *testing.T) { |
| 2028 |
nothing calls this directly
no test coverage detected