This repository has been archived by the owner on Nov 8, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 51
/
private_state_test.go
92 lines (71 loc) · 3.2 KB
/
private_state_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
84
85
86
87
88
89
90
91
92
package state_test
import (
"encoding/json"
"testing"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"github.com/s7techlab/cckit/state"
"github.com/s7techlab/cckit/state/testdata"
"github.com/s7techlab/cckit/state/testdata/schema"
expectcc "github.com/s7techlab/cckit/testing/expect"
)
func TestPrivateState(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecs(t, "Private state suite")
}
// var (
// actors testcc.Identities
// booksCC *testcc.MockStub
// err error
// )
var _ = Describe(`PrivateState`, func() {
// BeforeSuite(func() {
// actors, err = testcc.IdentitiesFromFiles(`SOME_MSP`, map[string]string{
// `owner`: `s7techlab.pem`,
// }, examplecert.Content)
// Expect(err).To(BeNil())
// //Create books chaincode mock - struct based schema
// booksCC = testcc.NewMockStub(`books`, testdata.NewBooksCC())
// booksCC.From(actors[`owner`]).Init()
// })
Describe(`Struct based schema private`, func() {
It("Allow to insert entries", func() {
expectcc.ResponseOk(booksCC.From(Owner).Invoke(`privateBookInsert`, &testdata.PrivateBooks[0]))
expectcc.ResponseOk(booksCC.From(Owner).Invoke(`privateBookInsert`, &testdata.PrivateBooks[1]))
expectcc.ResponseOk(booksCC.From(Owner).Invoke(`privateBookInsert`, &testdata.PrivateBooks[2]))
})
It("Disallow to insert entries with same keys", func() {
expectcc.ResponseError(booksCC.From(Owner).Invoke(`privateBookInsert`, &testdata.PrivateBooks[2]))
})
It("Allow to get entry list", func() {
books := expectcc.PayloadIs(booksCC.Invoke(`privateBookList`), &[]schema.PrivateBook{}).([]schema.PrivateBook)
Expect(len(books)).To(Equal(3))
Expect(books[0]).To(Equal(testdata.PrivateBooks[0]))
Expect(books[1]).To(Equal(testdata.PrivateBooks[1]))
Expect(books[2]).To(Equal(testdata.PrivateBooks[2]))
})
It("Allow to get entry converted to target type", func() {
book1FromCC := expectcc.PayloadIs(booksCC.Invoke(`privateBookGet`, testdata.PrivateBooks[0].Id), &schema.PrivateBook{}).(schema.PrivateBook)
Expect(book1FromCC).To(Equal(testdata.PrivateBooks[0]))
})
It("Allow to get entry json", func() {
book2JsonFromCC := booksCC.Invoke(`privateBookGet`, testdata.PrivateBooks[2].Id).Payload
book2Json, _ := json.Marshal(testdata.PrivateBooks[2])
Expect(book2JsonFromCC).To(Equal(book2Json))
})
It("Allow to upsert entry", func() {
book2Updated := testdata.PrivateBooks[2]
book2Updated.Title = `thirdiest title`
updateRes := expectcc.PayloadIs(booksCC.Invoke(`privateBookUpsert`, &book2Updated), &schema.PrivateBook{}).(schema.PrivateBook)
Expect(updateRes.Title).To(Equal(book2Updated.Title))
book3FromCC := expectcc.PayloadIs(booksCC.Invoke(`privateBookGet`, testdata.PrivateBooks[2].Id), &schema.PrivateBook{}).(schema.PrivateBook)
Expect(book3FromCC).To(Equal(book2Updated))
})
It("Allow to delete entry", func() {
expectcc.ResponseOk(booksCC.From(Owner).Invoke(`privateBookDelete`, testdata.PrivateBooks[0].Id))
books := expectcc.PayloadIs(booksCC.Invoke(`privateBookList`), &[]schema.PrivateBook{}).([]schema.PrivateBook)
Expect(len(books)).To(Equal(2))
expectcc.ResponseError(booksCC.Invoke(`privateBookGet`, testdata.PrivateBooks[0].Id), state.ErrKeyNotFound)
})
})
})