Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pipeline versioning tests #2028

Merged
merged 15 commits into from
Nov 14, 2024
4 changes: 2 additions & 2 deletions core/api-server/lib/service/pipeline-versions.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class PipelineVersions {
}

async getVersions(options) {
validator.pipelines.validatePipelineName(options);
validator.pipelines.validatePipelineName(options.name);
return versioning.getVersions(options, true);
}

Expand All @@ -23,7 +23,7 @@ class PipelineVersions {
if (!pipeline) {
throw new ResourceNotFoundError('pipeline', name);
}
const pipelineVersion = await versioning.getVersion({ version });
const pipelineVersion = await versioning.getVersion({ version }, true);
if (!pipelineVersion) {
throw new ResourceNotFoundError('version', version);
}
Expand Down
6 changes: 3 additions & 3 deletions core/api-server/lib/service/pipelines.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ const versionsService = require('./pipeline-versions');
class PipelineService {
async updatePipeline(options) {
validator.pipelines.validateUpdatePipeline(options);
const oldPipeLine = await this.getPipeline(options);
await validator.algorithms.validateAlgorithmExists(options);
validator.gateways.validateGatewayNodes(options.nodes);
const oldPipeLine = await this.getPipeline(options);
const newPipeline = {
modified: Date.now(),
...options,
Expand All @@ -26,7 +26,7 @@ class PipelineService {
newPipeline.version = newVersion;
}
await stateManager.replacePipeline(newPipeline);
return options;
return newPipeline;
}

async deletePipeline(options) {
Expand Down Expand Up @@ -244,7 +244,7 @@ class PipelineService {
const version = await this._versioning(true, newPipeline);
newPipeline.version = version;
await stateManager.insertPipeline(newPipeline);
return options;
return newPipeline;
}

_comparePipelines(oldPipeline, newPipeline) {
Expand Down
2 changes: 1 addition & 1 deletion core/api-server/lib/service/versioning.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class Versioning {
const extractedObject = isPipeline ? object.pipeline : object.algorithm;
const { name } = extractedObject;
const version = uid({ length: SETTINGS.VERSION_LENGTH });
const latestSemver = await this.getLatestSemver({ name });
const latestSemver = await this.getLatestSemver({ name }, isPipeline);
const semver = this.incSemver(latestSemver);
const newVersion = {
version,
Expand Down
4 changes: 4 additions & 0 deletions core/api-server/tests/exec-streaming.js
Original file line number Diff line number Diff line change
Expand Up @@ -850,6 +850,10 @@ describe('Streaming', () => {
};
const response = await request(options);
expect(response.response.statusCode).to.equal(HttpStatus.StatusCodes.CREATED);
expect(response.body).to.have.property('modified');
expect(response.body).to.have.property('version');
delete response.body.version;
delete response.body.modified;
expect(response.body).to.deep.equal(pipeline);
});
});
Expand Down
8 changes: 8 additions & 0 deletions core/api-server/tests/pipelines-store.js
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,10 @@ describe('Store/Pipelines', () => {
};
const response = await request(options);
expect(response.response.statusCode).to.equal(StatusCodes.CREATED);
expect(response.body).to.have.property('modified');
expect(response.body).to.have.property('version');
delete response.body.version;
delete response.body.modified;
expect(response.body).to.eql(pipeline);
const storedPipeline = await request({
uri: restPath + '/' + pipeline.name,
Expand Down Expand Up @@ -739,6 +743,10 @@ describe('Store/Pipelines', () => {
body: pipeline
};
const response = await request(options);
expect(response.body).to.have.property('modified');
expect(response.body).to.have.property('version');
delete response.body.version;
delete response.body.modified;
expect(response.body).to.deep.equal(pipeline);
});
it('should throw validation error if algorithmName not exists', async () => {
Expand Down
87 changes: 87 additions & 0 deletions core/api-server/tests/pipelines-versions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
const { expect } = require('chai');
const clone = require('clone');
const { uid: uuid } = require('@hkube/uid');
const { pipelines } = require('./mocks');
const { request } = require('./utils');
const stateManager = require('../lib/state/state-manager');
let restUrl, restPath;


describe('Versions/Pipelines', () => {
const pipeline = clone(pipelines[0]);

const addPipeline = async (pipeline) => {
const name = `pipe-test-${uuid()}`;
await stateManager.deletePipeline({ name, keepOldVersions: false })
const addRequest = { uri: `${restUrl}/store/pipelines`, method: 'POST', body: pipeline };
pipeline.name = name;
const res = await request(addRequest);
return { name, version: res.body.version };
}

const updatePipeline = async (pipeline) => {
const updateRequest = { uri: `${restUrl}/store/pipelines`, method: 'PUT', body: pipeline };
const res = await request(updateRequest);
return res.body.version;
}

const getAllVersions = async (name) => {
const versionReq = { uri: `${restPath}/${name}`, method: 'GET' };
const res = await request(versionReq);
return res.body;
}

const getSpecificVersion = async (name, version) => {
const versionReq = { uri: `${restPath}/${name}/${version}`, method: 'GET' };
const res = await request(versionReq);
return res.body.version;
}

before(() => {
restUrl = global.testParams.restUrl;
restPath = `${restUrl}/versions/pipelines`;
});

describe('get', () => {
it('should succeed to get list of the new pipeline version', async () => {
const { name } = await addPipeline(pipeline);
const versionsList = await getAllVersions(name);
expect(versionsList).to.have.lengthOf(1);
});

it('should succeed to get version', async () => {
const { name, version } = await addPipeline(pipeline);
const specificVersion = await getSpecificVersion(name, version);
expect(specificVersion).to.eql(version);
});

it.only('should succeed to get versions and change version to latest', async () => {
const { name, version: oldVersion } = await addPipeline(pipeline);
const pipeline2 = clone(pipeline);
pipeline2.options.ttl = 6666;
const newVersion = await updatePipeline(pipeline2);
const versionsList = await getAllVersions(name)
const semver = versionsList.map((v) => v.semver);
expect(versionsList).to.have.lengthOf(2);
expect(semver).to.eql(['1.0.1', '1.0.0']);
expect(oldVersion).to.be.not.equal(newVersion);
expect(newVersion).to.be.equal(versionsList[0].version);
});
});

describe('versions when pipeline is deleted', () => {
it('should return empty list after pipeline deleted', async () => {
const { name } = await addPipeline(pipeline);
await stateManager.deletePipeline({ name, keepOldVersions: false });
const versionsList = await getAllVersions(name);
expect(versionsList).to.have.lengthOf(0);
});

it('should return the versions of the deleted pipeline', async () => {
const { name } = await addPipeline(pipeline);
await stateManager.deletePipeline({ name, keepOldVersions: true });
const versionsList = await getAllVersions(name);
expect(versionsList).to.have.lengthOf(1);
});
});
});
Loading