(t *testing.T)
| 32 | } |
| 33 | |
| 34 | func TestListPorts_escapesControlSequencesInLabel(t *testing.T) { |
| 35 | tests := []struct { |
| 36 | name string |
| 37 | tty bool |
| 38 | }{ |
| 39 | {name: "tty", tty: true}, |
| 40 | {name: "not tty", tty: false}, |
| 41 | } |
| 42 | |
| 43 | for _, tt := range tests { |
| 44 | t.Run(tt.name, func(t *testing.T) { |
| 45 | mockApi := GetMockApi(false) |
| 46 | mockApi.GetCodespaceRepositoryContentsFunc = func(ctx context.Context, codespace *api.Codespace, path string) ([]byte, error) { |
| 47 | return []byte(`{"portsAttributes":{"0":{"label":"web \u001b]0;title\u0007end"}}}`), nil |
| 48 | } |
| 49 | ios, _, stdout, _ := iostreams.Test() |
| 50 | ios.SetStdoutTTY(tt.tty) |
| 51 | |
| 52 | a := &App{ |
| 53 | io: ios, |
| 54 | apiClient: mockApi, |
| 55 | } |
| 56 | |
| 57 | selector := &CodespaceSelector{api: a.apiClient, codespaceName: "codespace-name"} |
| 58 | err := a.ListPorts(t.Context(), selector, nil) |
| 59 | require.NoError(t, err) |
| 60 | |
| 61 | assert.Contains(t, stdout.String(), `web ^[]0;title^Gend`) |
| 62 | assert.NotContains(t, stdout.String(), "\x1b]") |
| 63 | assert.NotContains(t, stdout.String(), "\a") |
| 64 | }) |
| 65 | } |
| 66 | } |
| 67 | |
| 68 | func TestPortsUpdateVisibilitySuccess(t *testing.T) { |
| 69 | portVisibilities := []portVisibility{ |
nothing calls this directly
no test coverage detected