forked from ravendb/ravendb-go-client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdelete_document_command_test.go
83 lines (73 loc) · 2.1 KB
/
delete_document_command_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
package tests
import (
"testing"
"github.com/ravendb/ravendb-go-client"
"github.com/stretchr/testify/assert"
)
func deleteDocumentCommandTestCanDeleteDocument(t *testing.T, driver *RavenTestDriver) {
var err error
store := driver.getDocumentStoreMust(t)
defer store.Close()
{
session := openSessionMust(t, store)
user := &User{}
user.setName("Marcin")
err = session.StoreWithID(user, "users/1")
assert.NoError(t, err)
err = session.SaveChanges()
assert.NoError(t, err)
session.Close()
}
command := ravendb.NewDeleteDocumentCommand("users/1", nil)
err = store.GetRequestExecutor("").ExecuteCommand(command, nil)
assert.NoError(t, err)
{
session := openSessionMust(t, store)
var loadedUser *User
err = session.Load(&loadedUser, "users/1")
assert.NoError(t, err)
assert.Nil(t, loadedUser)
session.Close()
}
}
func deleteDocumentCommandTestCanDeleteDocumentByEtag(t *testing.T, driver *RavenTestDriver) {
var err error
store := driver.getDocumentStoreMust(t)
defer store.Close()
var changeVector *string
{
session := openSessionMust(t, store)
user := &User{}
user.setName("Marcin")
err = session.StoreWithID(user, "users/1")
assert.NoError(t, err)
err = session.SaveChanges()
assert.NoError(t, err)
changeVector, err = session.Advanced().GetChangeVectorFor(user)
assert.NoError(t, err)
session.Close()
}
{
session := openSessionMust(t, store)
var loadedUser *User
err = session.Load(&loadedUser, "users/1")
assert.NoError(t, err)
assert.NotNil(t, loadedUser)
loadedUser.Age = 5
err = session.SaveChanges()
assert.NoError(t, err)
session.Close()
}
command := ravendb.NewDeleteDocumentCommand("users/1", changeVector)
err = store.GetRequestExecutor("").ExecuteCommand(command, nil)
assert.Error(t, err)
_ = err.(*ravendb.ConcurrencyError)
}
func TestDeleteDocumentCommand(t *testing.T) {
driver := createTestDriver(t)
destroy := func() { destroyDriver(t, driver) }
defer recoverTest(t, destroy)
// follows execution order of java tests
deleteDocumentCommandTestCanDeleteDocument(t, driver)
deleteDocumentCommandTestCanDeleteDocumentByEtag(t, driver)
}