index.spec.ts 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. import { formatHost } from '../src/utils'
  2. describe('formatHost Function Tests', () => {
  3. it('should return default URL for empty string', () => {
  4. expect(formatHost('')).toBe('http://127.0.0.1:11434')
  5. })
  6. it('should parse plain IP address', () => {
  7. expect(formatHost('1.2.3.4')).toBe('http://1.2.3.4:11434')
  8. })
  9. it('should parse IP address with port', () => {
  10. expect(formatHost('1.2.3.4:56789')).toBe('http://1.2.3.4:56789')
  11. })
  12. it('should parse with only a port', () => {
  13. expect(formatHost(':56789')).toBe('http://127.0.0.1:56789')
  14. })
  15. it('should parse HTTP URL', () => {
  16. expect(formatHost('http://1.2.3.4')).toBe('http://1.2.3.4:80')
  17. })
  18. it('should parse HTTPS URL', () => {
  19. expect(formatHost('https://1.2.3.4')).toBe('https://1.2.3.4:443')
  20. })
  21. it('should parse HTTPS URL with port', () => {
  22. expect(formatHost('https://1.2.3.4:56789')).toBe('https://1.2.3.4:56789')
  23. })
  24. it('should parse domain name', () => {
  25. expect(formatHost('example.com')).toBe('http://example.com:11434')
  26. })
  27. it('should parse domain name with port', () => {
  28. expect(formatHost('example.com:56789')).toBe('http://example.com:56789')
  29. })
  30. it('should parse HTTP domain', () => {
  31. expect(formatHost('http://example.com')).toBe('http://example.com:80')
  32. })
  33. it('should parse HTTPS domain', () => {
  34. expect(formatHost('https://example.com')).toBe('https://example.com:443')
  35. })
  36. it('should parse HTTPS domain with port', () => {
  37. expect(formatHost('https://example.com:56789')).toBe('https://example.com:56789')
  38. })
  39. it('should handle trailing slash in domain', () => {
  40. expect(formatHost('example.com/')).toBe('http://example.com:11434')
  41. })
  42. it('should handle trailing slash in domain with port', () => {
  43. expect(formatHost('example.com:56789/')).toBe('http://example.com:56789')
  44. })
  45. it('should handle traling slash with only a port', () => {
  46. expect(formatHost(':56789/')).toBe('http://127.0.0.1:56789')
  47. })
  48. })