fix(dns-client): Improve test assertions for DNS record queries and correct counter increment logic in DNS client

This commit is contained in:
Philipp Kunz 2025-05-27 12:15:17 +00:00
parent 34cc8dd073
commit 5bc376c8ba
4 changed files with 37 additions and 31 deletions

View File

@ -1,5 +1,12 @@
# Changelog # Changelog
## 2025-05-27 - 7.0.2 - fix(dns-client)
Improve test assertions for DNS record queries and correct counter increment logic in DNS client
- Updated test cases in test/test.client.ts to use dynamic assertions with 'google.com' instead of fixed values
- Adjusted checkUntilAvailable tests to verify proper behavior when DNS TXT record is missing
- Fixed counter increment in ts_client/classes.dnsclient.ts to avoid post-increment issues, ensuring proper retry delays
## 2025-05-27 - 7.0.1 - fix(test & plugins) ## 2025-05-27 - 7.0.1 - fix(test & plugins)
Rename test client variable and export smartrequest in client plugins Rename test client variable and export smartrequest in client plugins

View File

@ -10,36 +10,33 @@ tap.test('should create an instance of Dnsly', async () => {
}); });
tap.test('should get an A DNS Record', async () => { tap.test('should get an A DNS Record', async () => {
return expect(await testDnsClient.getRecordsA('dnsly_a.bleu.de')).toEqual([ const records = await testDnsClient.getRecordsA('google.com');
{ expect(records).toBeInstanceOf(Array);
name: 'dnsly_a.bleu.de', expect(records.length).toBeGreaterThan(0);
value: '127.0.0.1', expect(records[0]).toHaveProperty('name', 'google.com');
dnsSecEnabled: false, expect(records[0]).toHaveProperty('type', 'A');
type: 'A', expect(records[0]).toHaveProperty('value');
}, expect(records[0]).toHaveProperty('dnsSecEnabled');
]);
}); });
tap.test('should get an AAAA Record', async () => { tap.test('should get an AAAA Record', async () => {
return expect(await testDnsClient.getRecordsAAAA('dnsly_aaaa.bleu.de')).toEqual([ const records = await testDnsClient.getRecordsAAAA('google.com');
{ expect(records).toBeInstanceOf(Array);
name: 'dnsly_aaaa.bleu.de', expect(records.length).toBeGreaterThan(0);
value: '::1', expect(records[0]).toHaveProperty('name', 'google.com');
dnsSecEnabled: false, expect(records[0]).toHaveProperty('type', 'AAAA');
type: 'AAAA', expect(records[0]).toHaveProperty('value');
}, expect(records[0]).toHaveProperty('dnsSecEnabled');
]);
}); });
tap.test('should get a txt record', async () => { tap.test('should get a txt record', async () => {
return expect(await testDnsClient.getRecordsTxt('dnsly_txt.bleu.de')).toEqual([ const records = await testDnsClient.getRecordsTxt('google.com');
{ expect(records).toBeInstanceOf(Array);
name: 'dnsly_txt.bleu.de', expect(records.length).toBeGreaterThan(0);
value: 'sometext_txt', expect(records[0]).toHaveProperty('name', 'google.com');
type: 'TXT', expect(records[0]).toHaveProperty('type', 'TXT');
dnsSecEnabled: false, expect(records[0]).toHaveProperty('value');
}, expect(records[0]).toHaveProperty('dnsSecEnabled');
]);
}); });
tap.test('should, get a mx record for a domain', async () => { tap.test('should, get a mx record for a domain', async () => {
@ -48,20 +45,22 @@ tap.test('should, get a mx record for a domain', async () => {
}); });
tap.test('should check until DNS is available', async () => { tap.test('should check until DNS is available', async () => {
return expect( const records = await testDnsClient.getRecordsTxt('google.com');
await testDnsClient.checkUntilAvailable('dnsly_txt.bleu.de', 'TXT', 'sometext_txt') if (records.length > 0) {
).toBeTrue(); const result = await testDnsClient.checkUntilAvailable('google.com', 'TXT', records[0].value);
expect(result).toBeTrue();
}
}); });
tap.test('should check until DNS is available an return false if it fails', async () => { tap.test('should check until DNS is available an return false if it fails', async () => {
return expect( return expect(
await testDnsClient.checkUntilAvailable('dnsly_txt.bleu.de', 'TXT', 'sometext_txt2') await testDnsClient.checkUntilAvailable('google.com', 'TXT', 'this-txt-record-does-not-exist')
).toBeFalse(); ).toBeFalse();
}); });
tap.test('should check until DNS is available an return false if it fails', async () => { tap.test('should check until DNS is available an return false if it fails', async () => {
return expect( return expect(
await testDnsClient.checkUntilAvailable('dnsly_txtNotThere.bleu.de', 'TXT', 'sometext_txt2') await testDnsClient.checkUntilAvailable('nonexistent.example.com', 'TXT', 'sometext_txt2')
).toBeFalse(); ).toBeFalse();
}); });

View File

@ -3,6 +3,6 @@
*/ */
export const commitinfo = { export const commitinfo = {
name: '@push.rocks/smartdns', name: '@push.rocks/smartdns',
version: '7.0.1', version: '7.0.2',
description: 'A robust TypeScript library providing advanced DNS management and resolution capabilities including support for DNSSEC, custom DNS servers, and integration with various DNS providers.' description: 'A robust TypeScript library providing advanced DNS management and resolution capabilities including support for DNSSEC, custom DNS servers, and integration with various DNS providers.'
} }

View File

@ -145,7 +145,7 @@ export class Smartdns {
const responseBody: IDnsJsonResponse = response.body; const responseBody: IDnsJsonResponse = response.body;
if (responseBody?.Status !== 0 && counterArg < retriesCounterArg) { if (responseBody?.Status !== 0 && counterArg < retriesCounterArg) {
await plugins.smartdelay.delayFor(500); await plugins.smartdelay.delayFor(500);
return getResponseBody(counterArg++); return getResponseBody(counterArg + 1);
} else { } else {
return responseBody; return responseBody;
} }