(t *testing.T)
| 10 | ) |
| 11 | |
| 12 | func TestNewCodespaceConnection(t *testing.T) { |
| 13 | ctx := context.Background() |
| 14 | |
| 15 | // Create a mock codespace |
| 16 | connection := api.CodespaceConnection{ |
| 17 | TunnelProperties: api.TunnelProperties{ |
| 18 | ConnectAccessToken: "connect-token", |
| 19 | ManagePortsAccessToken: "manage-ports-token", |
| 20 | ServiceUri: "http://global.rel.tunnels.api.visualstudio.com/", |
| 21 | TunnelId: "tunnel-id", |
| 22 | ClusterId: "usw2", |
| 23 | Domain: "domain.com", |
| 24 | }, |
| 25 | } |
| 26 | allowedPortPrivacySettings := []string{"public", "private"} |
| 27 | codespace := &api.Codespace{ |
| 28 | Connection: connection, |
| 29 | RuntimeConstraints: api.RuntimeConstraints{AllowedPortPrivacySettings: allowedPortPrivacySettings}, |
| 30 | } |
| 31 | |
| 32 | // Create the mock HTTP client |
| 33 | httpClient, err := NewMockHttpClient() |
| 34 | if err != nil { |
| 35 | t.Fatalf("NewHttpClient returned an error: %v", err) |
| 36 | } |
| 37 | |
| 38 | // Create the connection |
| 39 | conn, err := NewCodespaceConnection(ctx, codespace, httpClient) |
| 40 | if err != nil { |
| 41 | t.Fatalf("NewCodespaceConnection returned an error: %v", err) |
| 42 | } |
| 43 | |
| 44 | // Verify closing before connected doesn't throw |
| 45 | err = conn.Close() |
| 46 | if err != nil { |
| 47 | t.Fatalf("Close returned an error: %v", err) |
| 48 | } |
| 49 | |
| 50 | // Check that the connection was created successfully |
| 51 | if conn == nil { |
| 52 | t.Fatal("NewCodespaceConnection returned nil") |
| 53 | } |
| 54 | |
| 55 | // Verify that the connection contains the expected tunnel properties |
| 56 | if conn.tunnelProperties != connection.TunnelProperties { |
| 57 | t.Fatalf("NewCodespaceConnection returned a connection with unexpected tunnel properties: %+v", conn.tunnelProperties) |
| 58 | } |
| 59 | |
| 60 | // Verify that the connection contains the expected tunnel |
| 61 | expectedTunnel := &tunnels.Tunnel{ |
| 62 | AccessTokens: map[tunnels.TunnelAccessScope]string{tunnels.TunnelAccessScopeConnect: connection.TunnelProperties.ConnectAccessToken, tunnels.TunnelAccessScopeManagePorts: connection.TunnelProperties.ManagePortsAccessToken}, |
| 63 | TunnelID: connection.TunnelProperties.TunnelId, |
| 64 | ClusterID: connection.TunnelProperties.ClusterId, |
| 65 | Domain: connection.TunnelProperties.Domain, |
| 66 | } |
| 67 | if !reflect.DeepEqual(conn.Tunnel, expectedTunnel) { |
| 68 | t.Fatalf("NewCodespaceConnection returned a connection with unexpected tunnel: %+v", conn.Tunnel) |
| 69 | } |
nothing calls this directly
no test coverage detected