|
1 | | -import fs from "fs"; |
2 | | -import yaml from "js-yaml"; |
3 | 1 | import os from "os"; |
4 | 2 | import path from "path"; |
5 | 3 | import shell from "shelljs"; |
6 | 4 | import uuid from "uuid/v4"; |
7 | | -import { Bedrock, bedrockFileInfo, write } from "./config"; |
| 5 | +import { Bedrock, write } from "./config"; |
8 | 6 | import { disableVerboseLogging, enableVerboseLogging, logger } from "./logger"; |
9 | 7 | import { IBedrockFile, IBedrockFileInfo } from "./types"; |
10 | 8 |
|
@@ -103,85 +101,3 @@ describe("Bedrock", () => { |
103 | 101 | expect(error).toBeDefined(); |
104 | 102 | }); |
105 | 103 | }); |
106 | | - |
107 | | -describe("isBedrockFileValid", () => { |
108 | | - test("Should fail when empty file directory is passed", async () => { |
109 | | - let invalidDirError: Error | undefined; |
110 | | - |
111 | | - try { |
112 | | - logger.info("calling create"); |
113 | | - await bedrockFileInfo(""); |
114 | | - } catch (err) { |
115 | | - invalidDirError = err; |
116 | | - } |
117 | | - expect(invalidDirError).toBeDefined(); |
118 | | - }); |
119 | | - |
120 | | - test("Should return false when bedrock file does not exist", async () => { |
121 | | - // Create random directory to initialize |
122 | | - const randomTmpDir = path.join(os.tmpdir(), uuid()); |
123 | | - fs.mkdirSync(randomTmpDir); |
124 | | - |
125 | | - const fileInfo: IBedrockFileInfo = await bedrockFileInfo(randomTmpDir); |
126 | | - |
127 | | - logger.info(`bedrock.yaml file exists: ${fileInfo.exist}`); |
128 | | - |
129 | | - expect(fileInfo.exist).toBe(false); |
130 | | - }); |
131 | | - |
132 | | - test("Should pass when bedrock file exists with variable groups length 0", async () => { |
133 | | - // Create random directory to initialize |
134 | | - const randomTmpDir = path.join(os.tmpdir(), uuid()); |
135 | | - fs.mkdirSync(randomTmpDir); |
136 | | - |
137 | | - logger.info(`random temp dir: ${randomTmpDir}`); |
138 | | - |
139 | | - // create bedrock file to simulate the the use case that `spk project init` ran before |
140 | | - const bedrockFileData: IBedrockFile = { |
141 | | - rings: {}, |
142 | | - services: {}, |
143 | | - variableGroups: [] |
144 | | - }; |
145 | | - |
146 | | - const asYaml = yaml.safeDump(bedrockFileData, { |
147 | | - lineWidth: Number.MAX_SAFE_INTEGER |
148 | | - }); |
149 | | - fs.writeFileSync(path.join(randomTmpDir, "bedrock.yaml"), asYaml); |
150 | | - |
151 | | - const fileInfo: IBedrockFileInfo = await bedrockFileInfo(randomTmpDir); |
152 | | - logger.verbose( |
153 | | - `bedrock.yaml file exists: ${fileInfo.exist} in ${randomTmpDir}` |
154 | | - ); |
155 | | - |
156 | | - expect(fileInfo.exist).toBe(true); |
157 | | - expect(fileInfo.hasVariableGroups).toBe(false); |
158 | | - }); |
159 | | - |
160 | | - test("Should pass when bedrock file exists with one variable group", async () => { |
161 | | - // Create random directory to initialize |
162 | | - const randomTmpDir = path.join(os.tmpdir(), uuid()); |
163 | | - fs.mkdirSync(randomTmpDir); |
164 | | - |
165 | | - logger.info(`random temp dir: ${randomTmpDir}`); |
166 | | - |
167 | | - // create bedrock file to simulate the the use case that `spk project init` ran before |
168 | | - const bedrockFileData: IBedrockFile = { |
169 | | - rings: {}, |
170 | | - services: {}, |
171 | | - variableGroups: [variableGroupName] |
172 | | - }; |
173 | | - |
174 | | - const asYaml = yaml.safeDump(bedrockFileData, { |
175 | | - lineWidth: Number.MAX_SAFE_INTEGER |
176 | | - }); |
177 | | - fs.writeFileSync(path.join(randomTmpDir, "bedrock.yaml"), asYaml); |
178 | | - |
179 | | - const fileInfo: IBedrockFileInfo = await bedrockFileInfo(randomTmpDir); |
180 | | - logger.info( |
181 | | - `bedrock.yaml file exists: ${fileInfo.exist} in ${randomTmpDir}` |
182 | | - ); |
183 | | - |
184 | | - expect(fileInfo.exist).toBe(true); |
185 | | - expect(fileInfo.hasVariableGroups).toBe(true); |
186 | | - }); |
187 | | -}); |
0 commit comments