Skip to content

Commit

Permalink
Merge pull request #2039 from zowe/fix/coverity-null-like
Browse files Browse the repository at this point in the history
fix: Coverity null-like in `updateSchemaAtLayer`
  • Loading branch information
traeok committed Feb 8, 2024
2 parents c5a99d8 + 83c5bc7 commit 5667624
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1416,6 +1416,17 @@ describe("TeamConfig ProfileInfo tests", () => {
};
};

it("does nothing if there are no layers that match the built layer path", async () => {
const profInfo = createNewProfInfo(teamProjDir);
await profInfo.readProfilesFromDisk({ homeDir: teamHomeProjDir });
(profInfo as any).mProfileSchemaCache = new Map();
(profInfo as any).mProfileSchemaCache.set("/some/nonexistent/layer/path:someUnregisteredProfType");
const writeFileSync = jest.spyOn(jsonfile, "writeFileSync");
writeFileSync.mockReset();
(profInfo as any).updateSchemaAtLayer("someUnregisteredProfType", {} as any);
expect(writeFileSync).not.toHaveBeenCalled();
});

// case 1: schema is the same as the cached one; do not write to disk
it("does not write schema to disk if it hasn't changed", async () => {
const blockMocks = getBlockMocks();
Expand Down
3 changes: 3 additions & 0 deletions packages/imperative/src/config/src/ProfileInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1331,6 +1331,9 @@ export class ProfileInfo {

const layerPath = cachedType != null ? cachedType[0].substring(0, cachedType[0].lastIndexOf(":")) : this.getTeamConfig().layerActive().path;
const layerToUpdate = this.getTeamConfig().mLayers.find((l) => l.path === layerPath);
if (layerToUpdate == null) {
return;
}
const cacheKey = `${layerPath}:${profileType}`;

const sameSchemaExists = versionChanged ? false :
Expand Down

0 comments on commit 5667624

Please sign in to comment.