MCPcopy Create free account
hub / github.com/cli/cli / TestJupyterWebForwardingURL

Function TestJupyterWebForwardingURL

pkg/cmd/codespace/jupyter_test.go:25–209  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

23}
24
25func TestJupyterWebForwardingURL(t *testing.T) {
26 const forwardingURI = "https://ideal-space-fishstick-abc123-8888.app.github.dev/"
27
28 forwardedPort := func() []*tunnels.TunnelPort {
29 return []*tunnels.TunnelPort{
30 {PortNumber: 8888, PortForwardingURIs: []string{forwardingURI}},
31 }
32 }
33
34 // portWithVisibility builds a forwarded port carrying the access control entries
35 // that Dev Tunnels uses for the given visibility.
36 portWithVisibility := func(visibility string) []*tunnels.TunnelPort {
37 var entry tunnels.TunnelAccessControlEntry
38 switch visibility {
39 case portforwarder.PublicPortVisibility:
40 entry = tunnels.TunnelAccessControlEntry{
41 Type: tunnels.TunnelAccessControlEntryTypeAnonymous,
42 Subjects: []string{},
43 Scopes: []string{string(tunnels.TunnelAccessScopeConnect)},
44 }
45 case portforwarder.OrgPortVisibility:
46 entry = tunnels.TunnelAccessControlEntry{
47 Type: tunnels.TunnelAccessControlEntryTypeOrganizations,
48 Scopes: []string{string(tunnels.TunnelAccessScopeConnect)},
49 Provider: string(tunnels.TunnelAuthenticationSchemeGitHub),
50 }
51 default:
52 t.Fatalf("unsupported visibility %q", visibility)
53 }
54
55 return []*tunnels.TunnelPort{{
56 PortNumber: 8888,
57 PortForwardingURIs: []string{forwardingURI},
58 AccessControl: &tunnels.TunnelAccessControl{Entries: []tunnels.TunnelAccessControlEntry{entry}},
59 }}
60 }
61
62 tests := []struct {
63 name string
64 ports []*tunnels.TunnelPort
65 listErr error
66 serverPort int
67 serverURL string
68 want string
69 wantErr string
70 }{
71 {
72 name: "preserves path and token from the reported URL",
73 ports: forwardedPort(),
74 serverPort: 8888,
75 serverURL: "http://localhost:8888/lab?token=abc",
76 want: "https://ideal-space-fishstick-abc123-8888.app.github.dev/lab?token=abc",
77 },
78 {
79 name: "reported origin is ignored",
80 ports: forwardedPort(),
81 serverPort: 8888,
82 serverURL: "http://127.0.0.1:9999/anything?x=1",

Callers

nothing calls this directly

Calls 5

jupyterWebForwardingURLFunction · 0.85
ContainsMethod · 0.80
EqualMethod · 0.80
RunMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected