21 lines
985 B
TypeScript
21 lines
985 B
TypeScript
import { strict as assert } from 'node:assert'
|
|
import { test } from 'node:test'
|
|
import { resolveContainerTerminal } from './containerTerminal'
|
|
|
|
const inspection = (running = true) => JSON.stringify([{
|
|
Id: 'container-id', State: { Running: running }, Mounts: [
|
|
{ Source: '/home/user/ws', Destination: '/workspace' },
|
|
{ Source: '/home/user/ws/module', Destination: '/module' }
|
|
]
|
|
}])
|
|
|
|
test('resolves module path from the most specific actual mount', () => {
|
|
assert.deepEqual(resolveContainerTerminal(inspection(), '/home/user/ws/module'), { id: 'container-id', cwd: '/module' })
|
|
assert.equal(resolveContainerTerminal(inspection(), '/home/user/ws/other').cwd, '/workspace/other')
|
|
})
|
|
|
|
test('rejects stopped containers and unrelated workspace paths', () => {
|
|
assert.throws(() => resolveContainerTerminal(inspection(false), '/home/user/ws/module'), /not running/)
|
|
assert.throws(() => resolveContainerTerminal(inspection(), '/home/user/ws-other/module'), /not mounted/)
|
|
})
|