|
1 | 1 | import { MongoshUnimplementedError } from '@mongosh/errors'; |
2 | 2 | import { expect } from 'chai'; |
3 | 3 | import stripAnsi from 'strip-ansi'; |
4 | | -import { getLocale, parseCliArgs } from './arg-parser'; |
| 4 | +import { |
| 5 | + coerceIfBoolean, |
| 6 | + generateYargsOptions, |
| 7 | + getLocale, |
| 8 | + parseCliArgs, |
| 9 | +} from './arg-parser'; |
5 | 10 |
|
6 | 11 | describe('arg-parser', function () { |
7 | 12 | describe('.getLocale', function () { |
@@ -1006,4 +1011,113 @@ describe('arg-parser', function () { |
1006 | 1011 | }); |
1007 | 1012 | } |
1008 | 1013 | }); |
| 1014 | + |
| 1015 | + describe('backwards compatibility', function () { |
| 1016 | + it('generates the same options as yargs-parser', function () { |
| 1017 | + const options = generateYargsOptions(); |
| 1018 | + |
| 1019 | + const expected = { |
| 1020 | + string: [ |
| 1021 | + 'apiVersion', |
| 1022 | + 'authenticationDatabase', |
| 1023 | + 'authenticationMechanism', |
| 1024 | + 'awsAccessKeyId', |
| 1025 | + 'awsIamSessionToken', |
| 1026 | + 'awsSecretAccessKey', |
| 1027 | + 'awsSessionToken', |
| 1028 | + 'csfleLibraryPath', |
| 1029 | + 'cryptSharedLibPath', |
| 1030 | + 'db', |
| 1031 | + 'gssapiHostName', |
| 1032 | + 'gssapiServiceName', |
| 1033 | + 'sspiHostnameCanonicalization', |
| 1034 | + 'sspiRealmOverride', |
| 1035 | + 'jsContext', |
| 1036 | + 'host', |
| 1037 | + 'keyVaultNamespace', |
| 1038 | + 'kmsURL', |
| 1039 | + 'locale', |
| 1040 | + 'oidcFlows', |
| 1041 | + 'oidcRedirectUri', |
| 1042 | + 'password', |
| 1043 | + 'port', |
| 1044 | + 'sslPEMKeyFile', |
| 1045 | + 'sslPEMKeyPassword', |
| 1046 | + 'sslCAFile', |
| 1047 | + 'sslCertificateSelector', |
| 1048 | + 'sslCRLFile', |
| 1049 | + 'sslDisabledProtocols', |
| 1050 | + 'tlsCAFile', |
| 1051 | + 'tlsCertificateKeyFile', |
| 1052 | + 'tlsCertificateKeyFilePassword', |
| 1053 | + 'tlsCertificateSelector', |
| 1054 | + 'tlsCRLFile', |
| 1055 | + 'tlsDisabledProtocols', |
| 1056 | + 'username', |
| 1057 | + ], |
| 1058 | + boolean: [ |
| 1059 | + 'apiDeprecationErrors', |
| 1060 | + 'apiStrict', |
| 1061 | + 'buildInfo', |
| 1062 | + 'exposeAsyncRewriter', |
| 1063 | + 'help', |
| 1064 | + 'ipv6', |
| 1065 | + 'nodb', |
| 1066 | + 'norc', |
| 1067 | + 'oidcTrustedEndpoint', |
| 1068 | + 'oidcIdTokenAsAccessToken', |
| 1069 | + 'oidcNoNonce', |
| 1070 | + 'perfTests', |
| 1071 | + 'quiet', |
| 1072 | + 'retryWrites', |
| 1073 | + 'shell', |
| 1074 | + 'smokeTests', |
| 1075 | + 'skipStartupWarnings', |
| 1076 | + 'ssl', |
| 1077 | + 'sslAllowInvalidCertificates', |
| 1078 | + 'sslAllowInvalidHostnames', |
| 1079 | + 'sslFIPSMode', |
| 1080 | + 'tls', |
| 1081 | + 'tlsAllowInvalidCertificates', |
| 1082 | + 'tlsAllowInvalidHostnames', |
| 1083 | + 'tlsFIPSMode', |
| 1084 | + 'tlsUseSystemCA', |
| 1085 | + 'verbose', |
| 1086 | + 'version', |
| 1087 | + ], |
| 1088 | + array: ['eval', 'file'], |
| 1089 | + coerce: { |
| 1090 | + json: coerceIfBoolean, |
| 1091 | + oidcDumpTokens: coerceIfBoolean, |
| 1092 | + browser: coerceIfBoolean, |
| 1093 | + }, |
| 1094 | + alias: { |
| 1095 | + h: 'help', |
| 1096 | + p: 'password', |
| 1097 | + u: 'username', |
| 1098 | + f: 'file', |
| 1099 | + 'build-info': 'buildInfo', |
| 1100 | + oidcRedirectUrl: 'oidcRedirectUri', // I'd get this wrong about 50% of the time |
| 1101 | + oidcIDTokenAsAccessToken: 'oidcIdTokenAsAccessToken', // ditto |
| 1102 | + }, |
| 1103 | + configuration: { |
| 1104 | + 'camel-case-expansion': false, |
| 1105 | + 'unknown-options-as-args': true, |
| 1106 | + 'parse-positional-numbers': false, |
| 1107 | + 'parse-numbers': false, |
| 1108 | + 'greedy-arrays': false, |
| 1109 | + 'short-option-groups': false, |
| 1110 | + }, |
| 1111 | + }; |
| 1112 | + |
| 1113 | + // Compare arrays without caring about order |
| 1114 | + expect(options.string?.sort()).to.deep.equal(expected.string.sort()); |
| 1115 | + expect(options.boolean?.sort()).to.deep.equal(expected.boolean.sort()); |
| 1116 | + expect(options.array?.sort()).to.deep.equal(expected.array.sort()); |
| 1117 | + |
| 1118 | + // Compare non-array properties normally |
| 1119 | + expect(options.alias).to.deep.equal(expected.alias); |
| 1120 | + expect(options.configuration).to.deep.equal(expected.configuration); |
| 1121 | + }); |
| 1122 | + }); |
1009 | 1123 | }); |
0 commit comments