mirror of
https://github.com/renovatebot/renovate.git
synced 2026-10-27 07:50:47 +00:00
c6578a476b
* support AWS S3 as a chart repository * support creds via hostRules * apply suggestions * fix(datasource/helm): classify s3 lookup errors * test: use await expect().resolves
80 lines
2.4 KiB
TypeScript
80 lines
2.4 KiB
TypeScript
import { getS3Client, parseS3Url } from './s3.ts';
|
|
import { parseUrl } from './url.ts';
|
|
|
|
describe('util/s3', () => {
|
|
afterEach(() => {
|
|
vi.resetModules();
|
|
});
|
|
|
|
it('parses S3 URLs', () => {
|
|
expect(parseS3Url('s3://bucket/key/path')).toEqual({
|
|
Bucket: 'bucket',
|
|
Key: 'key/path',
|
|
});
|
|
});
|
|
|
|
it('returns null for non-S3 URLs', () => {
|
|
expect(parseS3Url(parseUrl('http://example.com/key/path')!)).toBeNull();
|
|
});
|
|
|
|
it('returns null for invalid URLs', () => {
|
|
expect(parseS3Url('thisisnotaurl')).toBeNull();
|
|
});
|
|
|
|
it('returns a singleton S3 client instance', () => {
|
|
const client1 = getS3Client();
|
|
const client2 = getS3Client();
|
|
expect(client1).toBe(client2);
|
|
});
|
|
|
|
it('uses user-configured s3 values', async () => {
|
|
const s3 = await import('./s3.ts');
|
|
const globalConfig = await import('../config/global.ts');
|
|
globalConfig.GlobalConfig.set({
|
|
s3Endpoint: 'https://minio.domain.test',
|
|
s3PathStyle: true,
|
|
});
|
|
const client1 = s3.getS3Client();
|
|
const client2 = getS3Client();
|
|
expect(client1).not.toBe(client2);
|
|
await expect(client1.config.endpoint?.()).resolves.toStrictEqual({
|
|
hostname: 'minio.domain.test',
|
|
path: '/',
|
|
port: undefined,
|
|
protocol: 'https:',
|
|
query: undefined,
|
|
});
|
|
expect(client1.config.forcePathStyle).toBeTrue();
|
|
});
|
|
|
|
it('returns an uncached client when credentials are provided', async () => {
|
|
const credentials = {
|
|
accessKeyId: 'some-access-key',
|
|
secretAccessKey: 'some-secret-key',
|
|
sessionToken: 'some-session-token',
|
|
};
|
|
const client1 = getS3Client(undefined, undefined, credentials);
|
|
const client2 = getS3Client(undefined, undefined, credentials);
|
|
expect(client1).not.toBe(client2);
|
|
expect(client1).not.toBe(getS3Client());
|
|
await expect(client1.config.credentials()).resolves.toMatchObject(
|
|
credentials,
|
|
);
|
|
});
|
|
|
|
it('uses s3 values from globalConfig instead of GlobalConfig class', async () => {
|
|
const s3 = await import('./s3.ts');
|
|
const client1 = s3.getS3Client('https://minio.domain.test', true);
|
|
const client2 = getS3Client('https://minio.domain.test', true);
|
|
expect(client1).not.toBe(client2);
|
|
await expect(client1.config.endpoint?.()).resolves.toStrictEqual({
|
|
hostname: 'minio.domain.test',
|
|
path: '/',
|
|
port: undefined,
|
|
protocol: 'https:',
|
|
query: undefined,
|
|
});
|
|
expect(client1.config.forcePathStyle).toBeTrue();
|
|
});
|
|
});
|