Initial commit
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
import { tap, expect } from '@git.zone/tstest/tapbundle';
|
||||
import * as fs from 'node:fs/promises';
|
||||
import * as path from 'node:path';
|
||||
import { SambaClient, SambaServer } from '../ts/index.js';
|
||||
|
||||
tap.test('should serve and access a local SMB share', async () => {
|
||||
const sharePath = path.join(process.cwd(), '.nogit', `smartsamba-${Date.now()}`);
|
||||
await fs.mkdir(sharePath, { recursive: true });
|
||||
|
||||
const server = new SambaServer({
|
||||
host: '127.0.0.1',
|
||||
port: 0,
|
||||
users: [{ username: 'alice', password: 'secret' }],
|
||||
shares: [{ name: 'files', path: sharePath }],
|
||||
});
|
||||
|
||||
const started = await server.start();
|
||||
const client = new SambaClient({
|
||||
host: '127.0.0.1',
|
||||
port: started.port,
|
||||
auth: { username: 'alice', password: 'secret' },
|
||||
timeoutMs: 10000,
|
||||
});
|
||||
|
||||
try {
|
||||
await client.writeFile('files', 'hello.txt', 'hello samba');
|
||||
const content = await client.readFileAsString('files', 'hello.txt');
|
||||
expect(content).toEqual('hello samba');
|
||||
|
||||
const entries = await client.listDirectory('files');
|
||||
expect(entries.some((entry) => entry.name === 'hello.txt')).toBeTrue();
|
||||
|
||||
const info = await client.stat('files', 'hello.txt');
|
||||
expect(info.size).toEqual('hello samba'.length);
|
||||
expect(info.isDirectory).toBeFalse();
|
||||
|
||||
await client.createDirectory('files', 'nested');
|
||||
await client.rename('files', 'hello.txt', 'nested/renamed.txt');
|
||||
const renamed = await client.readFileAsString('files', 'nested/renamed.txt');
|
||||
expect(renamed).toEqual('hello samba');
|
||||
|
||||
await client.deleteFile('files', 'nested/renamed.txt');
|
||||
} finally {
|
||||
await client.stop();
|
||||
await server.stop();
|
||||
}
|
||||
});
|
||||
|
||||
export default tap.start();
|
||||
Reference in New Issue
Block a user