This repository has been archived by the owner on Sep 15, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 143
/
entry_del_test.go
61 lines (50 loc) · 2.04 KB
/
entry_del_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
package holochain
import (
"fmt"
"testing"
. "github.com/holochain/holochain-proto/hash"
. "github.com/smartystreets/goconvey/convey"
)
func TestDelEntrySysValidate(t *testing.T) {
d, _, h := PrepareTestChain("test")
defer CleanupTestChain(h, d)
Convey("validate del entry should fail if it doesn't match the del entry schema", t, func() {
err := sysValidateEntry(h, DelEntryDef, &GobEntry{C: ""}, nil)
So(err, ShouldNotBeNil)
So(err.Error(), ShouldEqual, "unexpected end of JSON input")
err = sysValidateEntry(h, DelEntryDef, &GobEntry{C: `{"Fish":2}`}, nil)
So(err, ShouldNotBeNil)
So(err.Error(), ShouldEqual, "Validation Failed: validator %del failed: object property 'Hash' is required")
err = sysValidateEntry(h, DelEntryDef, &GobEntry{C: `{"Hash": "not-a-hash"}`}, nil)
So(err, ShouldNotBeNil)
So(err.Error(), ShouldEqual, "Validation Failed: Error (input isn't valid multihash) when decoding Hash value 'not-a-hash'")
err = sysValidateEntry(h, DelEntryDef, &GobEntry{C: `{"Hash": 1}`}, nil)
So(err, ShouldNotBeNil)
So(err.Error(), ShouldEqual, "Validation Failed: validator %del failed: object property 'Hash' validation failed: value is not a string (Kind: float64)")
})
Convey("validate del entry should succeed on valid entry", t, func() {
err := sysValidateEntry(h, DelEntryDef, &GobEntry{C: `{"Hash": "QmUfY4WeqD3UUfczjdkoFQGEgCAVNf7rgFfjdeTbr7JF1C","Message": "obsolete"}`}, nil)
So(err, ShouldBeNil)
})
}
func TestDelEntryToJSON(t *testing.T) {
hashStr := "QmVGtdTZdTFaLsaj2RwdVG8jcjNNcp1DE914DKZ2kHmXHx"
hash, _ := NewHash(hashStr)
e1 := DelEntry{
Hash: hash,
Message: "my message",
}
var j string
var err error
Convey("it should convert to JSON", t, func() {
j, err = e1.ToJSON()
So(err, ShouldBeNil)
So(j, ShouldEqual, fmt.Sprintf(`{"Hash":"%s","Message":"my message"}`, hashStr))
})
Convey("it should convert from JSON", t, func() {
e2, err := DelEntryFromJSON(j)
So(err, ShouldBeNil)
So(e2.Message, ShouldEqual, e1.Message)
So(e2.Hash.String(), ShouldEqual, e1.Hash.String())
})
}