Files
orca/src/shared/ssh-target-generation.test.ts
T

50 lines
1.4 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { describe, expect, it } from 'vitest'
import {
nextSshTargetGeneration,
resolveSshTargetGenerationHighWaterMark
} from './ssh-target-generation'
describe('resolveSshTargetGenerationHighWaterMark', () => {
it('never reissues a generation an automation already captured', () => {
// A rolled-back counter cannot reissue an automation’s captured generation.
const highWaterMark = resolveSshTargetGenerationHighWaterMark({
persistedCounter: 2,
targetGenerations: [1, 2],
capturedGenerations: [9]
})
expect(highWaterMark).toBe(9)
expect(nextSshTargetGeneration(highWaterMark)).toBe(10)
})
it('never reissues a generation a stored target already carries', () => {
expect(
resolveSshTargetGenerationHighWaterMark({
persistedCounter: 0,
targetGenerations: [7],
capturedGenerations: []
})
).toBe(7)
})
it('keeps the persisted counter when it leads', () => {
expect(
resolveSshTargetGenerationHighWaterMark({
persistedCounter: 12,
targetGenerations: [3],
capturedGenerations: [5]
})
).toBe(12)
})
it('ignores corrupt values on every input', () => {
expect(
resolveSshTargetGenerationHighWaterMark({
persistedCounter: Number.NaN,
targetGenerations: [undefined, -4, 2.5],
capturedGenerations: [null]
})
).toBe(0)
expect(nextSshTargetGeneration(0)).toBe(1)
})
})