8
8
9
9
"github.com/stretchr/testify/assert"
10
10
"github.com/stretchr/testify/require"
11
+
12
+ "go.opentelemetry.io/collector/pdata/internal/json"
11
13
)
12
14
13
15
func TestProfileID (t * testing.T ) {
@@ -39,18 +41,6 @@ func TestProfileIDMarshal(t *testing.T) {
39
41
assert .Error (t , err )
40
42
}
41
43
42
- func TestProfileIDMarshalJSON (t * testing.T ) {
43
- tid := ProfileID ([16 ]byte {})
44
- json , err := tid .MarshalJSON ()
45
- require .NoError (t , err )
46
- assert .JSONEq (t , `""` , string (json ))
47
-
48
- tid = [16 ]byte {0x12 , 0x34 , 0x56 , 0x78 , 0x12 , 0x34 , 0x56 , 0x78 , 0x12 , 0x34 , 0x56 , 0x78 , 0x12 , 0x34 , 0x56 , 0x78 }
49
- json , err = tid .MarshalJSON ()
50
- require .NoError (t , err )
51
- assert .JSONEq (t , `"12345678123456781234567812345678"` , string (json ))
52
- }
53
-
54
44
func TestProfileIDUnmarshal (t * testing.T ) {
55
45
buf := [16 ]byte {0x12 , 0x34 , 0x56 , 0x78 , 0x12 , 0x34 , 0x56 , 0x78 , 0x12 , 0x34 , 0x56 , 0x78 , 0x12 , 0x34 , 0x56 , 0x78 }
56
46
@@ -68,33 +58,18 @@ func TestProfileIDUnmarshal(t *testing.T) {
68
58
assert .EqualValues (t , [16 ]byte {}, tid )
69
59
}
70
60
71
- func TestProfileIDUnmarshalJSON (t * testing.T ) {
72
- tid := ProfileID ([16 ]byte {})
73
- err := tid .UnmarshalJSON ([]byte (`""` ))
74
- require .NoError (t , err )
75
- assert .EqualValues (t , [16 ]byte {}, tid )
76
-
77
- err = tid .UnmarshalJSON ([]byte (`""""` ))
78
- require .Error (t , err )
61
+ func TestProfileIDMarshalAndUnmarshalJSON (t * testing.T ) {
62
+ stream := json .BorrowStream (nil )
63
+ defer json .ReturnStream (stream )
64
+ src := ProfileID ([16 ]byte {0x12 , 0x34 , 0x56 , 0x78 , 0x12 , 0x34 , 0x56 , 0x78 , 0x12 , 0x34 , 0x56 , 0x78 , 0x12 , 0x34 , 0x56 , 0x78 })
65
+ src .MarshalJSONStream (stream )
66
+ require .NoError (t , stream .Error )
79
67
80
- tidBytes := [16 ]byte {0x12 , 0x34 , 0x56 , 0x78 , 0x12 , 0x34 , 0x56 , 0x78 , 0x12 , 0x34 , 0x56 , 0x78 , 0x12 , 0x34 , 0x56 , 0x78 }
81
- err = tid .UnmarshalJSON ([]byte (`"12345678123456781234567812345678"` ))
82
- require .NoError (t , err )
83
- assert .EqualValues (t , tidBytes , tid )
84
-
85
- err = tid .UnmarshalJSON ([]byte (`12345678123456781234567812345678` ))
86
- require .NoError (t , err )
87
- assert .EqualValues (t , tidBytes , tid )
68
+ iter := json .BorrowIterator (stream .Buffer ())
69
+ defer json .ReturnIterator (iter )
70
+ dest := ProfileID {}
71
+ dest .UnmarshalJSONIter (iter )
72
+ require .NoError (t , iter .Error )
88
73
89
- err = tid .UnmarshalJSON ([]byte (`"nothex"` ))
90
- require .Error (t , err )
91
-
92
- err = tid .UnmarshalJSON ([]byte (`"1"` ))
93
- require .Error (t , err )
94
-
95
- err = tid .UnmarshalJSON ([]byte (`"123"` ))
96
- require .Error (t , err )
97
-
98
- err = tid .UnmarshalJSON ([]byte (`"` ))
99
- assert .Error (t , err )
74
+ assert .Equal (t , src , dest )
100
75
}
0 commit comments