From 8636b76257881c187dc9203db944b38ee0b75c26 Mon Sep 17 00:00:00 2001 From: ytimocin Date: Tue, 12 Nov 2024 15:33:26 -0800 Subject: [PATCH] Unskipping tea tests and adding protection around possible nil models Signed-off-by: ytimocin --- pkg/cli/cmd/deploy/deploy_test.go | 1 - pkg/cli/cmd/radinit/display_test.go | 7 +++-- pkg/cli/prompt/text/text_test.go | 43 ++++++++++++++++++++--------- 3 files changed, 35 insertions(+), 16 deletions(-) diff --git a/pkg/cli/cmd/deploy/deploy_test.go b/pkg/cli/cmd/deploy/deploy_test.go index 30635aa8665..954b5e8a4d9 100644 --- a/pkg/cli/cmd/deploy/deploy_test.go +++ b/pkg/cli/cmd/deploy/deploy_test.go @@ -527,7 +527,6 @@ func Test_Run(t *testing.T) { }) t.Run("Deployment with missing parameters", func(t *testing.T) { - //t.Skip() ctrl := gomock.NewController(t) defer ctrl.Finish() diff --git a/pkg/cli/cmd/radinit/display_test.go b/pkg/cli/cmd/radinit/display_test.go index 0a2d25c03af..8f5d6b58d22 100644 --- a/pkg/cli/cmd/radinit/display_test.go +++ b/pkg/cli/cmd/radinit/display_test.go @@ -35,8 +35,6 @@ var ( ) func Test_summaryModel(t *testing.T) { - t.Skip("Test is flaky. See: https://github.com/radius-project/radius/issues/8044") - waitForRender := func(t *testing.T, reader io.Reader) string { normalized := "" teatest.WaitFor(t, reader, func(bts []byte) bool { @@ -50,6 +48,11 @@ func Test_summaryModel(t *testing.T) { waitForEmpty := func(t *testing.T, reader io.Reader) string { normalized := "" teatest.WaitFor(t, reader, func(bts []byte) bool { + if bts == nil { + t.Log("Received nil bytes; continuing to wait") + return false + } + normalized = stripansi.Strip(strings.ReplaceAll(string(bts), "\r\n", "\n")) return !strings.Contains(normalized, strings.Trim(summaryFooter, "\n")) }, teatest.WithDuration(waitTimeout)) diff --git a/pkg/cli/prompt/text/text_test.go b/pkg/cli/prompt/text/text_test.go index 268998e569f..f197172aa10 100644 --- a/pkg/cli/prompt/text/text_test.go +++ b/pkg/cli/prompt/text/text_test.go @@ -122,35 +122,52 @@ func Test_E2E(t *testing.T) { }) t.Run("confirm default", func(t *testing.T) { - t.Skip("This test is intermittently failing in linux_amd64: https://github.com/radius-project/radius/issues/7670") tm := setup(t) - tm.Send(tea.KeyMsg{Type: tea.KeyEnter}) + tm.WaitFinished(t, teatest.WithFinalTimeout(waitTimeout)) + + finalModel := tm.FinalModel(t) + require.NotNil(t, finalModel, "Final model should not be nil") + + model, ok := finalModel.(Model) + require.True(t, ok, "Final model should be of type Model") - require.True(t, tm.FinalModel(t).(Model).valueEntered) - require.False(t, tm.FinalModel(t).(Model).Quitting) - require.Equal(t, defaultText, tm.FinalModel(t).(Model).GetValue()) + require.True(t, model.valueEntered) + require.False(t, model.Quitting) + require.Equal(t, defaultText, model.GetValue()) }) t.Run("confirm value", func(t *testing.T) { const userInputText = "abcd" tm := setup(t) - tm.Type(userInputText) tm.Send(tea.KeyMsg{Type: tea.KeyEnter}) + tm.WaitFinished(t, teatest.WithFinalTimeout(waitTimeout)) + + finalModel := tm.FinalModel(t) + require.NotNil(t, finalModel, "Final model should not be nil") - require.True(t, tm.FinalModel(t).(Model).valueEntered) - require.False(t, tm.FinalModel(t).(Model).Quitting) - require.Equal(t, userInputText, tm.FinalModel(t).(Model).GetValue()) + model, ok := finalModel.(Model) + require.True(t, ok, "Final model should be of type Model") + + require.True(t, model.valueEntered) + require.False(t, model.Quitting) + require.Equal(t, userInputText, model.GetValue()) }) t.Run("cancel", func(t *testing.T) { tm := setup(t) - tm.Send(tea.KeyMsg{Type: tea.KeyCtrlC}) + tm.WaitFinished(t, teatest.WithFinalTimeout(waitTimeout)) + + finalModel := tm.FinalModel(t) + require.NotNil(t, finalModel, "Final model should not be nil") + + model, ok := finalModel.(Model) + require.True(t, ok, "Final model should be of type Model") - require.False(t, tm.FinalModel(t).(Model).valueEntered) - require.True(t, tm.FinalModel(t).(Model).Quitting) - require.Equal(t, defaultText, tm.FinalModel(t).(Model).GetValue()) + require.False(t, model.valueEntered) + require.True(t, model.Quitting) + require.Equal(t, defaultText, model.GetValue()) }) }