chia7712 commented on code in PR #20177:
URL: https://github.com/apache/kafka/pull/20177#discussion_r2244362790
##########
tools/src/test/java/org/apache/kafka/tools/DelegationTokenCommandTest.java:
##########
@@ -109,4 +110,156 @@ private
DelegationTokenCommand.DelegationTokenCommandOptions getExpireOpts(Strin
String[] args = {"--bootstrap-server", "localhost:9092",
"--command-config", "testfile", "--expire", "--expiry-time-period", "-1",
"--hmac", hmac};
return new DelegationTokenCommand.DelegationTokenCommandOptions(args);
}
+
+
+ @Test
+ public void testCheckArgsMissingRequiredArgs() {
+ Exit.setExitProcedure((exitCode, message) -> {
+ throw new RuntimeException("Exit with code " + exitCode + ": " +
message);
+ });
+ try {
+ String[] argsCreateMissingBootstrap = {"--command-config",
"testfile", "--create", "--max-life-time-period", "604800000"};
+ DelegationTokenCommand.DelegationTokenCommandOptions
optsCreateMissingBootstrap = new
DelegationTokenCommand.DelegationTokenCommandOptions(argsCreateMissingBootstrap);
+ assertThrows(RuntimeException.class, () ->
optsCreateMissingBootstrap.checkArgs());
+
+ String[] argsCreateMissingConfig = {"--bootstrap-server",
"localhost:9092", "--create", "--max-life-time-period", "604800000"};
+ DelegationTokenCommand.DelegationTokenCommandOptions
optsCreateMissingConfig = new
DelegationTokenCommand.DelegationTokenCommandOptions(argsCreateMissingConfig);
+ assertThrows(RuntimeException.class, () ->
optsCreateMissingConfig.checkArgs());
+
+ String[] argsCreateMissingMaxLife = {"--bootstrap-server",
"localhost:9092", "--command-config", "testfile", "--create"};
+ DelegationTokenCommand.DelegationTokenCommandOptions
optsCreateMissingMaxLife = new
DelegationTokenCommand.DelegationTokenCommandOptions(argsCreateMissingMaxLife);
+ assertThrows(RuntimeException.class, () ->
optsCreateMissingMaxLife.checkArgs());
+
+ String[] argsRenewMissingBootstrap = {"--command-config",
"testfile", "--renew", "--hmac", "test-hmac", "--renew-time-period",
"604800000"};
+ DelegationTokenCommand.DelegationTokenCommandOptions
optsRenewMissingBootstrap = new
DelegationTokenCommand.DelegationTokenCommandOptions(argsRenewMissingBootstrap);
+ assertThrows(RuntimeException.class, () ->
optsRenewMissingBootstrap.checkArgs());
+
+ String[] argsRenewMissingConfig = {"--bootstrap-server",
"localhost:9092", "--renew", "--hmac", "test-hmac", "--renew-time-period",
"604800000"};
+ DelegationTokenCommand.DelegationTokenCommandOptions
optsRenewMissingConfig = new
DelegationTokenCommand.DelegationTokenCommandOptions(argsRenewMissingConfig);
+ assertThrows(RuntimeException.class, () ->
optsRenewMissingConfig.checkArgs());
+
+ String[] argsRenewMissingHmac = {"--bootstrap-server",
"localhost:9092", "--command-config", "testfile", "--renew",
"--renew-time-period", "604800000"};
+ DelegationTokenCommand.DelegationTokenCommandOptions
optsRenewMissingHmac = new
DelegationTokenCommand.DelegationTokenCommandOptions(argsRenewMissingHmac);
+ assertThrows(RuntimeException.class, () ->
optsRenewMissingHmac.checkArgs());
+
+ String[] argsRenewMissingRenewTime = {"--bootstrap-server",
"localhost:9092", "--command-config", "testfile", "--renew", "--hmac",
"test-hmac"};
+ DelegationTokenCommand.DelegationTokenCommandOptions
optsRenewMissingRenewTime = new
DelegationTokenCommand.DelegationTokenCommandOptions(argsRenewMissingRenewTime);
+ assertThrows(RuntimeException.class, () ->
optsRenewMissingRenewTime.checkArgs());
+
+ String[] argsExpireMissingBootstrap = {"--command-config",
"testfile", "--expire", "--hmac", "test-hmac", "--expiry-time-period",
"604800000"};
+ DelegationTokenCommand.DelegationTokenCommandOptions
optsExpireMissingBootstrap = new
DelegationTokenCommand.DelegationTokenCommandOptions(argsExpireMissingBootstrap);
+ assertThrows(RuntimeException.class, () ->
optsExpireMissingBootstrap.checkArgs());
+
+ String[] argsExpireMissingConfig = {"--bootstrap-server",
"localhost:9092", "--expire", "--hmac", "test-hmac", "--expiry-time-period",
"604800000"};
+ DelegationTokenCommand.DelegationTokenCommandOptions
optsExpireMissingConfig = new
DelegationTokenCommand.DelegationTokenCommandOptions(argsExpireMissingConfig);
+ assertThrows(RuntimeException.class, () ->
optsExpireMissingConfig.checkArgs());
+
+ String[] argsExpireMissingHmac = {"--bootstrap-server",
"localhost:9092", "--command-config", "testfile", "--expire",
"--expiry-time-period", "604800000"};
+ DelegationTokenCommand.DelegationTokenCommandOptions
optsExpireMissingHmac = new
DelegationTokenCommand.DelegationTokenCommandOptions(argsExpireMissingHmac);
+ assertThrows(RuntimeException.class, () ->
optsExpireMissingHmac.checkArgs());
+
+ String[] argsExpireMissingExpiryTime = {"--bootstrap-server",
"localhost:9092", "--command-config", "testfile", "--expire", "--hmac",
"test-hmac"};
+ DelegationTokenCommand.DelegationTokenCommandOptions
optsExpireMissingExpiryTime = new
DelegationTokenCommand.DelegationTokenCommandOptions(argsExpireMissingExpiryTime);
+ assertThrows(RuntimeException.class, () ->
optsExpireMissingExpiryTime.checkArgs());
+
+ String[] argsDescribeMissingBootstrap = {"--command-config",
"testfile", "--describe"};
+ DelegationTokenCommand.DelegationTokenCommandOptions
optsDescribeMissingBootstrap = new
DelegationTokenCommand.DelegationTokenCommandOptions(argsDescribeMissingBootstrap);
+ assertThrows(RuntimeException.class, () ->
optsDescribeMissingBootstrap.checkArgs());
+
+ String[] argsDescribeMissingConfig = {"--bootstrap-server",
"localhost:9092", "--describe"};
+ DelegationTokenCommand.DelegationTokenCommandOptions
optsDescribeMissingConfig = new
DelegationTokenCommand.DelegationTokenCommandOptions(argsDescribeMissingConfig);
+ assertThrows(RuntimeException.class, () ->
optsDescribeMissingConfig.checkArgs());
Review Comment:
Please use `optsDescribeMissingConfig::checkArgs` instead
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]