@@ -13,45 +13,77 @@ import * as proto from 'protocol';
13
13
import * as $ from 'platform/types/observe' ;
14
14
import * as convertor from '../src/util/convertor' ;
15
15
import * as runners from './runners' ;
16
+ import * as ty from '../src/protocol' ;
16
17
17
18
const config = readConfigurationFile ( ) . get ( ) . tests . protocol ;
18
19
20
+ function deepEqualObj ( a : any , b : any , depth = Infinity ) : boolean {
21
+ if ( depth < 1 || ( typeof a !== 'object' && typeof b !== 'object' ) ) {
22
+ return a === b || ( a == null && b == null ) ;
23
+ }
24
+ if ( a == null || b == null ) {
25
+ return a == null && b == null ;
26
+ }
27
+ if ( Array . isArray ( a ) && Array . isArray ( b ) ) {
28
+ if ( a . length !== b . length ) return false ;
29
+ return a . every ( ( item , index ) => deepEqualObj ( item , b [ index ] , depth - 1 ) ) ;
30
+ }
31
+ if ( typeof a === 'object' && typeof b === 'object' ) {
32
+ const keys1 = Object . keys ( a ) ;
33
+ const keys2 = Object . keys ( b ) ;
34
+
35
+ if ( keys1 . length !== keys2 . length ) return false ;
36
+ if ( ! keys1 . every ( ( key ) => keys2 . includes ( key ) ) ) return false ;
37
+
38
+ return keys1 . every ( ( key ) => deepEqualObj ( a [ key ] , b [ key ] , depth - 1 ) ) ;
39
+ }
40
+ return a === b ;
41
+ }
42
+
19
43
describe ( 'Protocol' , function ( ) {
20
44
it ( config . regular . list [ 1 ] , function ( ) {
21
45
return runners . noSession ( config . regular , 1 , async ( logger , done ) => {
22
- {
23
- let origin = convertor . toObserveOptions ( {
46
+ function check ( origin : ty . ObserveOptions ) {
47
+ expect (
48
+ deepEqualObj (
49
+ proto . ObserveOptions . decode ( proto . ObserveOptions . encode ( origin ) ) ,
50
+ origin ,
51
+ ) ,
52
+ ) . toBe ( true ) ;
53
+ }
54
+ check (
55
+ convertor . toObserveOptions ( {
24
56
origin : { File : [ 'somefile' , $ . Types . File . FileType . Text , 'path_to_file' ] } ,
25
57
parser : { Text : null } ,
26
- } ) ;
27
- let decoded = proto . ObserveOptions . decode ( proto . ObserveOptions . encode ( origin ) ) ;
28
- expect ( origin ) . toEqual ( decoded ) ;
29
- }
30
- {
31
- let origin = convertor . toObserveOptions ( {
58
+ } ) ,
59
+ ) ;
60
+ check (
61
+ convertor . toObserveOptions ( {
32
62
origin : {
33
63
Stream : [ 'stream' , { TCP : { bind_addr : '0.0.0.0' } } ] ,
34
64
} ,
35
65
parser : { Text : null } ,
36
- } ) ;
37
- let decoded = proto . ObserveOptions . decode ( proto . ObserveOptions . encode ( origin ) ) ;
38
- expect ( origin ) . toEqual ( decoded ) ;
39
- }
40
- {
41
- let origin = convertor . toObserveOptions ( {
66
+ } ) ,
67
+ ) ;
68
+ check (
69
+ convertor . toObserveOptions ( {
42
70
origin : {
43
71
Stream : [
44
72
'stream' ,
45
- { Process : { command : 'command' , cwd : 'cwd' , envs : { one : 'one' } } } ,
73
+ {
74
+ Process : {
75
+ command : 'command' ,
76
+ cwd : 'cwd' ,
77
+ envs : { one : 'one' } ,
78
+ } ,
79
+ } ,
46
80
] ,
47
81
} ,
48
82
parser : { Text : null } ,
49
- } ) ;
50
- let decoded = proto . ObserveOptions . decode ( proto . ObserveOptions . encode ( origin ) ) ;
51
- expect ( origin ) . toEqual ( decoded ) ;
52
- }
53
- {
54
- let origin = convertor . toObserveOptions ( {
83
+ } ) ,
84
+ ) ;
85
+ check (
86
+ convertor . toObserveOptions ( {
55
87
origin : {
56
88
Concat : [
57
89
[ 'somefile1' , $ . Types . File . FileType . Text , 'path_to_file' ] ,
@@ -60,13 +92,13 @@ describe('Protocol', function () {
60
92
] ,
61
93
} ,
62
94
parser : { Text : null } ,
63
- } ) ;
64
- let decoded = proto . ObserveOptions . decode ( proto . ObserveOptions . encode ( origin ) ) ;
65
- expect ( origin ) . toEqual ( decoded ) ;
66
- }
67
- {
68
- let origin = convertor . toObserveOptions ( {
69
- origin : { File : [ 'somefile' , $ . Types . File . FileType . Binary , 'path_to_file' ] } ,
95
+ } ) ,
96
+ ) ;
97
+ check (
98
+ convertor . toObserveOptions ( {
99
+ origin : {
100
+ File : [ 'somefile' , $ . Types . File . FileType . Binary , 'path_to_file' ] ,
101
+ } ,
70
102
parser : {
71
103
Dlt : {
72
104
fibex_file_paths : [ 'path' ] ,
@@ -75,13 +107,13 @@ describe('Protocol', function () {
75
107
tz : 'zz' ,
76
108
} ,
77
109
} ,
78
- } ) ;
79
- let decoded = proto . ObserveOptions . decode ( proto . ObserveOptions . encode ( origin ) ) ;
80
- // expect(origin).toEqual(decoded);
81
- }
82
- {
83
- let origin = convertor . toObserveOptions ( {
84
- origin : { File : [ 'somefile' , $ . Types . File . FileType . Binary , 'path_to_file' ] } ,
110
+ } ) ,
111
+ ) ;
112
+ check (
113
+ convertor . toObserveOptions ( {
114
+ origin : {
115
+ File : [ 'somefile' , $ . Types . File . FileType . Binary , 'path_to_file' ] ,
116
+ } ,
85
117
parser : {
86
118
Dlt : {
87
119
fibex_file_paths : [ ] ,
@@ -90,13 +122,13 @@ describe('Protocol', function () {
90
122
tz : 'zz' ,
91
123
} ,
92
124
} ,
93
- } ) ;
94
- let decoded = proto . ObserveOptions . decode ( proto . ObserveOptions . encode ( origin ) ) ;
95
- // expect(origin).toEqual(decoded);
96
- }
97
- {
98
- let origin = convertor . toObserveOptions ( {
99
- origin : { File : [ 'somefile' , $ . Types . File . FileType . Binary , 'path_to_file' ] } ,
125
+ } ) ,
126
+ ) ;
127
+ check (
128
+ convertor . toObserveOptions ( {
129
+ origin : {
130
+ File : [ 'somefile' , $ . Types . File . FileType . Binary , 'path_to_file' ] ,
131
+ } ,
100
132
parser : {
101
133
Dlt : {
102
134
fibex_file_paths : undefined ,
@@ -105,13 +137,13 @@ describe('Protocol', function () {
105
137
tz : 'zz' ,
106
138
} ,
107
139
} ,
108
- } ) ;
109
- let decoded = proto . ObserveOptions . decode ( proto . ObserveOptions . encode ( origin ) ) ;
110
- // expect(origin).toEqual(decoded);
111
- }
112
- {
113
- let origin = convertor . toObserveOptions ( {
114
- origin : { File : [ 'somefile' , $ . Types . File . FileType . Binary , 'path_to_file' ] } ,
140
+ } ) ,
141
+ ) ;
142
+ check (
143
+ convertor . toObserveOptions ( {
144
+ origin : {
145
+ File : [ 'somefile' , $ . Types . File . FileType . Binary , 'path_to_file' ] ,
146
+ } ,
115
147
parser : {
116
148
Dlt : {
117
149
fibex_file_paths : [ 'path' ] ,
@@ -127,46 +159,44 @@ describe('Protocol', function () {
127
159
tz : 'zz' ,
128
160
} ,
129
161
} ,
130
- } ) ;
131
- let decoded = proto . ObserveOptions . decode ( proto . ObserveOptions . encode ( origin ) ) ;
132
- // expect(origin).toEqual(decoded);
133
- }
134
- {
135
- let origin = convertor . toObserveOptions ( {
136
- origin : { File : [ 'somefile' , $ . Types . File . FileType . PcapNG , 'path_to_file' ] } ,
162
+ } ) ,
163
+ ) ;
164
+ check (
165
+ convertor . toObserveOptions ( {
166
+ origin : {
167
+ File : [ 'somefile' , $ . Types . File . FileType . PcapNG , 'path_to_file' ] ,
168
+ } ,
137
169
parser : {
138
170
SomeIp : {
139
171
fibex_file_paths : [ 'path' ] ,
140
172
} ,
141
173
} ,
142
- } ) ;
143
- let decoded = proto . ObserveOptions . decode ( proto . ObserveOptions . encode ( origin ) ) ;
144
- // expect(origin).toEqual(decoded);
145
- }
146
- {
147
- let origin = convertor . toObserveOptions ( {
148
- origin : { File : [ 'somefile' , $ . Types . File . FileType . PcapNG , 'path_to_file' ] } ,
174
+ } ) ,
175
+ ) ;
176
+ check (
177
+ convertor . toObserveOptions ( {
178
+ origin : {
179
+ File : [ 'somefile' , $ . Types . File . FileType . PcapNG , 'path_to_file' ] ,
180
+ } ,
149
181
parser : {
150
182
SomeIp : {
151
183
fibex_file_paths : [ ] ,
152
184
} ,
153
185
} ,
154
- } ) ;
155
- let decoded = proto . ObserveOptions . decode ( proto . ObserveOptions . encode ( origin ) ) ;
156
- // expect(origin).toEqual(decoded);
157
- }
158
- {
159
- let origin = convertor . toObserveOptions ( {
160
- origin : { File : [ 'somefile' , $ . Types . File . FileType . PcapNG , 'path_to_file' ] } ,
186
+ } ) ,
187
+ ) ;
188
+ check (
189
+ convertor . toObserveOptions ( {
190
+ origin : {
191
+ File : [ 'somefile' , $ . Types . File . FileType . PcapNG , 'path_to_file' ] ,
192
+ } ,
161
193
parser : {
162
194
SomeIp : {
163
195
fibex_file_paths : undefined ,
164
196
} ,
165
197
} ,
166
- } ) ;
167
- let decoded = proto . ObserveOptions . decode ( proto . ObserveOptions . encode ( origin ) ) ;
168
- // expect(origin).toEqual(decoded);
169
- }
198
+ } ) ,
199
+ ) ;
170
200
finish ( undefined , done ) ;
171
201
} ) ;
172
202
} ) ;
0 commit comments