增强Salon Nacos回退读回校验
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
import { createHash } from 'node:crypto';
|
||||
|
||||
export async function verifyConfigReadback(url, expectedContent, expectExists, options = {}) {
|
||||
const request = options.request || fetch;
|
||||
const attempts = options.attempts || 3;
|
||||
const delayMs = options.delayMs ?? 1000;
|
||||
const expectedHash = expectExists ? sha256(expectedContent) : null;
|
||||
|
||||
for (let attempt = 0; attempt < attempts; attempt += 1) {
|
||||
const response = await request(url);
|
||||
const actual = await response.text();
|
||||
const matches = expectExists
|
||||
? response.ok && sha256(actual) === expectedHash
|
||||
: response.status === 404;
|
||||
if (matches) return true;
|
||||
if (attempt + 1 < attempts && delayMs > 0) {
|
||||
await new Promise((resolve) => setTimeout(resolve, delayMs));
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function sha256(value) {
|
||||
return createHash('sha256').update(value ?? '', 'utf8').digest('hex');
|
||||
}
|
||||
Reference in New Issue
Block a user