From 4b689f6a9c7d116cc6d3e2549ba3b9ad6f45110f Mon Sep 17 00:00:00 2001 From: Lena Fuhrimann <6780471+cloudlena@users.noreply.github.com> Date: Fri, 9 Jun 2023 22:32:02 +0200 Subject: [PATCH] Allow to set verbose flag --- internal/livelint/check_can_access_app.go | 1 - internal/livelint/checks_model.go | 3 +- internal/livelint/interaction.go | 7 ++++- internal/livelint/mock_ui_test.go | 37 +++++++++++++++++++++++ internal/livelint/run_checks.go | 7 +++-- 5 files changed, 49 insertions(+), 6 deletions(-) diff --git a/internal/livelint/check_can_access_app.go b/internal/livelint/check_can_access_app.go index 9df7690..fa5118a 100644 --- a/internal/livelint/check_can_access_app.go +++ b/internal/livelint/check_can_access_app.go @@ -59,7 +59,6 @@ func (n *Livelint) canPortForward(pod apiv1.Pod, port int32, checkFunc func(uint handleConnectionError := func(err error) { connectionSuccessful = false } - // nolint:reassign runtime.ErrorHandlers = append(runtime.ErrorHandlers, handleConnectionError) // prepare the port forwarding diff --git a/internal/livelint/checks_model.go b/internal/livelint/checks_model.go index 030c6bb..47b6db6 100644 --- a/internal/livelint/checks_model.go +++ b/internal/livelint/checks_model.go @@ -97,7 +97,6 @@ func (m Model) View() string { return doc.String() } -// nolint:ireturn func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { switch msg := msg.(type) { case tea.KeyMsg: @@ -224,7 +223,7 @@ type check struct { outcome summaryMsg } -func initalizeStatus(context string) statusMsg { +func initializeStatus(context string) statusMsg { return statusMsg{context: context, checks: []check{}} } diff --git a/internal/livelint/interaction.go b/internal/livelint/interaction.go index 7bd9fa0..b4515da 100644 --- a/internal/livelint/interaction.go +++ b/internal/livelint/interaction.go @@ -13,6 +13,7 @@ type UserInteraction interface { DisplayCheckCompletion(completionMsg string, kind SummaryType) DisplayError(errorMsg error) AskYesNo(question string) bool + SetVerbose() StartSpinner() StopSpinner() } @@ -37,7 +38,7 @@ func (ui *BubbleteaUI) AskYesNo(question string) bool { } func (ui *BubbleteaUI) DisplayContext(contextMsg string) { - ui.statusMsg = initalizeStatus(contextMsg) + ui.statusMsg = initializeStatus(contextMsg) ui.Send(ui.statusMsg) } @@ -60,6 +61,10 @@ func (ui *BubbleteaUI) DisplayError(errorMsg error) { ui.Send(errMsg{err: errorMsg}) } +func (ui *BubbleteaUI) SetVerbose() { + ui.Send(verboseMsg{verbose: true}) +} + func (ui *BubbleteaUI) StartSpinner() { ui.Send(showSpinnerMsg{showing: true}) } diff --git a/internal/livelint/mock_ui_test.go b/internal/livelint/mock_ui_test.go index eda59e9..0ad8007 100644 --- a/internal/livelint/mock_ui_test.go +++ b/internal/livelint/mock_ui_test.go @@ -36,6 +36,9 @@ var _ livelint.UserInteraction = &UserInteractionMock{} // DisplayErrorFunc: func(errorMsg error) { // panic("mock out the DisplayError method") // }, +// SetVerboseFunc: func() { +// panic("mock out the SetVerbose method") +// }, // StartSpinnerFunc: func() { // panic("mock out the StartSpinner method") // }, @@ -67,6 +70,9 @@ type UserInteractionMock struct { // DisplayErrorFunc mocks the DisplayError method. DisplayErrorFunc func(errorMsg error) + // SetVerboseFunc mocks the SetVerbose method. + SetVerboseFunc func() + // StartSpinnerFunc mocks the StartSpinner method. StartSpinnerFunc func() @@ -107,6 +113,9 @@ type UserInteractionMock struct { // ErrorMsg is the errorMsg argument value. ErrorMsg error } + // SetVerbose holds details about calls to the SetVerbose method. + SetVerbose []struct { + } // StartSpinner holds details about calls to the StartSpinner method. StartSpinner []struct { } @@ -120,6 +129,7 @@ type UserInteractionMock struct { lockDisplayCheckStart sync.RWMutex lockDisplayContext sync.RWMutex lockDisplayError sync.RWMutex + lockSetVerbose sync.RWMutex lockStartSpinner sync.RWMutex lockStopSpinner sync.RWMutex } @@ -320,6 +330,33 @@ func (mock *UserInteractionMock) DisplayErrorCalls() []struct { return calls } +// SetVerbose calls SetVerboseFunc. +func (mock *UserInteractionMock) SetVerbose() { + if mock.SetVerboseFunc == nil { + panic("UserInteractionMock.SetVerboseFunc: method is nil but UserInteraction.SetVerbose was just called") + } + callInfo := struct { + }{} + mock.lockSetVerbose.Lock() + mock.calls.SetVerbose = append(mock.calls.SetVerbose, callInfo) + mock.lockSetVerbose.Unlock() + mock.SetVerboseFunc() +} + +// SetVerboseCalls gets all the calls that were made to SetVerbose. +// Check the length with: +// +// len(mockedUserInteraction.SetVerboseCalls()) +func (mock *UserInteractionMock) SetVerboseCalls() []struct { +} { + var calls []struct { + } + mock.lockSetVerbose.RLock() + calls = mock.calls.SetVerbose + mock.lockSetVerbose.RUnlock() + return calls +} + // StartSpinner calls StartSpinnerFunc. func (mock *UserInteractionMock) StartSpinner() { if mock.StartSpinnerFunc == nil { diff --git a/internal/livelint/run_checks.go b/internal/livelint/run_checks.go index ebaab83..a0bedd5 100644 --- a/internal/livelint/run_checks.go +++ b/internal/livelint/run_checks.go @@ -5,7 +5,7 @@ import ( ) // RunChecks checks for potential issues with a deployment. -func (n *Livelint) RunChecks(namespace, deploymentName string, isVerbose bool) error { +func (n *Livelint) RunChecks(namespace, deploymentName string, verbose bool) error { if namespace == "" { return fmt.Errorf("error running checks: %w", errNamespaceUndefined) } @@ -13,8 +13,11 @@ func (n *Livelint) RunChecks(namespace, deploymentName string, isVerbose bool) e return errDeploymentNameUndefined } - // nolint:govet n.ui.DisplayContext(fmt.Sprintf("Checking Deployment %q in Namespace %q", deploymentName, namespace)) + if verbose { + n.ui.SetVerbose() + } + n.ui.DisplayCheckStart("Checking Pods") allPods, err := n.getDeploymentPods(namespace, deploymentName)