|
6 | 6 | import * as vscode from 'vscode' |
7 | 7 | import assert from 'assert' |
8 | 8 | import sinon from 'sinon' |
9 | | -import { getProjectRootUri, getProjectRoot, getSource, isDotnetRuntime } from '../../../shared/sam/utils' |
| 9 | +import { |
| 10 | + getProjectRootUri, |
| 11 | + getProjectRoot, |
| 12 | + getSource, |
| 13 | + isDotnetRuntime, |
| 14 | + getSamCliErrorMessage, |
| 15 | + throwIfErrorMatches, |
| 16 | +} from '../../../shared/sam/utils' |
10 | 17 | import { TemplateItem } from '../../../shared/sam/sync' |
11 | 18 | import { RegionNode } from '../../../awsexplorer/regionNode' |
12 | 19 | import { Region } from '../../../shared/regions/endpoints' |
13 | | -import { RegionProvider } from '../../../shared' |
| 20 | +import { RegionProvider, ToolkitError } from '../../../shared' |
14 | 21 | import { DeployedResource, DeployedResourceNode } from '../../../awsService/appBuilder/explorer/nodes/deployedNode' |
| 22 | +import { ChildProcessResult } from '../../../shared/utilities/processUtils' |
15 | 23 |
|
16 | 24 | describe('SAM utils', async function () { |
17 | 25 | it('returns the projectRoot', async function () { |
@@ -148,4 +156,36 @@ describe('SAM utils', async function () { |
148 | 156 | }) |
149 | 157 | }) |
150 | 158 | }) |
| 159 | + |
| 160 | + describe('gets the SAM CLI error from stderr', async function () { |
| 161 | + it('returns the error message', async function () { |
| 162 | + const stderr = |
| 163 | + 'Starting Build use cache\nStarting Build inside a container\nCache is invalid, running build and copying resources for following functions (ResizerFunction)\nBuilding codeuri: /Users/mbfreder/TestApp/JavaSamApp/serverless-patterns/s3lambda-resizing-python/src runtime: python3.12 metadata: {} architecture: x86_64 functions: ResizerFunction\nError: Docker is unreachable. Docker needs to be running to build inside a container.' |
| 164 | + const response = getSamCliErrorMessage(stderr) |
| 165 | + assert.deepStrictEqual( |
| 166 | + response, |
| 167 | + 'Error: Docker is unreachable. Docker needs to be running to build inside a container.' |
| 168 | + ) |
| 169 | + }) |
| 170 | + }) |
| 171 | + |
| 172 | + describe('throwIfErrorMatches', async function () { |
| 173 | + it('should throw a ToolkitError with the correct code when an error message matches', () => { |
| 174 | + const mockError = new Error('Mock Error') |
| 175 | + const mockResult: ChildProcessResult = { |
| 176 | + exitCode: 1, |
| 177 | + error: mockError, |
| 178 | + stdout: '', |
| 179 | + stderr: 'Docker is unreachable.', |
| 180 | + } |
| 181 | + assert.throws( |
| 182 | + () => throwIfErrorMatches(mockResult), |
| 183 | + (e: any) => { |
| 184 | + assert.strictEqual(e instanceof ToolkitError, true) |
| 185 | + assert.strictEqual(e.code, 'DockerUnreachable') |
| 186 | + return true |
| 187 | + } |
| 188 | + ) |
| 189 | + }) |
| 190 | + }) |
151 | 191 | }) |
0 commit comments