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 <ytimocin@microsoft.com>
  • Loading branch information
ytimocin committed Dec 15, 2024
1 parent 3383692 commit 046f346
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 37 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
42 changes: 21 additions & 21 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 @@ -47,16 +45,6 @@ func Test_summaryModel(t *testing.T) {
return normalized
}

waitForEmpty := func(t *testing.T, reader io.Reader) string {
normalized := ""
teatest.WaitFor(t, reader, func(bts []byte) bool {
normalized = stripansi.Strip(strings.ReplaceAll(string(bts), "\r\n", "\n"))
return !strings.Contains(normalized, strings.Trim(summaryFooter, "\n"))
}, teatest.WithDuration(waitTimeout))

return normalized
}

resultTest := func(t *testing.T, expected summaryResult, key tea.KeyType) {
options := initOptions{}
model := &summaryModel{
Expand All @@ -66,12 +54,18 @@ func Test_summaryModel(t *testing.T) {

waitForRender(t, tm.Output())

// Press ENTER
tm.Send(tea.KeyMsg{Type: key})
// Press the given key
tm.Send(tea.KeyMsg{
Type: key,
})

// Wait for final render and exit.
tm.WaitFinished(t, teatest.WithFinalTimeout(waitTimeout))
waitForEmpty(t, tm.FinalOutput(t))
if err := tm.Quit(); err != nil {
t.Fatal(err)
}

// FinalModel only returns once the program has finished running or when it times out.
// Please see: https://github.com/charmbracelet/x/blob/20117e9c8cd5ad229645f1bca3422b7e4110c96c/exp/teatest/teatest.go#L220.
// That is why we call tm.Quit() before tm.FinalModel().
model = tm.FinalModel(t).(*summaryModel)
require.Equal(t, expected, model.result)
}
Expand All @@ -98,11 +92,17 @@ func Test_summaryModel(t *testing.T) {
assert.Equal(t, expected, output)

// Press ENTER
tm.Send(tea.KeyMsg{Type: tea.KeyEnter})
tm.Send(tea.KeyMsg{
Type: tea.KeyEnter,
})

if err := tm.Quit(); err != nil {
t.Fatal(err)
}

// Wait for final render and exit.
tm.WaitFinished(t, teatest.WithFinalTimeout(waitTimeout))
waitForEmpty(t, tm.FinalOutput(t))
// FinalModel only returns once the program has finished running or when it times out.
// Please see: https://github.com/charmbracelet/x/blob/20117e9c8cd5ad229645f1bca3422b7e4110c96c/exp/teatest/teatest.go#L220.
// That is why we call tm.Quit() before tm.FinalModel().
model = tm.FinalModel(t).(*summaryModel)
assert.Equal(t, summaryResult(resultConfimed), model.result)
}
Expand Down
61 changes: 46 additions & 15 deletions pkg/cli/prompt/text/text_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ func validateNewTextModel(t *testing.T, model *Model, options *TextModelOptions)
}

func Test_E2E(t *testing.T) {

const expectedPrompt = "\r" + testPrompt + "\n" +
"\n" +
"> " + testPlaceholder + "\n" +
Expand Down Expand Up @@ -122,35 +121,67 @@ 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,
})

if err := tm.Quit(); err != nil {
t.Fatal(err)
}

tm.Send(tea.KeyMsg{Type: tea.KeyEnter})
// FinalModel only returns once the program has finished running or when it times out.
// Please see: https://github.com/charmbracelet/x/blob/20117e9c8cd5ad229645f1bca3422b7e4110c96c/exp/teatest/teatest.go#L220.
// That is why we call tm.Quit() before tm.FinalModel().
model, ok := tm.FinalModel(t).(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.Send(tea.KeyMsg{
Type: tea.KeyEnter,
})

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())
if err := tm.Quit(); err != nil {
t.Fatal(err)
}

// FinalModel only returns once the program has finished running or when it times out.
// Please see: https://github.com/charmbracelet/x/blob/20117e9c8cd5ad229645f1bca3422b7e4110c96c/exp/teatest/teatest.go#L220.
// That is why we call tm.Quit() before tm.FinalModel().
model, ok := tm.FinalModel(t).(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,
})

if err := tm.Quit(); err != nil {
t.Fatal(err)
}

tm.Send(tea.KeyMsg{Type: tea.KeyCtrlC})
// FinalModel only returns once the program has finished running or when it times out.
// Please see: https://github.com/charmbracelet/x/blob/20117e9c8cd5ad229645f1bca3422b7e4110c96c/exp/teatest/teatest.go#L220.
// That is why we call tm.Quit() before tm.FinalModel().
model, ok := tm.FinalModel(t).(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 046f346

Please sign in to comment.