Skip to content

Commit

Permalink
Fix when missing functionConfig (#175)
Browse files Browse the repository at this point in the history
  • Loading branch information
prachirp authored Jul 13, 2020
1 parent adee356 commit 949dcdd
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 9 deletions.
2 changes: 1 addition & 1 deletion ts/kpt-functions/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion ts/kpt-functions/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "kpt-functions",
"version": "0.14.2",
"version": "0.14.3",
"description": "KPT functions framework library",
"author": "KPT Authors",
"license": "Apache-2.0",
Expand Down
9 changes: 4 additions & 5 deletions ts/kpt-functions/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,12 +172,10 @@ export class Configs {
* Throws a FunctionConfigError if functionConfig is undefined OR
* if the kind is not a v1/ConfigMap.
*/
getFunctionConfigMap() {
getFunctionConfigMap(): Map<string, string> | undefined {
const cm = this.getFunctionConfig();
if (cm === undefined) {
throw new FunctionConfigError(
`functionConfig expected, instead undefined`
);
return undefined;
}
if (!isConfigMap(cm)) {
throw new FunctionConfigError(
Expand All @@ -204,7 +202,8 @@ export class Configs {
* @key key The key in the 'data' field in the ConfigMap object given as the functionConfig.
*/
getFunctionConfigValue(key: string): string | undefined {
return this.getFunctionConfigMap().get(key);
const cm = this.getFunctionConfigMap();
return cm ? cm.get(key) : cm;
}

/**
Expand Down
4 changes: 2 additions & 2 deletions ts/kpt-functions/src/types_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -264,8 +264,8 @@ describe('functionConfig', () => {
it('no object', () => {
const configs = new Configs(undefined);
expect(configs.getFunctionConfig()).toBeUndefined();
expect(() => configs.getFunctionConfigMap()).toThrow();
expect(() => configs.getFunctionConfigValue('k3')).toThrow();
expect(configs.getFunctionConfigMap()).toBeUndefined();
expect(configs.getFunctionConfigValue('k3')).toBeUndefined();
expect(() => configs.getFunctionConfigValueOrThrow('k3')).toThrow();
});

Expand Down

0 comments on commit 949dcdd

Please sign in to comment.