-
Notifications
You must be signed in to change notification settings - Fork 0
/
nulls_test.go
80 lines (65 loc) · 1.65 KB
/
nulls_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
package nulls
import (
"encoding/json"
"github.com/stretchr/testify/suite"
"testing"
)
// jsonNull is the marshalled nil-value.
var jsonNull []byte
func init() {
var err error
jsonNull, err = json.Marshal(nil)
if err != nil {
panic(err)
}
}
// marshalMust marshals the given value and panics if marshalling fails.
func marshalMust(v any) []byte {
raw, err := json.Marshal(v)
if err != nil {
panic(err)
}
return raw
}
// isNullSuite tests isNull.
type isNullSuite struct {
suite.Suite
}
func (suite *isNullSuite) TestNil() {
suite.True(isNull(nil), "should return correct value")
}
func (suite *isNullSuite) TestNull() {
suite.True(isNull([]byte("null")), "should return correct value")
}
func (suite *isNullSuite) TestEmpty() {
suite.False(isNull([]byte("")), "should return correct value")
}
func (suite *isNullSuite) TestOK() {
suite.False(isNull([]byte("Hello World!")), "should return correct value")
}
func TestIsNull(t *testing.T) {
suite.Run(t, new(isNullSuite))
}
// copyBytesSuite tests copyBytes.
type copyBytesSuite struct {
suite.Suite
}
func (suite *copyBytesSuite) TestNil() {
b := copyBytes(nil)
suite.Nil(b, "should return correct value")
}
func (suite *copyBytesSuite) TestEmpty() {
original := make([]byte, 0)
b := copyBytes(original)
suite.Equal(original, b, "should return correct value")
suite.NotSame(original, b, "should return copy")
}
func (suite *copyBytesSuite) TestOK() {
original := []byte("Hello World!")
b := copyBytes(original)
suite.Equal(original, b, "should return correct value")
suite.NotSame(original, b, "should return copy")
}
func TestCopyBytes(t *testing.T) {
suite.Run(t, new(copyBytesSuite))
}