|
| 1 | +import { describe, it, expect } from "@jest/globals"; |
| 2 | +import { extractSshHostname } from "./runtimeBadge"; |
| 3 | +import type { RuntimeConfig } from "@/types/runtime"; |
| 4 | + |
| 5 | +describe("extractSshHostname", () => { |
| 6 | + it("should return null for undefined runtime config", () => { |
| 7 | + expect(extractSshHostname(undefined)).toBeNull(); |
| 8 | + }); |
| 9 | + |
| 10 | + it("should return null for local runtime", () => { |
| 11 | + const config: RuntimeConfig = { |
| 12 | + type: "local", |
| 13 | + srcBaseDir: "/home/user/.cmux/src", |
| 14 | + }; |
| 15 | + expect(extractSshHostname(config)).toBeNull(); |
| 16 | + }); |
| 17 | + |
| 18 | + it("should extract hostname from simple host", () => { |
| 19 | + const config: RuntimeConfig = { |
| 20 | + type: "ssh", |
| 21 | + host: "myserver", |
| 22 | + srcBaseDir: "/home/user/.cmux/src", |
| 23 | + }; |
| 24 | + expect(extractSshHostname(config)).toBe("myserver"); |
| 25 | + }); |
| 26 | + |
| 27 | + it("should extract hostname from user@host format", () => { |
| 28 | + const config: RuntimeConfig = { |
| 29 | + type: "ssh", |
| 30 | + host: "user@myserver.example.com", |
| 31 | + srcBaseDir: "/home/user/.cmux/src", |
| 32 | + }; |
| 33 | + expect(extractSshHostname(config)).toBe("myserver.example.com"); |
| 34 | + }); |
| 35 | + |
| 36 | + it("should handle hostname with port in host string", () => { |
| 37 | + const config: RuntimeConfig = { |
| 38 | + type: "ssh", |
| 39 | + host: "myserver:2222", |
| 40 | + srcBaseDir: "/home/user/.cmux/src", |
| 41 | + }; |
| 42 | + expect(extractSshHostname(config)).toBe("myserver"); |
| 43 | + }); |
| 44 | + |
| 45 | + it("should handle user@host:port format", () => { |
| 46 | + const config: RuntimeConfig = { |
| 47 | + type: "ssh", |
| 48 | + host: "user@myserver.example.com:2222", |
| 49 | + srcBaseDir: "/home/user/.cmux/src", |
| 50 | + }; |
| 51 | + expect(extractSshHostname(config)).toBe("myserver.example.com"); |
| 52 | + }); |
| 53 | + |
| 54 | + it("should handle SSH config alias", () => { |
| 55 | + const config: RuntimeConfig = { |
| 56 | + type: "ssh", |
| 57 | + host: "my-server-alias", |
| 58 | + srcBaseDir: "/home/user/.cmux/src", |
| 59 | + }; |
| 60 | + expect(extractSshHostname(config)).toBe("my-server-alias"); |
| 61 | + }); |
| 62 | +}); |
0 commit comments