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

Fix Bug that prevents showing survey prompt #5027

Merged
merged 2 commits into from
Nov 13, 2020
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
11 changes: 10 additions & 1 deletion pkg/skaffold/color/formatter.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2019 The Skaffold Authors
Copyright 2020 The Skaffold Authors

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand All @@ -19,6 +19,7 @@ package color
import (
"fmt"
"io"
"os"
"strings"

colors "github.com/heroku/color"
Expand Down Expand Up @@ -142,3 +143,11 @@ func IsColorable(out io.Writer) bool {
return false
}
}

func IsStdout(out io.Writer) bool {
o, ok := out.(colorableWriter)
if ok {
return o.Writer == os.Stdout
}
return out == os.Stdout
}
38 changes: 37 additions & 1 deletion pkg/skaffold/color/formatter_test.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2019 The Skaffold Authors
Copyright 2020 The Skaffold Authors

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand All @@ -18,7 +18,11 @@ package color

import (
"bytes"
"io"
"os"
"testing"

"github.com/GoogleContainerTools/skaffold/testutil"
)

func compareText(t *testing.T, expected, actual string) {
Expand Down Expand Up @@ -89,3 +93,35 @@ func TestFprintlnChangeDefaultToUnknown(t *testing.T) {
Default.Fprintln(cw, "2", "less", "chars!")
compareText(t, "2 less chars!\n", b.String())
}

func TestIsStdOut(t *testing.T) {
tests := []struct {
description string
out io.Writer
expected bool
}{
{
description: "std out passed",
out: os.Stdout,
expected: true,
},
{
description: "out nil",
out: nil,
},
{
description: "out bytes buffer",
out: new(bytes.Buffer),
},
{
description: "colorable std out passed",
out: NewWriter(os.Stdout),
expected: true,
},
}
for _, test := range tests {
testutil.Run(t, test.description, func(t *testutil.T) {
t.CheckDeepEqual(test.expected, IsStdout(test.out))
})
}
}
7 changes: 1 addition & 6 deletions pkg/skaffold/survey/survey.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"context"
"fmt"
"io"
"os"

"github.com/pkg/browser"
"github.com/sirupsen/logrus"
Expand All @@ -47,7 +46,7 @@ Tip: To permanently disable the survey prompt, run:
skaffold config set --survey --global disable-prompt true`, URL)

// for testing
isStdOut = stdOut
isStdOut = color.IsStdout
open = browser.OpenURL
updateConfig = config.UpdateGlobalSurveyPrompted
)
Expand Down Expand Up @@ -82,7 +81,3 @@ func (s *Runner) OpenSurveyForm(_ context.Context, out io.Writer) error {
// When prompting for the survey, we need to use the same field.
return config.UpdateGlobalSurveyTaken(s.configFile)
}

func stdOut(out io.Writer) bool {
return out == os.Stdout
}
28 changes: 0 additions & 28 deletions pkg/skaffold/survey/survey_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package survey
import (
"bytes"
"io"
"os"
"testing"

"github.com/GoogleContainerTools/skaffold/testutil"
Expand Down Expand Up @@ -53,30 +52,3 @@ func TestDisplaySurveyForm(t *testing.T) {
})
}
}

func TestIsStdOut(t *testing.T) {
tests := []struct {
description string
out io.Writer
expected bool
}{
{
description: "std out passed",
out: os.Stdout,
expected: true,
},
{
description: "out nil",
out: nil,
},
{
description: "out bytes buffer",
out: new(bytes.Buffer),
},
}
for _, test := range tests {
testutil.Run(t, test.description, func(t *testutil.T) {
t.CheckDeepEqual(test.expected, isStdOut(test.out))
})
}
}