From e7f0c81a27bbb45e6ee77fd00b981863b496a5ef Mon Sep 17 00:00:00 2001 From: Narek Hovhannisyan Date: Mon, 25 Sep 2023 18:04:06 +0400 Subject: [PATCH] mocks: init fs index file. --- src/__mocks__/fs/index.ts | 54 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 src/__mocks__/fs/index.ts diff --git a/src/__mocks__/fs/index.ts b/src/__mocks__/fs/index.ts new file mode 100644 index 000000000..ae86025db --- /dev/null +++ b/src/__mocks__/fs/index.ts @@ -0,0 +1,54 @@ +import {expect} from '@jest/globals'; + +import * as YAML from 'js-yaml'; + +export const readFile = async (_filePath: string, _format: string) => { + return ` + name: gsf-demo + description: + Hello + tags: + kind: web + complexity: moderate + category: cloud + initialize: + models: + - name: boavizta-cpu + kind: builtin + config: + allocation: LINEAR + verbose: true + graph: + children: + front-end: + pipeline: + - boavizta-cpu + config: + boavizta-cpu: + core-units: 24 + processor: Intel® Core™ i7-1185G7 + observations: + - timestamp: 2023-07-06T00:00 # [KEYWORD] [NO-SUBFIELDS] time when measurement occurred + duration: 3600 # Secs + cpu-util: 18.392 + - timestamp: 2023-08-06T00:00 # [KEYWORD] [NO-SUBFIELDS] time when measurement occurred + duration: 3600 # Secs + cpu-util: 16`; +}; + +export const mkdir = (dirPath: string, _object: any) => dirPath; + +export const writeFile = async (pathToFile: string, content: string) => { + if (pathToFile === 'reject') { + throw Error('Wrong file path'); + } + + const mockPathToFile = 'mock-pathToFile'; + const mockContent = { + name: 'mock-name', + }; + const mockObject = YAML.dump(mockContent, {noRefs: true}); + + expect(pathToFile).toBe(mockPathToFile); + expect(content).toBe(mockObject); +};