6
6
// disabling init_rand_seed as it takes longer than the actual test execution
7
7
process . env . DISABLE_INIT_RANDOM_SEED = "true" ;
8
8
9
+ const _ = require ( 'lodash' ) ;
9
10
const fs = require ( 'fs' ) ;
10
11
const path = require ( 'path' ) ;
11
12
const os_util = require ( '../../../util/os_utils' ) ;
@@ -14,6 +15,8 @@ const { ConfigFS } = require('../../../sdk/config_fs');
14
15
const { TMP_PATH , set_nc_config_dir_in_config } = require ( '../../system_tests/test_utils' ) ;
15
16
const { TYPES , ACTIONS } = require ( '../../../manage_nsfs/manage_nsfs_constants' ) ;
16
17
18
+ const ManageCLIError = require ( '../../../manage_nsfs/manage_nsfs_cli_errors' ) . ManageCLIError ;
19
+
17
20
const tmp_fs_path = path . join ( TMP_PATH , 'test_nc_connection_cli.test' ) ;
18
21
const timeout = 5000 ;
19
22
@@ -58,7 +61,9 @@ describe('manage nsfs cli connection flow', () => {
58
61
it ( 'cli create connection from cli' , async ( ) => {
59
62
const conn_options = { ...defaults , config_root} ;
60
63
conn_options . name = "fromcli" ;
61
- await exec_manage_cli ( TYPES . CONNECTION , ACTIONS . ADD , conn_options ) ;
64
+ const res = await exec_manage_cli ( TYPES . CONNECTION , ACTIONS . ADD , conn_options ) ;
65
+ const res_json = JSON . parse ( res . trim ( ) ) ;
66
+ expect ( _ . isEqual ( new Set ( Object . keys ( res_json . response ) ) , new Set ( [ 'reply' , 'code' , 'message' ] ) ) ) . toBe ( true ) ;
62
67
const connection = await config_fs . get_connection_by_name ( conn_options . name ) ;
63
68
assert_connection ( connection , conn_options , true ) ;
64
69
} , timeout ) ;
@@ -96,6 +101,26 @@ describe('manage nsfs cli connection flow', () => {
96
101
assert_connection ( res . response . reply , defaults , false ) ;
97
102
} , timeout ) ;
98
103
104
+ it ( 'conn already exists' , async ( ) => {
105
+ const action = ACTIONS . ADD ;
106
+ const { name, agent_request_object, request_options_object, notification_protocol } = defaults ;
107
+ const conn_options = { config_root, name, agent_request_object, request_options_object, notification_protocol } ;
108
+ await exec_manage_cli ( TYPES . CONNECTION , action , conn_options ) ;
109
+ const actual = await config_fs . get_connection_by_name ( name ) ;
110
+ assert_connection ( actual , defaults , true ) ;
111
+
112
+ const res = await exec_manage_cli ( TYPES . CONNECTION , action , conn_options , true ) ;
113
+ const res_json = JSON . parse ( res . trim ( ) ) ;
114
+ expect ( res_json . error . code ) . toBe ( ManageCLIError . ConnectionAlreadyExists . code ) ;
115
+ } ) ;
116
+
117
+ it ( 'conn does not exist' , async ( ) => {
118
+ const conn_options = { config_root, name : "badname" } ;
119
+ const res = await exec_manage_cli ( TYPES . CONNECTION , ACTIONS . DELETE , conn_options , true ) ;
120
+ const res_json = JSON . parse ( res . trim ( ) ) ;
121
+ expect ( res_json . error . code ) . toBe ( ManageCLIError . NoSuchConnection . code ) ;
122
+ } ) ;
123
+
99
124
} ) ;
100
125
} ) ;
101
126
@@ -123,13 +148,17 @@ function assert_connection(connection, connection_options, is_encrypted) {
123
148
* @param {string } action
124
149
* @param {object } options
125
150
*/
126
- async function exec_manage_cli ( type , action , options ) {
151
+ async function exec_manage_cli ( type , action , options , expect_failure = false ) {
127
152
const command = create_command ( type , action , options ) ;
128
153
let res ;
129
154
try {
130
155
res = await os_util . exec ( command , { return_stdout : true } ) ;
131
156
} catch ( e ) {
132
- res = e ;
157
+ if ( expect_failure ) {
158
+ res = e . stdout ;
159
+ } else {
160
+ res = e ;
161
+ }
133
162
}
134
163
return res ;
135
164
}
0 commit comments