forked from BuxOrg/bux
-
Notifications
You must be signed in to change notification settings - Fork 0
/
model_options_test.go
113 lines (93 loc) · 2.48 KB
/
model_options_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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
package bux
import (
"testing"
"github.com/stretchr/testify/assert"
)
// TestNew will test the method New()
func TestNew(t *testing.T) {
t.Parallel()
t.Run("Get opts", func(t *testing.T) {
opt := New()
assert.IsType(t, *new(ModelOps), opt)
})
t.Run("apply opts", func(t *testing.T) {
opt := New()
m := new(Model)
m.SetOptions(opt)
assert.Equal(t, true, m.IsNew())
})
}
// TestWithMetadata will test the method WithMetadata()
func TestWithMetadata(t *testing.T) {
t.Parallel()
t.Run("Get opts", func(t *testing.T) {
opt := WithMetadata("key", "value")
assert.IsType(t, *new(ModelOps), opt)
})
t.Run("apply opts", func(t *testing.T) {
opt := WithMetadata("key", "value")
m := new(Model)
m.SetOptions(opt)
assert.Equal(t, "value", m.Metadata["key"])
})
}
// TestWithMetadataFromJSON will test the method WithMetadataFromJSON()
func TestWithMetadataFromJSON(t *testing.T) {
t.Parallel()
t.Run("Get opts", func(t *testing.T) {
opt := WithMetadataFromJSON([]byte(`{"key": "value"}`))
assert.IsType(t, *new(ModelOps), opt)
})
t.Run("apply opts", func(t *testing.T) {
opt := WithMetadataFromJSON([]byte(`{"key": "value"}`))
m := new(Model)
m.SetOptions(opt)
assert.Equal(t, "value", m.Metadata["key"])
})
}
// TestWithXPub will test the method WithXPub()
func TestWithXPub(t *testing.T) {
t.Parallel()
t.Run("Get opts", func(t *testing.T) {
opt := WithXPub(testXPub)
assert.IsType(t, *new(ModelOps), opt)
})
t.Run("apply opts", func(t *testing.T) {
opt := WithXPub(testXPub)
m := new(Model)
m.SetOptions(opt)
assert.Equal(t, testXPub, m.rawXpubKey)
})
}
// TestWithEncryptionKey will test the method WithEncryptionKey()
func TestWithEncryptionKey(t *testing.T) {
t.Parallel()
t.Run("Get opts", func(t *testing.T) {
opt := WithEncryptionKey(testEncryption)
assert.IsType(t, *new(ModelOps), opt)
})
t.Run("apply opts", func(t *testing.T) {
opt := WithEncryptionKey(testEncryption)
m := new(Model)
m.SetOptions(opt)
assert.Equal(t, testEncryption, m.encryptionKey)
})
}
// TestWithMetadatas will test the method WithMetadatas()
func TestWithMetadatas(t *testing.T) {
t.Parallel()
t.Run("Get opts", func(t *testing.T) {
opt := WithMetadatas(map[string]interface{}{
"key": "value",
})
assert.IsType(t, *new(ModelOps), opt)
})
t.Run("apply opts", func(t *testing.T) {
opt := WithMetadatas(map[string]interface{}{
"key": "value",
})
m := new(Model)
m.SetOptions(opt)
assert.Equal(t, "value", m.Metadata["key"])
})
}