Skip to content

Commit

Permalink
fix(sfppackage): improve error message when repository URL is not par…
Browse files Browse the repository at this point in the history
…seable

This adds a skipped test that should be enabled after flxbl-io#137
  • Loading branch information
richard-giraud committed Nov 15, 2024
1 parent 357b118 commit 14ddb23
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 1 deletion.
19 changes: 18 additions & 1 deletion src/core/package/SfpPackageInquirer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,24 @@ export default class SfpPackageInquirer {
let remoteURL: gitUrlParse.GitUrl;

for (let sfpPackage of this.sfpPackages) {
let currentRemoteURL = gitUrlParse(sfpPackage.repository_url);
let currentRemoteURL: gitUrlParse.GitUrl;

const packageRemoteURL: string | undefined = sfpPackage.repository_url;
if (typeof packageRemoteURL === 'undefined') {
throw new Error(`Package '${sfpPackage.package_name}' does not have a repository URL`);
}

try {
currentRemoteURL = gitUrlParse(packageRemoteURL);
} catch (ex) {
if (ex instanceof Error && ex.message === 'URL parsing failed.') {
throw new Error(
`Invalid repository URL for package '${sfpPackage.package_name}': ${packageRemoteURL}`
);
} else {
throw ex;
}
}

if (remoteURL == null) {
remoteURL = currentRemoteURL;
Expand Down
46 changes: 46 additions & 0 deletions tests/core/package/SfpPackageInquirer.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { expect } from '@jest/globals';
import SfpPackage from '../../../lib/core/package/SfpPackage';
import SfpPackageInquirer from '../../../src/core/package/SfpPackageInquirer';

describe('validateArtifactsSourceRepository', () => {
describe('Given a bad repository URL, display', () => {
it('should accept a good repository SSH URL', async () => {
const repositoryUrl = '[email protected]:flxbl-io/sfp-test.git';

let sfpPackage: SfpPackage = new SfpPackage();
sfpPackage.package_name = 'testPackageName';
sfpPackage.repository_url = repositoryUrl;

let sfpPackageInquirer = new SfpPackageInquirer([sfpPackage]);
sfpPackageInquirer.validateArtifactsSourceRepository();
});

// TODO: re-enable once https://github.com/flxbl-io/sfp/issues/137 is fixed
it.skip.failing('should accept a good repository SSH URL with a URL-encoded space', async () => {
const repositoryUrl = '[email protected]:flxbl-io/sfp%20test.git';

let sfpPackage: SfpPackage = new SfpPackage();
sfpPackage.package_name = 'testPackageName';
sfpPackage.repository_url = repositoryUrl;

let sfpPackageInquirer = new SfpPackageInquirer([sfpPackage]);
sfpPackageInquirer.validateArtifactsSourceRepository();
});

it('should reject a bad repository SSH URL with a helpful error message', async () => {
const repositoryUrl = 'git';

const t = () => {
let sfpPackage: SfpPackage = new SfpPackage();
sfpPackage.package_name = 'testPackageName';
sfpPackage.repository_url = repositoryUrl;

let sfpPackageInquirer = new SfpPackageInquirer([sfpPackage]);
sfpPackageInquirer.validateArtifactsSourceRepository();
};

expect(t).toThrow(Error);
expect(t).toThrow("Invalid repository URL for package 'testPackageName': git");
});
});
});

0 comments on commit 14ddb23

Please sign in to comment.