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

Function TestCopyLogWithLinePrefix_TerminalEscapeSequences

pkg/cmd/run/view/view_test.go:2762–2800  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

2760var expectedLegacyRunLogOutputWithNoSteps = fmt.Sprintf("%s%s", legacyCoolJobRunWithNoStepLogsLogOutput, legacySadJobRunWithNoStepLogsLogOutput)
2761
2762func TestCopyLogWithLinePrefix_TerminalEscapeSequences(t *testing.T) {
2763 tests := []struct {
2764 name string
2765 input string
2766 }{
2767 {
2768 name: "OSC title set sequence",
2769 input: "normal prefix\x1b]0;HIJACKED TITLE\x07trailing text\n",
2770 },
2771 {
2772 name: "CSI color sequence",
2773 input: "\x1b[31mRED TEXT\x1b[0m normal text\n",
2774 },
2775 {
2776 name: "screen title set sequence used in original report",
2777 input: "\x1bk;echo this is an arbitrary command;\x1b\\\n",
2778 },
2779 {
2780 name: "CSI window title query",
2781 input: "before\x1b[21tafter\n",
2782 },
2783 {
2784 name: "multiple escape sequences",
2785 input: "\x1b]0;title\x07\x1b[31mred\x1b[0m\x1b[21t\n",
2786 },
2787 }
2788
2789 for _, tt := range tests {
2790 t.Run(tt.name, func(t *testing.T) {
2791 var buf bytes.Buffer
2792 err := copyLogWithLinePrefix(&buf, strings.NewReader(tt.input), "jobname\tstep\t")
2793 require.NoError(t, err)
2794
2795 output := buf.String()
2796 assert.NotContains(t, output, "\x1b",
2797 "output should not contain raw ESC (0x1b) bytes, got: %q", output)
2798 })
2799 }
2800}
2801
2802func TestRunLog(t *testing.T) {
2803 t.Run("when the cache dir doesn't exist, exists return false", func(t *testing.T) {

Callers

nothing calls this directly

Calls 3

copyLogWithLinePrefixFunction · 0.85
RunMethod · 0.65
StringMethod · 0.65

Tested by

no test coverage detected