Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't update survey prompt if survey prompt is not shown to stdout #6192

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions pkg/skaffold/survey/survey.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ Tip: To permanently disable the survey prompt, run:

var (
// for testing
isStdOut = output.IsStdout
open = browser.OpenURL
updateConfig = sConfig.UpdateGlobalSurveyPrompted
isStdOut = output.IsStdout
open = browser.OpenURL
updateSurveyPrompted = sConfig.UpdateGlobalSurveyPrompted
)

type Runner struct {
Expand Down Expand Up @@ -79,10 +79,11 @@ func recentlyPromptedOrTaken(cfg *sConfig.ContextConfig) bool {
}

func (s *Runner) DisplaySurveyPrompt(out io.Writer) error {
if isStdOut(out) {
output.Green.Fprintf(out, hats.prompt())
if !isStdOut(out) {
return nil
}
return updateConfig(s.configFile)
output.Green.Fprintf(out, hats.prompt())
return updateSurveyPrompted(s.configFile)
}

func (s *Runner) OpenSurveyForm(_ context.Context, out io.Writer, id string) error {
Expand Down
20 changes: 13 additions & 7 deletions pkg/skaffold/survey/survey_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,23 @@ import (

func TestDisplaySurveyForm(t *testing.T) {
tests := []struct {
description string
mockStdOut bool
expected string
description string
mockSurveyPrompted func(_ string) error
expected string
mockStdOut bool
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor tweak: mockStdOut should go above expected since it's a test input

}{
{
description: "std out",
mockStdOut: true,
description: "std out",
mockStdOut: true,
mockSurveyPrompted: func(_ string) error { return nil },
expected: `Help improve Skaffold with our 2-minute anonymous survey: run 'skaffold survey'
`,
},
{
description: "not std out",
mockSurveyPrompted: func(_ string) error {
return fmt.Errorf("not expected to call")
},
},
}
for _, test := range tests {
Expand All @@ -50,9 +55,10 @@ func TestDisplaySurveyForm(t *testing.T) {
t.Override(&isStdOut, mock)
mockOpen := func(string) error { return nil }
t.Override(&open, mockOpen)
t.Override(&updateConfig, func(_ string) error { return nil })
t.Override(&updateSurveyPrompted, test.mockSurveyPrompted)
var buf bytes.Buffer
New("test").DisplaySurveyPrompt(&buf)
err := New("test").DisplaySurveyPrompt(&buf)
t.CheckNoError(err)
t.CheckDeepEqual(test.expected, buf.String())
})
}
Expand Down