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

feat: added keploy version mapping #89

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions keploy-version.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"1.0.20": "v2.3.0-beta41",
"1.0.25": "v2.3.0-beta41"
}
25 changes: 3 additions & 22 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "keployio",
"displayName": "Keploy",
"description": "Streamline testing with the power of Keploy, directly in your favorite IDE.",
"version": "1.0.20",
"version": "1.0.25",
"publisher": "Keploy",
"icon": "media/logo.png",
"pricing": "Free",
Expand Down Expand Up @@ -57,7 +57,7 @@
},
"submenus": [
{
"icon": "$(account)",
"icon": "$(account)",
"label": "Sign In Options",
"id": "sign_in_submenu"
}
Expand All @@ -69,14 +69,6 @@
"when": "view == Keploy-Sidebar && keploy.signedIn != true",
"group": "navigation"
},
{
"command": "keploy.updateKeploy",
"when": "view == Keploy-Sidebar"
},
{
"command": "keploy.getLatestVersion",
"when": "view == Keploy-Sidebar"
},
{
"command": "keploy.KeployVersion",
"when": "view == Keploy-Sidebar"
Expand Down Expand Up @@ -107,7 +99,6 @@
{
"command": "keploy.SignInWithMicrosoft",
"title": "Sign In with Microsoft"

}
]
},
Expand All @@ -133,21 +124,11 @@
"command": "keploy.utg",
"title": "Keploy: Unit Test Generation"
},
{
"command": "keploy.updateKeploy",
"title": "Update your Keploy",
"when": "view == Keploy-Sidebar"
},
{
"command": "keploy.KeployVersion",
"title": "View Your Keploy Version",
"when": "view == Keploy-Sidebar"
},
{
"command": "keploy.getLatestVersion",
"title": "Get Latest Version",
"when": "view == Keploy-Sidebar"
},
{
"command": "keploy.viewChangeLog",
"title": "View Change Log",
Expand Down Expand Up @@ -216,4 +197,4 @@
"walk": "^2.3.15",
"yaml": "^2.4.2"
}
}
}
19 changes: 17 additions & 2 deletions src/OneClickInstall.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,26 @@
import { exec } from 'child_process';
import { getKeployVersion , getCurrentKeployVersion } from './version';

