From 0ba67aaf7aae71f980d80de9ed9a03d2d76fef76 Mon Sep 17 00:00:00 2001 From: boxofyellow <54955040+boxofyellow@users.noreply.github.com> Date: Thu, 25 Jan 2024 09:58:31 -0800 Subject: [PATCH] leave shared object unchanged --- __tests__/ghcr-client.test.ts | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/__tests__/ghcr-client.test.ts b/__tests__/ghcr-client.test.ts index d039fe8..6c01032 100644 --- a/__tests__/ghcr-client.test.ts +++ b/__tests__/ghcr-client.test.ts @@ -484,9 +484,13 @@ describe('publishOCIArtifact', () => { }) it('throws an error if one of the layers has the wrong media type', async () => { - const modifiedTestManifest = testManifest + const modifiedTestManifest = { ...testManifest } // This is _NOT_ a deep clone + modifiedTestManifest.layers = cloneLayers(modifiedTestManifest.layers) modifiedTestManifest.layers[0].mediaType = 'application/json' + // just checking to make sure we are not changing the shared object + expect(modifiedTestManifest.layers[0].mediaType).not.toEqual(testManifest.layers[0].mediaType) + await expect( publishOCIArtifact( token, @@ -496,7 +500,7 @@ describe('publishOCIArtifact', () => { semver, zipFile, tarFile, - testManifest + modifiedTestManifest ) ).rejects.toThrow('Unknown media type application/json') }) @@ -534,3 +538,9 @@ function validateRequestConfig(status: number, url: string, config: any): void { ) } } + +function cloneLayers(layers: ociContainer.Layer[]) : ociContainer.Layer[] { + const result : ociContainer.Layer[] = []; + layers.forEach(val => result.push({ ... val })) // this is _NOT_ a deep clone + return result +} \ No newline at end of file