Skip to content

Commit

Permalink
Unskipping tea tests and adding protection around possible nil models
Browse files Browse the repository at this point in the history
Signed-off-by: ytimocin <[email protected]>
  • Loading branch information
ytimocin committed Nov 13, 2024
1 parent dcd669a commit 8636b76
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 16 deletions.
1 change: 0 additions & 1 deletion pkg/cli/cmd/deploy/deploy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
7 changes: 5 additions & 2 deletions pkg/cli/cmd/radinit/display_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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))
Expand Down
43 changes: 30 additions & 13 deletions pkg/cli/prompt/text/text_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
})
}

0 comments on commit 8636b76

Please sign in to comment.