Skip to content
This repository was archived by the owner on Jul 8, 2025. It is now read-only.

Commit 5bc4fed

Browse files
committed
test changing auth file for skopeo
1 parent b769241 commit 5bc4fed

File tree

2 files changed

+22
-41
lines changed

2 files changed

+22
-41
lines changed

src/imageAnalysis/collector.ts

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@ export interface IImage {
2424
*/
2525
export class Image implements IImage {
2626
public platform: string;
27-
27+
2828
constructor(
2929
public name: IPositionedString,
3030
public line: string
31-
) {}
31+
) { }
3232
}
3333

3434
/**
@@ -66,9 +66,9 @@ export class ImageMap {
6666
parsedImageRef = parseImageRef(image.name.value);
6767
}
6868
if (this.mapper.has(parsedImageRef.getPackageURL().toString())) {
69-
this.mapper.get(parsedImageRef.getPackageURL().toString()).push(image);
69+
this.mapper.get(parsedImageRef.getPackageURL().toString()).push(image);
7070
} else {
71-
this.mapper.set(parsedImageRef.getPackageURL().toString(), [image]);
71+
this.mapper.set(parsedImageRef.getPackageURL().toString(), [image]);
7272
}
7373
});
7474
}
@@ -80,18 +80,16 @@ export class ImageMap {
8080
*/
8181
public get(key: string): IImage[] {
8282
const images: IImage[] = [];
83-
/* istanbul ignore else */
8483
if (this.mapper.has(key)) {
85-
images.push(...this.mapper.get(key));
84+
images.push(...this.mapper.get(key));
8685
}
8786

8887
// Check if the key includes ":latest"
8988
if (key.includes(':latest')) {
90-
const keyWithoutLatest = key.replace(':latest', '');
91-
/* istanbul ignore else */
92-
if (this.mapper.has(keyWithoutLatest)) {
93-
images.push(...this.mapper.get(keyWithoutLatest));
94-
}
89+
const keyWithoutLatest = key.replace(':latest', '');
90+
if (this.mapper.has(keyWithoutLatest)) {
91+
images.push(...this.mapper.get(keyWithoutLatest));
92+
}
9593
}
9694

9795
return images;
@@ -103,13 +101,13 @@ export class ImageMap {
103101
* @param img - The image object image position information.
104102
* @returns The range within the image document that represents the image.
105103
*/
106-
export function getRange (img: IImage): Range {
104+
export function getRange(img: IImage): Range {
107105
const pos: IPosition = img.name.position;
108106
const length = img.line.length;
109107

110108
return {
111109
start: {
112-
line: pos.line - 1,
110+
line: pos.line - 1,
113111
character: pos.column
114112
},
115113
end: {

test/imageAnalysis/collector.test.ts

Lines changed: 11 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,10 @@ import { Image, ImageMap, getRange } from '../../src/imageAnalysis/collector';
66

77
describe('Image Analysis Collector tests', () => {
88

9-
// Mock image collection
10-
let reqImages: Image[] = [
11-
new Image ({ value: 'alpine', position: { line: 1, column: 0 } }, 'FROM --platform=linux/amd64 alpine as a'),
12-
new Image ({ value: 'alpine:latest', position: { line: 2, column: 0 } }, 'FROM --platform=linux/amd64 alpine:latest AS a'),
9+
// Mock image collection, we can't test unpinned images here as they will change over time, resulting in tests that always need updating.
10+
const reqImages: Image[] = [
11+
new Image ({ value: 'alpine:3.21.3', position: { line: 2, column: 0 } }, 'FROM --platform=linux/amd64 alpine:3.21.3 AS a'),
1312
new Image ({ value: 'alpine@sha256:c5b1261d6d3e43071626931fc004f70149baeba2c8ec672bd4f27761f8e1ad6b', position: { line: 3, column: 0 } }, 'FROM --platform=linux/amd64 alpine@sha256:c5b1261d6d3e43071626931fc004f70149baeba2c8ec672bd4f27761f8e1ad6b As a'),
14-
new Image ({ value: 'alpine', position: { line: 4, column: 0 } }, 'FROM --platform=linux/amd64 alpine as a'),
1513
];
1614
reqImages.forEach(image => image.platform = 'linux/amd64');
1715

@@ -20,9 +18,8 @@ describe('Image Analysis Collector tests', () => {
2018
const imageMap = new ImageMap(reqImages);
2119

2220
expect(Object.fromEntries(imageMap.mapper)).to.eql({
23-
'alpine': [reqImages[0], reqImages[3]],
24-
'alpine:latest': [reqImages[1]],
25-
'alpine@sha256:c5b1261d6d3e43071626931fc004f70149baeba2c8ec672bd4f27761f8e1ad6b': [reqImages[2]]
21+
'pkg:oci/alpine@sha256:1c4eef651f65e2f7daee7ee785882ac164b02b78fb74503052a26dc061c90474?arch=amd64&os=linux&tag=3.21.3': [reqImages[0]],
22+
'pkg:oci/alpine@sha256:c5b1261d6d3e43071626931fc004f70149baeba2c8ec672bd4f27761f8e1ad6b?arch=amd64&os=linux': [reqImages[1]]
2623
});
2724
});
2825

@@ -37,39 +34,25 @@ describe('Image Analysis Collector tests', () => {
3734

3835
const imageMap = new ImageMap(reqImages);
3936

40-
// The image names from the response always iclude 'latest' tag if no tag nor digest is provided
41-
expect(JSON.stringify(imageMap.get('alpine:latest'))).to.eq(JSON.stringify([reqImages[1], reqImages[0], reqImages[3]]));
42-
expect(JSON.stringify(imageMap.get('alpine@sha256:c5b1261d6d3e43071626931fc004f70149baeba2c8ec672bd4f27761f8e1ad6b'))).to.eq(JSON.stringify([reqImages[2]]));
37+
expect(JSON.stringify(imageMap.get('pkg:oci/alpine@sha256:c5b1261d6d3e43071626931fc004f70149baeba2c8ec672bd4f27761f8e1ad6b?arch=amd64&os=linux'))).to.eq(JSON.stringify([reqImages[1]]));
4338
});
4439

4540
it('should return image range', async () => {
46-
4741
expect(getRange(reqImages[0])).to.eql(
48-
{
49-
start: { line: 0, character: 0 },
50-
end: { line: 0, character: 39 }
51-
}
52-
);
53-
54-
expect(getRange(reqImages[1])).to.eql(
5542
{
5643
start: { line: 1, character: 0 },
5744
end: { line: 1, character: 46 }
5845
}
5946
);
6047

61-
expect(getRange(reqImages[2])).to.eql(
48+
expect(getRange(reqImages[1])).to.eql(
6249
{
6350
start: { line: 2, character: 0 },
6451
end: { line: 2, character: 111 }
6552
}
6653
);
67-
68-
expect(getRange(reqImages[3])).to.eql(
69-
{
70-
start: { line: 3, character: 0 },
71-
end: { line: 3, character: 39 }
72-
}
73-
);
7454
});
75-
})
55+
}).beforeAll(() => {
56+
// https://github.com/containers/skopeo/issues/1654
57+
process.env['EXHORT_SKOPEO_CONFIG_PATH'] = './auth.json';
58+
});

0 commit comments

Comments
 (0)