Skip to content

Commit 6bd7657

Browse files
authored
Merge pull request #3011 from tejal29/add_survey_logic
display survey prompt which points to survey url
2 parents e42e52a + 95ca068 commit 6bd7657

File tree

2 files changed

+123
-0
lines changed

2 files changed

+123
-0
lines changed

pkg/skaffold/survey/survey.go

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
Copyright 2019 The Skaffold Authors
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package survey
18+
19+
import (
20+
"io"
21+
"os"
22+
23+
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/color"
24+
)
25+
26+
const (
27+
Prompt = `Help improve Skaffold! Take a 10 seconds anonymous survey by running
28+
$skaffold survey`
29+
)
30+
31+
// for testing
32+
var (
33+
isStdOut = stdOut
34+
)
35+
36+
func DisplaySurveyForm(out io.Writer) {
37+
if isStdOut(out) {
38+
color.Default.Fprintln(out, Prompt)
39+
}
40+
}
41+
42+
func stdOut(out io.Writer) bool {
43+
return out == os.Stdout
44+
}

pkg/skaffold/survey/survey_test.go

+79
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
/*
2+
Copyright 2019 The Skaffold Authors
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package survey
18+
19+
import (
20+
"bytes"
21+
"io"
22+
"os"
23+
"testing"
24+
25+
"github.com/GoogleContainerTools/skaffold/testutil"
26+
)
27+
28+
func TestDisplaySurveyForm(t *testing.T) {
29+
tests := []struct {
30+
description string
31+
mockStdOut bool
32+
expected string
33+
}{
34+
{
35+
description: "std out",
36+
mockStdOut: true,
37+
expected: Prompt + "\n",
38+
},
39+
{
40+
description: "not std out",
41+
},
42+
}
43+
for _, test := range tests {
44+
testutil.Run(t, test.description, func(t *testutil.T) {
45+
mock := func(io.Writer) bool { return test.mockStdOut }
46+
t.Override(&isStdOut, mock)
47+
var buf bytes.Buffer
48+
DisplaySurveyForm(&buf)
49+
t.CheckDeepEqual(test.expected, buf.String())
50+
})
51+
}
52+
}
53+
54+
func TestIsStdOut(t *testing.T) {
55+
tests := []struct {
56+
description string
57+
out io.Writer
58+
expected bool
59+
}{
60+
{
61+
description: "std out passed",
62+
out: os.Stdout,
63+
expected: true,
64+
},
65+
{
66+
description: "out nil",
67+
out: nil,
68+
},
69+
{
70+
description: "out bytes buffer",
71+
out: new(bytes.Buffer),
72+
},
73+
}
74+
for _, test := range tests {
75+
testutil.Run(t, test.description, func(t *testutil.T) {
76+
t.CheckDeepEqual(test.expected, isStdOut(test.out))
77+
})
78+
}
79+
}

0 commit comments

Comments
 (0)