|
| 1 | +import { portForwardURL } from "./portForward"; |
| 2 | + |
| 3 | +describe("port forward URL", () => { |
| 4 | + const proxyHostWildcard = "*.proxy-host.tld"; |
| 5 | + const samplePort = 12345; |
| 6 | + const sampleAgent = "my-agent"; |
| 7 | + const sampleWorkspace = "my-workspace"; |
| 8 | + const sampleUsername = "my-username"; |
| 9 | + |
| 10 | + it("https, host and port", () => { |
| 11 | + const forwarded = portForwardURL( |
| 12 | + proxyHostWildcard, |
| 13 | + samplePort, |
| 14 | + sampleAgent, |
| 15 | + sampleWorkspace, |
| 16 | + sampleUsername, |
| 17 | + "https", |
| 18 | + ); |
| 19 | + expect(forwarded).toEqual( |
| 20 | + "http://12345s--my-agent--my-workspace--my-username.proxy-host.tld/", |
| 21 | + ); |
| 22 | + }); |
| 23 | + it("http, host, port and path", () => { |
| 24 | + const forwarded = portForwardURL( |
| 25 | + proxyHostWildcard, |
| 26 | + samplePort, |
| 27 | + sampleAgent, |
| 28 | + sampleWorkspace, |
| 29 | + sampleUsername, |
| 30 | + "http", |
| 31 | + "/path1/path2", |
| 32 | + ); |
| 33 | + expect(forwarded).toEqual( |
| 34 | + "http://12345--my-agent--my-workspace--my-username.proxy-host.tld/path1/path2", |
| 35 | + ); |
| 36 | + }); |
| 37 | + it("https, host, port, path and empty params", () => { |
| 38 | + const forwarded = portForwardURL( |
| 39 | + proxyHostWildcard, |
| 40 | + samplePort, |
| 41 | + sampleAgent, |
| 42 | + sampleWorkspace, |
| 43 | + sampleUsername, |
| 44 | + "https", |
| 45 | + "/path1/path2", |
| 46 | + "?", |
| 47 | + ); |
| 48 | + expect(forwarded).toEqual( |
| 49 | + "http://12345s--my-agent--my-workspace--my-username.proxy-host.tld/path1/path2?", |
| 50 | + ); |
| 51 | + }); |
| 52 | + it("http, host, port, path and query params", () => { |
| 53 | + const forwarded = portForwardURL( |
| 54 | + proxyHostWildcard, |
| 55 | + samplePort, |
| 56 | + sampleAgent, |
| 57 | + sampleWorkspace, |
| 58 | + sampleUsername, |
| 59 | + "http", |
| 60 | + "/path1/path2", |
| 61 | + "?key1=value1&key2=value2", |
| 62 | + ); |
| 63 | + expect(forwarded).toEqual( |
| 64 | + "http://12345--my-agent--my-workspace--my-username.proxy-host.tld/path1/path2?key1=value1&key2=value2", |
| 65 | + ); |
| 66 | + }); |
| 67 | +}); |
0 commit comments