Test DNS alias compatibility and collisions

This commit is contained in:
Kasra Bigdeli
2026-07-18 23:19:12 -07:00
parent 846d1d43bd
commit d1f06c1398
+67
View File
@@ -3,6 +3,10 @@ import AppsDataStore, {
isNameAllowed,
} from '../src/datastore/AppsDataStore'
import { runDataStoreMigrations } from '../src/datastore/DataStore'
import {
getLegacyServiceDnsAlias,
getServiceNetworkAttachments,
} from '../src/docker/DockerApi'
import ServiceManager from '../src/user/ServiceManager'
function createConfigStore(initialData: { [key: string]: any }) {
@@ -88,6 +92,69 @@ describe('service and volume naming migration', () => {
expect(failedVolumes).toEqual(['data'])
})
test('adds the legacy DNS alias to every network for a new app', () => {
const alias = getLegacyServiceDnsAlias(
'paperless-db',
'captain',
false
)
expect(
getServiceNetworkAttachments(
['captain-overlay-network', 'private-network'],
alias
)
).toEqual([
{
Target: 'captain-overlay-network',
Aliases: ['srv-captain--paperless-db'],
},
{
Target: 'private-network',
Aliases: ['srv-captain--paperless-db'],
},
])
})
test('does not add a redundant DNS alias to legacy apps', () => {
const alias = getLegacyServiceDnsAlias(
'srv-captain--paperless-db',
'captain',
true
)
expect(
getServiceNetworkAttachments(
['captain-overlay-network'],
alias
)
).toEqual([
{
Target: 'captain-overlay-network',
},
])
})
test('rejects a legacy DNS alias that conflicts with an orphaned service', async () => {
const serviceManager = Object.create(
ServiceManager.prototype
) as ServiceManager
;(serviceManager as any).dataStore = {
getAppsDataStore: () => ({
getServiceName: () => 'srv-captain--paperless-db',
}),
}
;(serviceManager as any).dockerApi = {
isServiceRunningByName: jest.fn().mockResolvedValue(true),
}
await expect(
serviceManager.ensureLegacyServiceNameAvailable('paperless-db')
).rejects.toThrow(
'A Docker service named srv-captain--paperless-db already exists'
)
})
test('deletes both physical volumes when neither remains in use', async () => {
const appsDataStore = new AppsDataStore(
createConfigStore({}),