Add more test coverage for compose/images

Closes: #1492
Change-type: patch
Signed-off-by: Miguel Casqueira <miguel@balena.io>
This commit is contained in:
Miguel Casqueira
2020-10-30 17:38:19 -04:00
parent d1380e15ca
commit cd0d53c39d
6 changed files with 666 additions and 28 deletions

View File

@ -15,6 +15,24 @@ export class NotFoundError extends TypedError {
const overrides: Dictionary<(...args: any[]) => Resolvable<any>> = {};
interface Action {
name: string;
parameters: Dictionary<any>;
}
export let actions: Action[] = [];
export function resetHistory() {
actions = [];
}
function addAction(name: string, parameters: Dictionary<any>) {
actions.push({
name,
parameters,
});
}
type DockerodeFunction = keyof dockerode;
for (const fn of Object.getOwnPropertyNames(dockerode.prototype)) {
if (
@ -62,18 +80,28 @@ export interface TestData {
function createMockedDockerode(data: TestData) {
const mockedDockerode = dockerode.prototype;
mockedDockerode.getNetwork = (id: string) => {
addAction('getNetwork', { id });
return {
inspect: async () => {
addAction('inspect', {});
return data.networks[id];
},
} as dockerode.Network;
};
mockedDockerode.getImage = (name: string) => {
addAction('getImage', { name });
return {
inspect: async () => {
addAction('inspect', {});
return data.images[name];
},
remove: async () => {
addAction('remove', {});
data.images = _.reject(data.images, {
name,
});
},
} as dockerode.Image;
};