-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
readGrpcCert: Remove Promise.any usage
- Loading branch information
Showing
2 changed files
with
99 additions
and
25 deletions.
There are no files selected for viewing
67 changes: 67 additions & 0 deletions
67
web/packages/teleterm/src/services/grpcCredentials/files.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/** | ||
* @jest-environment node | ||
*/ | ||
/** | ||
* Teleport | ||
* Copyright (C) 2024 Gravitational, Inc. | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
import fs from 'node:fs/promises'; | ||
import path from 'node:path'; | ||
import os from 'node:os'; | ||
import timers from 'node:timers/promises'; | ||
|
||
import { readGrpcCert } from './files'; | ||
|
||
let tempDir: string; | ||
|
||
beforeAll(async () => { | ||
tempDir = await fs.mkdtemp(path.join(os.tmpdir(), 'grpc-files-test')); | ||
}); | ||
|
||
afterAll(async () => { | ||
await fs.rm(tempDir, { recursive: true, force: true }); | ||
}); | ||
|
||
describe('readGrpcCert', () => { | ||
it('reads the file if the file already exists', async () => { | ||
await fs.writeFile(path.join(tempDir, 'already-exists'), 'foobar'); | ||
|
||
await expect( | ||
readGrpcCert(tempDir, 'already-exists').then(buffer => buffer.toString()) | ||
).resolves.toEqual('foobar'); | ||
}); | ||
|
||
it('reads the file when the file is created after starting a watcher', async () => { | ||
const readGrpcCertPromise = readGrpcCert( | ||
tempDir, | ||
'created-after-start' | ||
).then(buffer => buffer.toString()); | ||
await timers.setTimeout(10); | ||
|
||
await fs.writeFile(path.join(tempDir, 'created-after-start'), 'foobar'); | ||
|
||
await expect(readGrpcCertPromise).resolves.toEqual('foobar'); | ||
}); | ||
|
||
it('returns an error if the file is not created within the timeout', async () => { | ||
await expect( | ||
readGrpcCert(tempDir, 'non-existent', { timeoutMs: 1 }) | ||
).rejects.toMatchObject({ | ||
message: expect.stringContaining('within the timeout'), | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters