Skip to content

Commit

Permalink
Add test case for the validate command
Browse files Browse the repository at this point in the history
  • Loading branch information
AayushSaini101 committed Jan 4, 2025
1 parent ea91e0a commit 60390de
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
8 changes: 5 additions & 3 deletions src/core/models/SpecificationFile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,19 +106,21 @@ export class Specification {
if (proxyUrl) {
try {
new URL(proxyUrl);
const proxyAgent = new HttpsProxyAgent(proxyUrl,);
const proxyAgent = new HttpsProxyAgent(proxyUrl);
fetchOptions.agent = proxyAgent;
response = await fetch(targetUrl,fetchOptions);
} catch (error) {
throw new Error(`Invalid proxy URL: ${proxyUrl}`);
}
}

// Fetch the target URL
response = await fetch(targetUrl, fetchOptions);
response = await fetch(targetUrl);
if (!response.ok) {
// console.log(response+" sdf")
throw new ErrorLoadingSpec('url', targetUrl);
}
} catch (error) {
console.log(error);
throw new ErrorLoadingSpec('url', targetUrl);
}

Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/newtemplate/__transpiled/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions test/integration/validate.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,15 @@ describe('validate', () => {
expect(ctx.stderr).to.equal('');
done();
});
test
.stderr()
.stdout()
.command(['validate', 'http://localhost:8080/dummySpec.yml --proxyHost=host --proxyPort=8080'])
.it('works when url is passed with proxyHost and proxyPort with invalid host ', (ctx, done) => {
expect(ctx.stdout).to.contain('');
expect(ctx.stderr).to.equal('error loading AsyncAPI document from url: Failed to download http://localhost:8080/dummySpec.yml --proxyHost=host --proxyPort=8080.\n');
done();
});

test
.stderr()
Expand Down

0 comments on commit 60390de

Please sign in to comment.