@@ -20,168 +20,206 @@ describe('FaaS', () => {
20
20
region,
21
21
} ) ;
22
22
23
- test ( 'getRegion' , async ( ) => {
24
- const region = faas . getRegion ( ) ;
23
+ describe ( 'base methods' , ( ) => {
24
+ test ( 'getRegion' , async ( ) => {
25
+ const region = faas . getRegion ( ) ;
25
26
26
- expect ( region ) . toBe ( region ) ;
27
- } ) ;
28
-
29
- test ( 'setRegion' , async ( ) => {
30
- faas . setRegion ( 'ap-shanghai' ) ;
31
-
32
- expect ( faas . getRegion ( ) ) . toBe ( 'ap-shanghai' ) ;
27
+ expect ( region ) . toBe ( region ) ;
28
+ } ) ;
33
29
34
- // 还原为 ap-guangzhou
35
- faas . setRegion ( region ) ;
36
- } ) ;
30
+ test ( 'setRegion' , async ( ) => {
31
+ faas . setRegion ( 'ap-shanghai' ) ;
37
32
38
- test ( 'getNamespaces' , async ( ) => {
39
- const res = await faas . getNamespaces ( ) ;
40
- expect ( Array . isArray ( res ) ) . toBe ( true ) ;
41
- } ) ;
33
+ expect ( faas . getRegion ( ) ) . toBe ( 'ap-shanghai' ) ;
42
34
43
- test ( 'getVersions' , async ( ) => {
44
- const res = await faas . getVersions ( {
45
- ...faasConfig ,
35
+ // 还原为 ap-guangzhou
36
+ faas . setRegion ( region ) ;
46
37
} ) ;
47
38
48
- expect ( Array . isArray ( res ) ) . toBe ( true ) ;
49
- } ) ;
50
-
51
- test ( 'invoke' , async ( ) => {
52
- const res = ( await faas . invoke ( {
53
- ...faasConfig ,
54
- } ) ) as InvokeResult ;
55
-
56
- expect ( res ) . toEqual ( {
57
- billDuration : expect . any ( Number ) ,
58
- duration : expect . any ( Number ) ,
59
- errMsg : expect . any ( String ) ,
60
- memUsage : expect . any ( Number ) ,
61
- functionRequestId : expect . any ( String ) ,
62
- invokeResult : expect . any ( Number ) ,
63
- log : expect . any ( String ) ,
64
- retMsg : expect . any ( String ) ,
39
+ test ( 'getNamespaces' , async ( ) => {
40
+ const res = await faas . getNamespaces ( ) ;
41
+ expect ( Array . isArray ( res ) ) . toBe ( true ) ;
65
42
} ) ;
66
43
67
- reqId = res . functionRequestId ;
68
- } ) ;
69
- test ( 'invoke with wrong region' , async ( ) => {
70
- try {
71
- faas . setRegion ( 'ap-test' ) ;
72
- await faas . invoke ( {
44
+ test ( 'getVersions' , async ( ) => {
45
+ const res = await faas . getVersions ( {
73
46
...faasConfig ,
74
47
} ) ;
75
- } catch ( e ) {
76
- expect ( e . code ) . toBe ( '1001' ) ;
77
- }
78
- faas . setRegion ( region ) ;
48
+
49
+ expect ( Array . isArray ( res ) ) . toBe ( true ) ;
50
+ } ) ;
79
51
} ) ;
80
- test ( 'invoke with wrong namespace' , async ( ) => {
81
- try {
82
- await faas . invoke ( {
52
+
53
+ describe ( 'invoke' , ( ) => {
54
+ test ( 'invoke' , async ( ) => {
55
+ const res = ( await faas . invoke ( {
83
56
...faasConfig ,
84
- namespace : 'not_exist_namespace' ,
57
+ } ) ) as InvokeResult ;
58
+
59
+ expect ( res ) . toEqual ( {
60
+ billDuration : expect . any ( Number ) ,
61
+ duration : expect . any ( Number ) ,
62
+ errMsg : expect . any ( String ) ,
63
+ memUsage : expect . any ( Number ) ,
64
+ functionRequestId : expect . any ( String ) ,
65
+ invokeResult : expect . any ( Number ) ,
66
+ log : expect . any ( String ) ,
67
+ retMsg : expect . any ( String ) ,
85
68
} ) ;
86
- } catch ( e ) {
87
- expect ( e . code ) . toBe ( '1005' ) ;
88
- }
89
- } ) ;
90
- test ( 'invoke with wrong qualifier' , async ( ) => {
91
- try {
92
- await faas . invoke ( {
69
+
70
+ reqId = res . functionRequestId ;
71
+ } ) ;
72
+
73
+ test ( 'invoke with qualifier $DEFAULT' , async ( ) => {
74
+ const res = ( await faas . invoke ( {
93
75
...faasConfig ,
94
- qualifier : 'not_exist_qualifier' ,
76
+ qualifier : '$DEFAULT' ,
77
+ } ) ) as InvokeResult ;
78
+
79
+ expect ( res ) . toEqual ( {
80
+ billDuration : expect . any ( Number ) ,
81
+ duration : expect . any ( Number ) ,
82
+ errMsg : expect . any ( String ) ,
83
+ memUsage : expect . any ( Number ) ,
84
+ functionRequestId : expect . any ( String ) ,
85
+ invokeResult : expect . any ( Number ) ,
86
+ log : expect . any ( String ) ,
87
+ retMsg : expect . any ( String ) ,
95
88
} ) ;
96
- } catch ( e ) {
97
- expect ( e . code ) . toBe ( '1006' ) ;
98
- }
99
- } ) ;
89
+ } ) ;
100
90
101
- test ( 'getClsConfig' , async ( ) => {
102
- const res = await faas . getClsConfig ( {
103
- ...faasConfig ,
91
+ test ( 'invoke with wrong qualifier' , async ( ) => {
92
+ try {
93
+ await faas . invoke ( {
94
+ ...faasConfig ,
95
+ qualifier : 'wrong_qualifier' ,
96
+ } ) ;
97
+ } catch ( e ) {
98
+ expect ( e . code ) . toBe ( '1006' ) ;
99
+ }
104
100
} ) ;
105
101
106
- expect ( res ) . toEqual ( clsConfig ) ;
102
+ test ( 'invoke with wrong region' , async ( ) => {
103
+ try {
104
+ faas . setRegion ( 'ap-test' ) ;
105
+ await faas . invoke ( {
106
+ ...faasConfig ,
107
+ } ) ;
108
+ } catch ( e ) {
109
+ expect ( e . code ) . toBe ( '1001' ) ;
110
+ }
111
+ faas . setRegion ( region ) ;
112
+ } ) ;
113
+ test ( 'invoke with wrong namespace' , async ( ) => {
114
+ try {
115
+ await faas . invoke ( {
116
+ ...faasConfig ,
117
+ namespace : 'not_exist_namespace' ,
118
+ } ) ;
119
+ } catch ( e ) {
120
+ expect ( e . code ) . toBe ( '1005' ) ;
121
+ }
122
+ } ) ;
123
+ test ( 'invoke with wrong qualifier' , async ( ) => {
124
+ try {
125
+ await faas . invoke ( {
126
+ ...faasConfig ,
127
+ qualifier : 'not_exist_qualifier' ,
128
+ } ) ;
129
+ } catch ( e ) {
130
+ expect ( e . code ) . toBe ( '1006' ) ;
131
+ }
132
+ } ) ;
107
133
} ) ;
108
134
109
- test ( 'getLogList' , async ( ) => {
110
- const res = await faas . getLogList ( {
111
- ...faasConfig ,
135
+ describe ( 'log' , ( ) => {
136
+ test ( 'getClsConfig' , async ( ) => {
137
+ const res = await faas . getClsConfig ( {
138
+ ...faasConfig ,
139
+ } ) ;
140
+
141
+ expect ( res ) . toEqual ( clsConfig ) ;
112
142
} ) ;
113
143
114
- if ( res [ 0 ] ) {
115
- reqId = res [ 0 ] ! . requestId ;
116
- }
117
- expect ( res ) . toBeInstanceOf ( Array ) ;
118
- } ) ;
144
+ test ( 'getLogList' , async ( ) => {
145
+ const res = await faas . getLogList ( {
146
+ ...faasConfig ,
147
+ } ) ;
119
148
120
- test ( 'getLogDetail' , async ( ) => {
121
- const res = await faas . getLogDetail ( {
122
- ...faasConfig ,
123
- ...clsConfig ,
124
- reqId,
149
+ if ( res [ 0 ] ) {
150
+ reqId = res [ 0 ] ! . requestId ;
151
+ }
152
+ expect ( res ) . toBeInstanceOf ( Array ) ;
125
153
} ) ;
126
- expect ( res ) . toBeInstanceOf ( Array ) ;
127
- } ) ;
128
- test ( 'getLogByReqId' , async ( ) => {
129
- const res = await faas . getLogByReqId ( {
130
- ...faasConfig ,
131
- reqId,
154
+
155
+ test ( 'getLogDetail' , async ( ) => {
156
+ const res = await faas . getLogDetail ( {
157
+ ...faasConfig ,
158
+ ...clsConfig ,
159
+ reqId,
160
+ } ) ;
161
+ expect ( res ) . toBeInstanceOf ( Array ) ;
132
162
} ) ;
163
+ test ( 'getLogByReqId' , async ( ) => {
164
+ const res = await faas . getLogByReqId ( {
165
+ ...faasConfig ,
166
+ reqId,
167
+ } ) ;
133
168
134
- expect ( res ) . toEqual ( {
135
- requestId : reqId ,
136
- retryNum : 0 ,
137
- startTime : expect . any ( String ) ,
138
- memoryUsage : expect . any ( String ) ,
139
- duration : expect . any ( String ) ,
140
- message : expect . any ( String ) ,
141
- isCompleted : expect . any ( Boolean ) ,
169
+ expect ( res ) . toEqual ( {
170
+ requestId : reqId ,
171
+ retryNum : 0 ,
172
+ startTime : expect . any ( String ) ,
173
+ memoryUsage : expect . any ( String ) ,
174
+ duration : expect . any ( String ) ,
175
+ message : expect . any ( String ) ,
176
+ isCompleted : expect . any ( Boolean ) ,
177
+ } ) ;
142
178
} ) ;
143
179
} ) ;
144
180
145
- test ( 'getMetric' , async ( ) => {
146
- const res = await faas . getMetric ( {
147
- ...faasConfig ,
148
- metric : 'Invocation' ,
149
- isRaw : false ,
181
+ describe ( 'metric' , ( ) => {
182
+ test ( 'getMetric' , async ( ) => {
183
+ const res = await faas . getMetric ( {
184
+ ...faasConfig ,
185
+ metric : 'Invocation' ,
186
+ isRaw : false ,
187
+ } ) ;
188
+ expect ( res ) . toBeInstanceOf ( Array ) ;
189
+ if ( res . length > 0 ) {
190
+ expect ( res ) . toEqual (
191
+ expect . arrayContaining ( [
192
+ {
193
+ time : expect . any ( String ) ,
194
+ value : expect . any ( Number ) ,
195
+ timestamp : expect . any ( Number ) ,
196
+ } ,
197
+ ] ) ,
198
+ ) ;
199
+ }
150
200
} ) ;
151
- expect ( res ) . toBeInstanceOf ( Array ) ;
152
- if ( res . length > 0 ) {
153
- expect ( res ) . toEqual (
154
- expect . arrayContaining ( [
201
+
202
+ test ( '[isRaw = true] getMetric' , async ( ) => {
203
+ const res = await faas . getMetric ( {
204
+ ...faasConfig ,
205
+ metric : 'Invocation' ,
206
+ isRaw : true ,
207
+ } ) ;
208
+
209
+ expect ( res ) . toEqual ( {
210
+ StartTime : expect . any ( String ) ,
211
+ EndTime : expect . any ( String ) ,
212
+ MetricName : expect . any ( String ) ,
213
+ Period : expect . any ( Number ) ,
214
+ DataPoints : expect . arrayContaining ( [
155
215
{
156
- time : expect . any ( String ) ,
157
- value : expect . any ( Number ) ,
158
- timestamp : expect . any ( Number ) ,
216
+ Dimensions : expect . any ( Array ) ,
217
+ Timestamps : expect . any ( Array ) ,
218
+ Values : expect . any ( Array ) ,
159
219
} ,
160
220
] ) ,
161
- ) ;
162
- }
163
- } ) ;
164
-
165
- test ( '[isRaw = true] getMetric' , async ( ) => {
166
- const res = await faas . getMetric ( {
167
- ...faasConfig ,
168
- metric : 'Invocation' ,
169
- isRaw : true ,
170
- } ) ;
171
-
172
- expect ( res ) . toEqual ( {
173
- StartTime : expect . any ( String ) ,
174
- EndTime : expect . any ( String ) ,
175
- MetricName : expect . any ( String ) ,
176
- Period : expect . any ( Number ) ,
177
- DataPoints : expect . arrayContaining ( [
178
- {
179
- Dimensions : expect . any ( Array ) ,
180
- Timestamps : expect . any ( Array ) ,
181
- Values : expect . any ( Array ) ,
182
- } ,
183
- ] ) ,
184
- RequestId : expect . stringMatching ( / .{ 36 } / g) ,
221
+ RequestId : expect . stringMatching ( / .{ 36 } / g) ,
222
+ } ) ;
185
223
} ) ;
186
224
} ) ;
187
225
} ) ;
0 commit comments