1
0
Fork 0
mirror of https://github.com/portainer/portainer.git synced 2025-07-20 22:09:41 +02:00

feat(podman): support add podman envs in the wizard [r8s-20] (#12056)
Some checks failed
ci / build_images (map[arch:amd64 platform:linux version:]) (push) Has been cancelled
ci / build_images (map[arch:amd64 platform:windows version:1809]) (push) Has been cancelled
ci / build_images (map[arch:amd64 platform:windows version:ltsc2022]) (push) Has been cancelled
ci / build_images (map[arch:arm platform:linux version:]) (push) Has been cancelled
ci / build_images (map[arch:arm64 platform:linux version:]) (push) Has been cancelled
ci / build_images (map[arch:ppc64le platform:linux version:]) (push) Has been cancelled
/ triage (push) Has been cancelled
Lint / Run linters (push) Has been cancelled
Test / test-client (push) Has been cancelled
Test / test-server (map[arch:amd64 platform:linux]) (push) Has been cancelled
Test / test-server (map[arch:amd64 platform:windows version:1809]) (push) Has been cancelled
Test / test-server (map[arch:amd64 platform:windows version:ltsc2022]) (push) Has been cancelled
Test / test-server (map[arch:arm64 platform:linux]) (push) Has been cancelled
ci / build_manifests (push) Has been cancelled

This commit is contained in:
Ali 2024-09-25 11:55:07 +12:00 committed by GitHub
parent db616bc8a5
commit 32e94d4e4e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
108 changed files with 1921 additions and 272 deletions

View file

@ -0,0 +1,147 @@
import { describe, it, expect } from 'vitest';
import { DockerNetwork } from '@/react/docker/networks/types';
import { ContainerListViewModel } from '../../types';
import { ContainerDetailsJSON } from '../../queries/useContainer';
import { getDefaultViewModel, getNetworkMode } from './toViewModel';
describe('getDefaultViewModel', () => {
it('should return the correct default view model for Windows', () => {
const result = getDefaultViewModel(true);
expect(result).toEqual({
networkMode: 'nat',
hostname: '',
domain: '',
macAddress: '',
ipv4Address: '',
ipv6Address: '',
primaryDns: '',
secondaryDns: '',
hostsFileEntries: [],
container: '',
});
});
it('should return the correct default view model for Podman', () => {
const result = getDefaultViewModel(false, true);
expect(result).toEqual({
networkMode: 'podman',
hostname: '',
domain: '',
macAddress: '',
ipv4Address: '',
ipv6Address: '',
primaryDns: '',
secondaryDns: '',
hostsFileEntries: [],
container: '',
});
});
it('should return the correct default view model for Linux Docker', () => {
const result = getDefaultViewModel(false);
expect(result).toEqual({
networkMode: 'bridge',
hostname: '',
domain: '',
macAddress: '',
ipv4Address: '',
ipv6Address: '',
primaryDns: '',
secondaryDns: '',
hostsFileEntries: [],
container: '',
});
});
});
describe('getNetworkMode', () => {
const mockNetworks: Array<DockerNetwork> = [
{
Name: 'bridge',
Id: 'bridge-id',
Driver: 'bridge',
Scope: 'local',
Attachable: false,
Internal: false,
IPAM: { Config: [], Driver: '', Options: {} },
Options: {},
Containers: {},
},
{
Name: 'host',
Id: 'host-id',
Driver: 'host',
Scope: 'local',
Attachable: false,
Internal: false,
IPAM: { Config: [], Driver: '', Options: {} },
Options: {},
Containers: {},
},
{
Name: 'custom',
Id: 'custom-id',
Driver: 'bridge',
Scope: 'local',
Attachable: true,
Internal: false,
IPAM: { Config: [], Driver: '', Options: {} },
Options: {},
Containers: {},
},
];
const mockRunningContainers: Array<ContainerListViewModel> = [
{
Id: 'container-1',
Names: ['container-1-name'],
} as ContainerListViewModel, // gaslight the type to avoid over-specifying
];
it('should return the network mode from HostConfig', () => {
const config: ContainerDetailsJSON = {
HostConfig: { NetworkMode: 'host' },
};
expect(getNetworkMode(config, mockNetworks)).toEqual(['host']);
});
it('should return the network mode from NetworkSettings if HostConfig is empty', () => {
const config: ContainerDetailsJSON = {
NetworkSettings: { Networks: { custom: {} } },
};
expect(getNetworkMode(config, mockNetworks)).toEqual(['custom']);
});
it('should return container mode when NetworkMode starts with "container:"', () => {
const config: ContainerDetailsJSON = {
HostConfig: { NetworkMode: 'container:container-1' },
};
expect(getNetworkMode(config, mockNetworks, mockRunningContainers)).toEqual(
['container', 'container-1-name']
);
});
it('should return "podman" for bridge network when isPodman is true', () => {
const config: ContainerDetailsJSON = {
HostConfig: { NetworkMode: 'bridge' },
};
expect(getNetworkMode(config, mockNetworks, [], true)).toEqual(['podman']);
});
it('should return "bridge" for default network mode on Docker', () => {
const config: ContainerDetailsJSON = {
HostConfig: { NetworkMode: 'default' },
};
expect(getNetworkMode(config, mockNetworks)).toEqual(['bridge']);
});
it('should return the first available network if no matching network is found', () => {
const config: ContainerDetailsJSON = {
HostConfig: { NetworkMode: 'non-existent' },
};
expect(getNetworkMode(config, mockNetworks)).toEqual(['bridge']);
});
});