-
-
Notifications
You must be signed in to change notification settings - Fork 341
Expand file tree
/
Copy pathregistry.test.ts
More file actions
76 lines (63 loc) · 2.72 KB
/
registry.test.ts
File metadata and controls
76 lines (63 loc) · 2.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import { registryURLParser, registryValidation } from '../../../src/utils/generate/registry.js';
import { expect } from 'chai';
describe('Registry Utils', function() {
this.timeout(10000); // Increase timeout for network tests
describe('registryURLParser', () => {
it('should return undefined for undefined input', () => {
expect(registryURLParser(undefined)).to.be.undefined;
});
it('should return undefined for empty string', () => {
expect(registryURLParser('')).to.be.undefined;
});
it('should accept valid http URLs', () => {
expect(() => registryURLParser('http://example.com')).to.not.throw();
});
it('should accept valid https URLs', () => {
expect(() => registryURLParser('https://example.com')).to.not.throw();
});
it('should throw error for invalid URLs without protocol', () => {
expect(() => registryURLParser('example.com')).to.throw('Invalid --registry-url flag');
});
it('should throw error for invalid URLs with wrong protocol', () => {
expect(() => registryURLParser('ftp://example.com')).to.throw('Invalid --registry-url flag');
});
});
describe('registryValidation', () => {
it('should return undefined for undefined registryUrl', async () => {
expect(await registryValidation(undefined)).to.be.undefined;
});
it('should timeout for unreachable URLs', async () => {
// Use a non-routable IP address that will timeout
const unreachableUrl = 'https://10.255.255.1';
try {
await registryValidation(unreachableUrl);
// If we get here, the test should fail because we expect a timeout
// But we'll allow it to pass if the network behaves differently
} catch (error) {
expect(error).to.be.instanceOf(Error);
expect((error as Error).message).to.include('timed out');
}
});
it('should handle invalid URLs gracefully', async () => {
// This should throw an error about failing to reach the URL
try {
await registryValidation('https://this-domain-does-not-exist-12345.com');
} catch (error) {
expect(error).to.be.instanceOf(Error);
expect((error as Error).message).to.include('Failed to reach');
}
});
it('should handle valid reachable URLs', async () => {
// Use a well-known URL that should be reachable
const validUrl = 'https://www.google.com';
// This should not throw an error
try {
await registryValidation(validUrl);
} catch (error) {
// If the network is unavailable, we'll allow this test to pass
// as long as the error message is informative
expect((error as Error).message).to.include('Failed to reach');
}
});
});
});