Skip to content

Commit 5177258

Browse files
fix: add unit test
1 parent dd8a7a1 commit 5177258

3 files changed

Lines changed: 43 additions & 1 deletion

File tree

pkg/cmd/hello/hello_test.go

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,39 @@
11
package hello
2+
3+
import "testing"
4+
5+
type shellOnboardingPollDoneCase struct {
6+
name string
7+
res *OnboardingObject
8+
want bool
9+
}
10+
11+
var shellOnboardingPollDoneCases = []shellOnboardingPollDoneCase{
12+
{
13+
name: "hasRunBrevShell",
14+
res: &OnboardingObject{HasRunBrevShell: true},
15+
want: true,
16+
},
17+
{
18+
name: "brevOpenOnly",
19+
res: &OnboardingObject{HasRunBrevOpen: true, HasRunBrevShell: false},
20+
want: false,
21+
},
22+
{
23+
name: "nil",
24+
res: nil,
25+
want: false,
26+
},
27+
}
28+
29+
func TestShellOnboardingPollDone(t *testing.T) {
30+
t.Parallel()
31+
for _, c := range shellOnboardingPollDoneCases {
32+
t.Run(c.name, func(t *testing.T) {
33+
t.Parallel()
34+
if got := shellOnboardingPollDone(c.res); got != c.want {
35+
t.Fatalf("got %v, want %v", got, c.want)
36+
}
37+
})
38+
}
39+
}

pkg/cmd/hello/onboarding_utils.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,10 @@ type OnboardingObject struct {
123123
HasRunBrevOpen bool `json:"hasRunBrevOpen"`
124124
}
125125

126+
func shellOnboardingPollDone(res *OnboardingObject) bool {
127+
return res != nil && res.HasRunBrevShell
128+
}
129+
126130
func SetupDefaultOnboardingFile() error {
127131
// get path
128132
path, err := GetOnboardingFilePath()

pkg/cmd/hello/steps.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ func doVsCodeOnboarding(
298298
if err1 != nil {
299299
return breverrors.WrapAndTrace(err1)
300300
}
301-
if res.HasRunBrevOpen {
301+
if shellOnboardingPollDone(res) {
302302
spinner.Suffix = spinnerSuffix
303303
time.Sleep(250 * time.Millisecond)
304304
spinner.Stop()

0 commit comments

Comments
 (0)