backend: Gitlab URL Reader to throw error when apiBaseUrl is missing

And add more tests for all other URL Readers
This commit is contained in:
Himanshu Mishra
2021-01-29 17:10:03 +01:00
parent ec02b0591d
commit 81f4b6330a
4 changed files with 45 additions and 0 deletions
@@ -242,5 +242,17 @@ describe('BitbucketUrlReader', () => {
expect(response.etag).toBe('12ab34cd56ef');
});
it('should throw error when apiBaseUrl is missing', () => {
expect(() => {
/* eslint-disable no-new */
new BitbucketUrlReader(
{
host: 'bitbucket.mycompany.net',
},
{ treeResponseFactory },
);
}).toThrowError('must configure an explicit apiBaseUrl');
});
});
});
@@ -376,5 +376,20 @@ describe('GithubUrlReader', () => {
};
await expect(fnGithub).rejects.toThrow(NotFoundError);
});
it('should throw error when apiBaseUrl is missing', () => {
expect(() => {
/* eslint-disable no-new */
new GithubUrlReader(
{
host: 'ghe.mycompany.net',
},
{
treeResponseFactory,
credentialsProvider: mockCredentialsProvider,
},
);
}).toThrowError('must configure an explicit apiBaseUrl');
});
});
});
@@ -379,5 +379,17 @@ describe('GitlabUrlReader', () => {
};
await expect(fnGithub).rejects.toThrow(NotFoundError);
});
it('should throw error when apiBaseUrl is missing', () => {
expect(() => {
/* eslint-disable no-new */
new GitlabUrlReader(
{
host: 'gitlab.mycompany.com',
},
{ treeResponseFactory },
);
}).toThrowError('must configure an explicit apiBaseUrl');
});
});
});
@@ -51,6 +51,12 @@ export class GitlabUrlReader implements UrlReader {
deps: { treeResponseFactory: ReadTreeResponseFactory },
) {
this.treeResponseFactory = deps.treeResponseFactory;
if (!config.apiBaseUrl) {
throw new Error(
`GitLab integration for '${config.host}' must configure an explicit apiBaseUrl`,
);
}
}
async read(url: string): Promise<Buffer> {