From bf506f3c554e806a77f231f81934f8e608ec53dc Mon Sep 17 00:00:00 2001 From: Billy Zha Date: Mon, 25 Nov 2024 10:11:09 +0000 Subject: [PATCH 1/2] fix(ut): close file after read finished Signed-off-by: Billy Zha --- internal/testutils/console.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/testutils/console.go b/internal/testutils/console.go index 5d26674c7..1691da1b4 100644 --- a/internal/testutils/console.go +++ b/internal/testutils/console.go @@ -50,8 +50,8 @@ func MatchPty(pty containerd.Console, device *os.File, expected ...string) error defer wg.Done() _, _ = io.Copy(&buffer, pty) }() - device.Close() wg.Wait() + device.Close() return OrderedMatch(buffer.String(), expected...) } From 0873a3f89cc3971639d32a675022277eff4100f3 Mon Sep 17 00:00:00 2001 From: Billy Zha Date: Wed, 27 Nov 2024 12:48:40 +0000 Subject: [PATCH 2/2] fix e2e Signed-off-by: Billy Zha --- .../display/status/console/console_test.go | 16 ++++++++-------- internal/testutils/console.go | 2 +- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/cmd/oras/internal/display/status/console/console_test.go b/cmd/oras/internal/display/status/console/console_test.go index 65549e9e2..595b0f2c3 100644 --- a/cmd/oras/internal/display/status/console/console_test.go +++ b/cmd/oras/internal/display/status/console/console_test.go @@ -43,11 +43,11 @@ func givenTestConsole(t *testing.T) (c Console, pty containerd.Console, tty *os. if err != nil { t.Fatal(err) } - - c = &console{ - Console: pty, + c, err = NewConsole(tty) + if err != nil { + t.Fatal(err) } - return c, pty, tty + return } func validateSize(t *testing.T, gotWidth, gotHeight, wantWidth, wantHeight int) { @@ -96,7 +96,7 @@ func TestConsole_NewRow(t *testing.T) { c.NewRow() - err := testutils.MatchPty(pty, tty, "^[8\r\n^[7") + err := testutils.MatchPty(pty, tty, "\x1b8\r\n\x1b7") if err != nil { t.Fatalf("NewRow output error: %v", err) } @@ -107,7 +107,7 @@ func TestConsole_OutputTo(t *testing.T) { c.OutputTo(1, "test string") - err := testutils.MatchPty(pty, tty, "^[8^[[1Ftest string^[[0m\r\n^[[0K") + err := testutils.MatchPty(pty, tty, "\x1b8\x1b[1Ftest string\x1b[0m\r\n\x1b[0K") if err != nil { t.Fatalf("OutputTo output error: %v", err) } @@ -118,7 +118,7 @@ func TestConsole_Restore(t *testing.T) { c.Restore() - err := testutils.MatchPty(pty, tty, "^[8^[[0G^[[2K^[[?25h") + err := testutils.MatchPty(pty, tty, "\x1b8\x1b[0G\x1b[2K\x1b[?25h") if err != nil { t.Fatalf("Restore output error: %v", err) } @@ -129,7 +129,7 @@ func TestConsole_Save(t *testing.T) { c.Save() - err := testutils.MatchPty(pty, tty, "^[[?25l^[7^[[0m") + err := testutils.MatchPty(pty, tty, "\x1b[?25l\x1b7\x1b[0m") if err != nil { t.Fatalf("Save output error: %v", err) } diff --git a/internal/testutils/console.go b/internal/testutils/console.go index 1691da1b4..5d26674c7 100644 --- a/internal/testutils/console.go +++ b/internal/testutils/console.go @@ -50,8 +50,8 @@ func MatchPty(pty containerd.Console, device *os.File, expected ...string) error defer wg.Done() _, _ = io.Copy(&buffer, pty) }() - wg.Wait() device.Close() + wg.Wait() return OrderedMatch(buffer.String(), expected...) }