index.spec.ts 2.0 KB

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