Skip to content

Commit

Permalink
update test and some names for clarity
Browse files Browse the repository at this point in the history
  • Loading branch information
joshspicer authored Nov 6, 2023
1 parent c3178e5 commit 0ac3a9d
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 20 deletions.
6 changes: 3 additions & 3 deletions src/spec-node/collectionCommonUtils/publishCommandImpl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,13 @@ export async function doPublishCommand(params: CommonParams, version: string, oc
const { output } = params;

output.write(`Fetching published versions...`, LogLevel.Info);
const publishedVersions = await getPublishedTags(params, ociRef);
const publishedTags = await getPublishedTags(params, ociRef);

if (!publishedVersions) {
if (!publishedTags) {
return;
}

const semanticVersions: string[] | undefined = getSemanticVersions(version, publishedVersions, output);
const semanticVersions: string[] | undefined = getSemanticVersions(version, publishedTags, output);

if (!!semanticVersions) {
output.write(`Publishing versions: ${semanticVersions.toString()}...`, LogLevel.Info);
Expand Down
24 changes: 12 additions & 12 deletions src/test/container-features/containerFeaturesOCIPush.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export const output = makeLog(createPlainLog(text => process.stdout.write(text),
const testAssetsDir = `${__dirname}/assets`;

interface PublishResult {
publishedVersions: string[];
publishedTags: string[];
digest: string;
version: string;
publishedLegacyIds?: string[];
Expand Down Expand Up @@ -87,7 +87,7 @@ registry`;
const color = result['color'];
assert.isDefined(color);
assert.isDefined(color.digest);
assert.deepEqual(color.publishedVersions, [
assert.deepEqual(color.publishedTags, [
'1',
'1.0',
'1.0.0',
Expand All @@ -99,7 +99,7 @@ registry`;
const hello = result['hello'];
assert.isDefined(hello);
assert.isDefined(hello.digest);
assert.deepEqual(hello.publishedVersions, [
assert.deepEqual(hello.publishedTags, [
'1',
'1.0',
'1.0.0',
Expand All @@ -123,8 +123,8 @@ registry`;
assert.isTrue(success);
assert.isDefined(infoTagsResult);
const tags = JSON.parse(infoTagsResult.stdout);
const publishedVersions: string[] = tags['publishedVersions'];
assert.equal(publishedVersions.length, 1);
const publishedTags: string[] = tags['publishedTags'];
assert.equal(publishedTags.length, 4);

success = false; // Reset success flag.
try {
Expand Down Expand Up @@ -172,15 +172,15 @@ registry`;
assert.isObject(color);
// Check that the color object has no properties
assert.isUndefined(color.digest);
assert.isUndefined(color.publishedVersions);
assert.isUndefined(color.publishedTags);
assert.isUndefined(color.version);

// -- The breakfix version of hello was updated, so major and minor should be published again, too.
const hello = result['hello'];
assert.isDefined(hello);
assert.isDefined(hello.digest);
assert.isArray(hello.publishedVersions);
assert.deepEqual(hello.publishedVersions, [
assert.isArray(hello.publishedTags);
assert.deepEqual(hello.publishedTags, [
'1',
'1.0',
'1.0.1',
Expand Down Expand Up @@ -219,7 +219,7 @@ registry`;
const newColor = result['new-color'];
assert.isDefined(newColor);
assert.isDefined(newColor.digest);
assert.deepEqual(newColor.publishedVersions, [
assert.deepEqual(newColor.publishedTags, [
'1',
'1.0',
'1.0.1',
Expand All @@ -234,7 +234,7 @@ registry`;
const hello = result['hello'];
assert.isDefined(hello);
assert.isDefined(hello.digest);
assert.deepEqual(hello.publishedVersions, [
assert.deepEqual(hello.publishedTags, [
'1',
'1.0',
'1.0.0',
Expand Down Expand Up @@ -299,8 +299,8 @@ registry`;
assert.isTrue(success);
assert.isDefined(infoTagsResult);
const tags = JSON.parse(infoTagsResult.stdout);
const publishedVersions: string[] = tags['publishedVersions'];
assert.equal(publishedVersions.length, 1);
const publishedTags: string[] = tags['publishedTags'];
assert.equal(publishedTags.length, 1);
});
});

Expand Down
79 changes: 74 additions & 5 deletions src/test/container-features/featuresCLICommands.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -545,15 +545,15 @@ describe('test function getSermanticVersions', () => {
});
});

describe('test function getVersionsStrictSorted', async () => {
describe('test functions getVersionsStrictSorted and getPublishedTags', async () => {
it('should list published versions', async () => {
const resource = 'ghcr.io/devcontainers/features/node';
const featureRef = getRef(output, resource);
if (!featureRef) {
assert.fail('featureRef should not be undefined');
}
const versionsList = await getPublishedTags({ output, env: process.env }, featureRef) ?? [];
assert.includeMembers(versionsList, ['1', '1.0', '1.0.0']);
const publishedTags = await getPublishedTags({ output, env: process.env }, featureRef) ?? [];
assert.includeMembers(publishedTags, ['1', '1.0', '1.0.0', 'latest']);
});

it('should list published versions in an advanced case', async () => {
Expand All @@ -565,7 +565,7 @@ describe('test function getVersionsStrictSorted', async () => {
}
const versionsList = await getVersionsStrictSorted({ output, env: process.env }, ref) ?? [];
console.log(versionsList);
const expected = [
const expectedVersions = [
'0.0.0',
'0.0.1',
'0.0.2',
Expand Down Expand Up @@ -603,7 +603,76 @@ describe('test function getVersionsStrictSorted', async () => {
'2.11.0',
'2.11.1',
];
assert.deepStrictEqual(versionsList, expected);
// Order matters here
assert.deepStrictEqual(versionsList, expectedVersions);


const publishedTags = await getPublishedTags({ output, env: process.env }, ref) ?? [];
const expectedTags = [
'latest',
'0',
'1',
'2',
'0.0',
'0.0.0',
'0.0.1',
'0.0.2',
'0.1',
'0.1.0',
'0.2',
'0.2.0',
'0.3',
'0.3.0',
'0.3.1',
'0.3.10',
'0.3.11',
'0.3.12',
'0.3.2',
'0.3.3',
'0.3.4',
'0.3.5',
'0.3.6',
'0.3.7',
'0.3.8',
'0.3.9',
'0.4',
'0.4.0',
'1.0',
'1.0.0',
'1.1',
'1.1.0',
'2.0',
'2.0.0',
'2.1',
'2.1.0',
'2.10',
'2.10.0',
'2.10.1',
'2.11',
'2.11.0',
'2.11.1',
'2.2',
'2.2.0',
'2.2.1',
'2.3',
'2.3.0',
'2.4',
'2.4.0',
'2.5',
'2.5.0',
'2.6',
'2.6.0',
'2.7',
'2.7.0',
'2.8',
'2.8.0',
'2.9',
'2.9.0'
];
// Order is not guaranteed here (up to however the registry returns the tags)
assert.strictEqual(publishedTags.length, expectedTags.length);
assert.includeMembers(publishedTags, expectedTags);

});

});

0 comments on commit 0ac3a9d

Please sign in to comment.