import { describe, it, expect } from 'vitest';
import { backupInternals } from './run.js';

describe('backup internals', () => {
  it('builds minio host URL with protocol and encoded credentials', () => {
    const host = backupInternals.buildMinioHost({
      endpoint: 'localhost:9000',
      accessKey: 'minio-admin',
      secretKey: 's3cr3t/with:chars',
      secure: false,
    });

    expect(host).toBe('http://minio-admin:s3cr3t%2Fwith%3Achars@localhost:9000');
  });

  it('builds object key from prefix and file name', () => {
    expect(backupInternals.buildObjectKey('flynn/daily', 'a.tar.gz')).toBe('flynn/daily/a.tar.gz');
    expect(backupInternals.buildObjectKey('/flynn/daily/', 'a.tar.gz')).toBe('flynn/daily/a.tar.gz');
    expect(backupInternals.buildObjectKey('', 'a.tar.gz')).toBe('a.tar.gz');
  });
});
