install.test.ts 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. import { describe, it, expect } from 'vitest';
  2. import {
  3. buildScriptCommand,
  4. buildDockerRun,
  5. buildDockerCompose,
  6. type InstallOptions,
  7. } from './install';
  8. const base: InstallOptions = {
  9. method: 'script',
  10. version: '',
  11. enableFail2ban: true,
  12. panelPort: '',
  13. webBasePath: '',
  14. };
  15. describe('buildScriptCommand', () => {
  16. it('uses the master install.sh for the latest version', () => {
  17. expect(buildScriptCommand(base)).toBe(
  18. 'bash <(curl -Ls https://raw.githubusercontent.com/mhsanaei/3x-ui/master/install.sh)',
  19. );
  20. });
  21. it('pins a specific version by passing the tag to master install.sh', () => {
  22. const cmd = buildScriptCommand({ ...base, version: 'v3.4.1' });
  23. expect(cmd).toBe(
  24. 'bash <(curl -Ls https://raw.githubusercontent.com/mhsanaei/3x-ui/master/install.sh) v3.4.1',
  25. );
  26. });
  27. it('supports the rolling dev-latest build', () => {
  28. const cmd = buildScriptCommand({ ...base, version: 'dev-latest' });
  29. expect(cmd).toBe(
  30. 'bash <(curl -Ls https://raw.githubusercontent.com/mhsanaei/3x-ui/master/install.sh) dev-latest',
  31. );
  32. });
  33. });
  34. describe('buildDockerRun', () => {
  35. it('reflects fail2ban, port, and base path options', () => {
  36. const cmd = buildDockerRun({
  37. ...base,
  38. enableFail2ban: false,
  39. panelPort: '8443',
  40. webBasePath: '/panel',
  41. });
  42. expect(cmd).toContain('XUI_ENABLE_FAIL2BAN=false');
  43. expect(cmd).toContain('XUI_PORT=8443');
  44. expect(cmd).toContain('XUI_INIT_WEB_BASE_PATH=/panel');
  45. expect(cmd).toContain('ghcr.io/mhsanaei/3x-ui:latest');
  46. expect(cmd).toContain('-v $PWD/db/:/etc/x-ui/');
  47. });
  48. it('omits unset port and path', () => {
  49. const cmd = buildDockerRun(base);
  50. expect(cmd).not.toContain('XUI_PORT');
  51. expect(cmd).not.toContain('XUI_INIT_WEB_BASE_PATH');
  52. });
  53. });
  54. describe('buildDockerCompose', () => {
  55. it('produces valid-looking compose with the image and volumes', () => {
  56. const yaml = buildDockerCompose({ ...base, panelPort: '2096' });
  57. expect(yaml).toContain('image: ghcr.io/mhsanaei/3x-ui:latest');
  58. expect(yaml).toContain('network_mode: host');
  59. expect(yaml).toContain("XUI_PORT: '2096'");
  60. expect(yaml).toContain('- ./db/:/etc/x-ui/');
  61. });
  62. });