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