export default function executeKeployOneClickCommand(): void {
export default async function executeKeployOneClickCommand(): Promise<void> {
// Check if Keploy is installed by trying to run the `keploy` command
const checkKeployExistsCommand = `keploy`;
const keployVersion = await getKeployVersion();
const currentKeployVersion = await getCurrentKeployVersion();

// Check the if keploy is installed and have the same version or not
if(currentKeployVersion !== "" && keployVersion !== currentKeployVersion){
const removeKeployCommand = `rm -rf ~/.keploy`;
exec(removeKeployCommand, (error, stdout, stderr) => {
if (error) {
console.error(`Error during removal: ${error.message}`);
return;
}
});
}

// The command to download and install Keploy
const installationCommand = `curl --silent -L https://keploy.io/install.sh -o /tmp/install.sh && chmod +x /tmp/install.sh && /tmp/install.sh -noRoot`;
const installationCommand = `curl --silent -L https://keploy.io/install.sh -o /tmp/install.sh && chmod +x /tmp/install.sh && /tmp/install.sh -v ${keployVersion} -noRoot`;

exec(checkKeployExistsCommand, (error, stdout, stderr) => {
if (error) {
// Execute the installation command
Expand Down
15 changes: 10 additions & 5 deletions src/test/suites/oneclickinstall.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import * as child_process from 'child_process';
import assert from 'assert';
import executeKeployOneClickCommand from '../../OneClickInstall';
import { suite, test, setup, teardown } from 'mocha';
import * as version from "../../version"

suite('executeKeployOneClickCommand', () => {
let execStub: sinon.SinonStub;
Expand All @@ -15,24 +16,28 @@ suite('executeKeployOneClickCommand', () => {
sinon.restore();
});

test('should install Keploy if not already installed', () => {
test('should install Keploy if not already installed', async () => {
const checkKeployExistsCommand = `keploy`;
const installationCommand = `curl --silent -L https://keploy.io/install.sh -o /tmp/install.sh && chmod +x /tmp/install.sh && /tmp/install.sh -noRoot`;
const installationCommand = `curl --silent -L https://keploy.io/install.sh -o /tmp/install.sh && chmod +x /tmp/install.sh && /tmp/install.sh -v v2.3.0-beta25 -noRoot`;
sinon.stub(version, 'getKeployVersion').resolves('v2.3.0-beta25');
sinon.stub(version, 'getCurrentKeployVersion').resolves('');

// Simulate Keploy not being installed
execStub.withArgs(checkKeployExistsCommand).callsArgWith(1, new Error('command not found'), '', '');

executeKeployOneClickCommand();
await executeKeployOneClickCommand();

assert(execStub.calledWith(installationCommand));
});

test('should not install Keploy if already installed', () => {
test('should not install Keploy if already installed', async () => {
const checkKeployExistsCommand = `keploy`;
sinon.stub(version, 'getKeployVersion').resolves('v2.3.0-beta25');
sinon.stub(version, 'getCurrentKeployVersion').resolves('');

execStub.withArgs(checkKeployExistsCommand).callsArgWith(1, null, 'Keploy version 1.0.0', '');

executeKeployOneClickCommand();
await executeKeployOneClickCommand();

assert(execStub.calledWith(checkKeployExistsCommand));
assert(execStub.calledOnce);
Expand Down
11 changes: 7 additions & 4 deletions src/test/suites/updateKeploy.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,19 @@ suite("updateKeploy Test", function () {
execStub.restore();
});

afterEach(() => {
sinon.restore();
});

test('downloading and updating binary should execute correct command with exec', async () => {
sinon.stub(process, 'platform').value('linux');
sinon.stub(version, 'getKeployVersion').resolves('v2.3.0-beta25');

const curlCmd = `curl --silent -L https://keploy.io/install.sh -o /tmp/install.sh && chmod +x /tmp/install.sh && /tmp/install.sh -noRoot`;
const curlCmd = `curl --silent -L https://keploy.io/install.sh -o /tmp/install.sh && chmod +x /tmp/install.sh && /tmp/install.sh -v v2.3.0-beta25 -noRoot`;

const promise = updateKeploy.downloadAndInstallKeployBinary();
await updateKeploy.downloadAndInstallKeployBinary();

assert.strictEqual(execStub.calledOnceWith(curlCmd), true);

await promise;
});

test('Download from docker should create a terminal and run the curl command on non-Windows platform', async () => {
Expand Down
16 changes: 8 additions & 8 deletions src/test/suites/version.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,16 @@ suite("Version tests", () => {
sinon.restore()
})

test("getKeployVersion should be calling correct api", async () => {
let api = "https://api.github.com/repos/keploy/keploy/releases/latest"
const mockResponse = {tag_name : "v2.3.0-beta25"};
fetchStub.resolves(new Response(JSON.stringify(mockResponse), { status: 200 }))
// test("getKeployVersion should be calling correct api", async () => {
// let api = "https://api.github.com/repos/keploy/keploy/releases/latest"
// const mockResponse = {tag_name : "v2.3.0-beta25"};
// fetchStub.resolves(new Response(JSON.stringify(mockResponse), { status: 200 }))

await getKeployVersion();
// await getKeployVersion();

assert(fetchStub.calledOnce)
assert(fetchStub.calledWith(api))
})
// assert(fetchStub.calledOnce)
// assert(fetchStub.calledWith(api))
// })

test("getCurrentKeployVersion should return version by executing keploy command", async () => {

Expand Down
6 changes: 4 additions & 2 deletions src/updateKeploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,12 @@ export async function downloadAndUpdateDocker(): Promise<void> {

export async function downloadAndInstallKeployBinary(): Promise<void> {
console.log('Downloading and installing Keploy binary...');
return new Promise<void>((resolve, reject) => {
return new Promise<void>(async (resolve, reject) => {

try {
const curlCmd = `curl --silent -L https://keploy.io/install.sh -o /tmp/install.sh && chmod +x /tmp/install.sh && /tmp/install.sh -noRoot`;
const keployVersion = await getKeployVersion();

const curlCmd = `curl --silent -L https://keploy.io/install.sh -o /tmp/install.sh && chmod +x /tmp/install.sh && /tmp/install.sh -v ${keployVersion} -noRoot`;

child_process.exec(curlCmd, (error, stdout, stderr) => {
if (error) {
Expand Down
22 changes: 12 additions & 10 deletions src/version.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@

import { execShell } from './execShell';
import * as path from 'path';
import * as fs from 'fs';
export async function getKeployVersion() {
// GitHub repository details
const repoOwner = "keploy";
const repoName = "keploy";
const packagePath = path.resolve(__dirname, '../package.json');
const packageContent = fs.readFileSync(packagePath, 'utf-8');
const packageData = JSON.parse(packageContent);

const apiURL = `https://api.github.com/repos/${repoOwner}/${repoName}/releases/latest`;
const keployVersionJsonPath = path.resolve(__dirname, '../keploy-version.json');
const keployVersionJsonContent = fs.readFileSync(keployVersionJsonPath, 'utf-8');
const keployVersionJson = JSON.parse(keployVersionJsonContent);

// Get the latest release
const response = await fetch(apiURL);
const data: any = await response.json();
const latestVersion = data.tag_name;
return latestVersion;
const keployVersion = keployVersionJson[`${packageData.version}`];

return keployVersion;
}

export async function getCurrentKeployVersion() {
Expand All @@ -24,7 +26,7 @@ export async function getCurrentKeployVersion() {
output = await execShell('/usr/local/bin/keploybin --version');
}catch(error){
console.log("Error Fetching version With Absolute path " + error);
throw error;
return '';
}
}
console.log('output:', output);
Expand Down
3 changes: 2 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
"rootDir": "src",
"esModuleInterop": true,
"skipLibCheck": true,
"strict": true /* enable all strict type-checking options */
"strict": true, /* enable all strict type-checking options */
"resolveJsonModule": true
/* Additional Checks */
// "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */
// "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */
Expand Down
Loading