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

Function TestListPorts_escapesControlSequencesInLabel

pkg/cmd/codespace/ports_test.go:34–66  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

32}
33
34func 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
68func TestPortsUpdateVisibilitySuccess(t *testing.T) {
69 portVisibilities := []portVisibility{

Callers

nothing calls this directly

Calls 7

ListPortsMethod · 0.95
TestFunction · 0.92
GetMockApiFunction · 0.85
SetStdoutTTYMethod · 0.80
ContainsMethod · 0.80
RunMethod · 0.65
StringMethod · 0.65

Tested by

no test coverage detected