-
Notifications
You must be signed in to change notification settings - Fork 0
/
role_test.go
56 lines (46 loc) · 1.51 KB
/
role_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
package main
import (
"encoding/json"
"fmt"
"testing"
"github.com/abbeydabiri/hdlchaincode/models"
"github.com/abbeydabiri/hdlchaincode/utils"
"github.com/google/uuid"
"github.com/hyperledger/fabric-chaincode-go/shim"
"github.com/hyperledger/fabric-chaincode-go/shimtest"
"github.com/stretchr/testify/assert"
)
func TestRoleWR(t *testing.T) {
fmt.Println("Entering TestRoleLogic")
assert := assert.New(t)
// Instantiate mockStub using HDLChaincode as the target chaincode to unit test
stub := shimtest.NewMockStub("TestStub", new(HDLChaincode))
//Verify stub is available
assert.NotNil(stub, "Stub is nil, Test stub creation failed")
uid := uuid.New().String()
writeResp := stub.MockInvoke(uid,
[][]byte{[]byte(utils.RoleW),
[]byte("1"),
[]byte("Test User Category"),
[]byte("Test User Type"),
[]byte("Test Role Name"),
[]byte("Test Role Desc"),
})
assert.EqualValues(shim.OK, writeResp.GetStatus(), writeResp.GetMessage())
testID := "1"
readResp := stub.MockInvoke(uid,
[][]byte{[]byte(utils.RoleR),
[]byte(testID),
})
assert.EqualValues(shim.OK, readResp.GetStatus(), readResp.GetMessage())
var ccResp struct {
Code string `json:"code"`
Role string `json:"message"`
Payload models.Role `json:"payload"`
}
if err := json.Unmarshal(readResp.GetPayload(), &ccResp); err != nil {
panic(err)
}
assert.Equal(testID, ccResp.Payload.RoleID, "Retrieved Role ID mismatch")
assert.Equal(utils.ROLEOO, ccResp.Payload.ObjectType, "Retrieved Object Type mismatch")
}