forked from hyperledger-cacti/cacti
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: shutdown hook configuration is using wrong config key
In the api-server constructor the evaluation for the activation / deactivation of the shutdown hook is based on the wrong configuration property so that it always is falling back to the default value and pre-configured value is not taken. Closes: hyperledger-cacti#1619 Signed-off-by: Michael Courtin <michael.courtin@accenture.com>
- Loading branch information
Showing
2 changed files
with
88 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
84 changes: 84 additions & 0 deletions
84
packages/cactus-cmd-api-server/src/test/typescript/unit/config/api-server-config.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
import "jest-extended"; | ||
import { | ||
ApiServer, | ||
// AuthorizationProtocol, | ||
ConfigService, | ||
} from "../../../../main/typescript/public-api"; | ||
|
||
describe("api-server shutdown-hook configuration tests", () => { | ||
// create a config service as base for the following UTs | ||
const configService = new ConfigService(); | ||
|
||
it("enables the shutdown hook based on schema-default", async () => { | ||
const expectedResult = true; | ||
const apiServerOptions = await configService.newExampleConfig(); | ||
const config = await configService.newExampleConfigConvict( | ||
apiServerOptions, | ||
); | ||
|
||
const apiServer = new ApiServer({ | ||
config: config.getProperties(), | ||
}); | ||
|
||
// check apiServerOptions | ||
expect(apiServerOptions).not.toBeUndefined(); | ||
expect(apiServerOptions.enableShutdownHook).toBe(expectedResult); | ||
|
||
// check apiServer | ||
expect(apiServer).toBeTruthy(); | ||
const result = apiServer["enableShutdownHook"]; | ||
expect(result).toBe(expectedResult); | ||
}); | ||
|
||
it("disables the shutdown hook based on the config value set to false", async () => { | ||
const expectedResult = false; | ||
const apiServerOptions = await configService.newExampleConfig(); | ||
|
||
// disable shutdown hook | ||
apiServerOptions.enableShutdownHook = false; | ||
|
||
const config = await configService.newExampleConfigConvict( | ||
apiServerOptions, | ||
true, | ||
); | ||
|
||
const apiServer = new ApiServer({ | ||
config: config.getProperties(), | ||
}); | ||
|
||
// check apiServerOptions | ||
expect(apiServerOptions).not.toBeUndefined(); | ||
expect(apiServerOptions.enableShutdownHook).toBe(expectedResult); | ||
|
||
// check apiServer | ||
expect(apiServer).toBeTruthy(); | ||
const result = apiServer["enableShutdownHook"]; | ||
expect(result).toBe(expectedResult); | ||
}); | ||
|
||
it("enables the shutdown hook based on the config value set to true", async () => { | ||
const expectedResult = true; | ||
const apiServerOptions = await configService.newExampleConfig(); | ||
|
||
// disable shutdown hook | ||
apiServerOptions.enableShutdownHook = true; | ||
|
||
const config = await configService.newExampleConfigConvict( | ||
apiServerOptions, | ||
true, | ||
); | ||
|
||
const apiServer = new ApiServer({ | ||
config: config.getProperties(), | ||
}); | ||
|
||
// check apiServerOptions | ||
expect(apiServerOptions).not.toBeUndefined(); | ||
expect(apiServerOptions.enableShutdownHook).toBe(expectedResult); | ||
|
||
// check apiServer | ||
expect(apiServer).toBeTruthy(); | ||
const result = apiServer["enableShutdownHook"]; | ||
expect(result).toBe(expectedResult); | ||
}); | ||
}); |