MCPcopy
hub / github.com/cli/cli / TestNewPortForwarder

Function TestNewPortForwarder

internal/codespaces/portforwarder/port_forwarder_test.go:12–54  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

10)
11
12func TestNewPortForwarder(t *testing.T) {
13 ctx := context.Background()
14
15 // Create a mock codespace
16 codespace := &api.Codespace{
17 Connection: api.CodespaceConnection{
18 TunnelProperties: api.TunnelProperties{
19 ConnectAccessToken: "connect-token",
20 ManagePortsAccessToken: "manage-ports-token",
21 ServiceUri: "http://global.rel.tunnels.api.visualstudio.com/",
22 TunnelId: "tunnel-id",
23 ClusterId: "usw2",
24 Domain: "domain.com",
25 },
26 },
27 RuntimeConstraints: api.RuntimeConstraints{
28 AllowedPortPrivacySettings: []string{"public", "private"},
29 },
30 }
31
32 // Create the mock HTTP client
33 httpClient, err := connection.NewMockHttpClient()
34 if err != nil {
35 t.Fatalf("NewHttpClient returned an error: %v", err)
36 }
37
38 // Call the function being tested
39 conn, err := connection.NewCodespaceConnection(ctx, codespace, httpClient)
40 if err != nil {
41 t.Fatalf("NewCodespaceConnection returned an error: %v", err)
42 }
43
44 // Create the new port forwarder
45 portForwarder, err := NewPortForwarder(ctx, conn)
46 if err != nil {
47 t.Fatalf("NewPortForwarder returned an error: %v", err)
48 }
49
50 // Check that the port forwarder was created successfully
51 if portForwarder == nil {
52 t.Fatal("NewPortForwarder returned nil")
53 }
54}
55
56func TestAccessControlEntriesToVisibility(t *testing.T) {
57 publicAccessControlEntry := []tunnels.TunnelAccessControlEntry{{

Callers

nothing calls this directly

Calls 3

NewMockHttpClientFunction · 0.92
NewCodespaceConnectionFunction · 0.92
NewPortForwarderFunction · 0.85

Tested by

no test coverage detected