Skip to content

Commit 250fdc8

Browse files
authored
Merge pull request #645 from cloudfoundry/quiet-completion-tests
Quiet completion tests
2 parents f51e90b + f340ae5 commit 250fdc8

File tree

2 files changed

+20
-18
lines changed

2 files changed

+20
-18
lines changed

cmd/completion/completion.go

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@ func IsItCompletionCommand(args []string) bool {
2323
return len(args) > 0 && (args[0] == cobraCompletionCmdName || args[0] == cobraCompleteCmdName)
2424
}
2525

26+
type CapturedResult struct {
27+
Lines []string
28+
Command *cobra.Command
29+
}
30+
2631
type CmdContext struct {
2732
ConfigPath string
2833
EnvironmentName string
@@ -152,13 +157,17 @@ func (c *BoshComplete) Execute(args []string) (*cobra.Command, error) {
152157
}
153158

154159
func (c *BoshComplete) ExecuteCaptured(args []string) (*CapturedResult, error) {
155-
buf := new(bytes.Buffer)
156-
c.rootCmd.SetOut(buf)
160+
outBuf := &bytes.Buffer{}
161+
errBuf := &bytes.Buffer{}
162+
163+
c.rootCmd.SetOut(outBuf)
164+
c.rootCmd.SetErr(errBuf)
157165
retCmd, err := c.Execute(args)
158166
if err != nil {
159167
return nil, err
160168
}
161-
retLines := strings.Split(buf.String(), "\n")
169+
retLines := strings.Split(outBuf.String(), "\n")
170+
c.logger.Debug("BoshComplete.ExecuteCapture() STDERR", errBuf.String())
162171
return &CapturedResult{Lines: retLines, Command: retCmd}, nil
163172
}
164173

@@ -170,8 +179,3 @@ func (c *BoshComplete) tryToBindValidArgsFunction(cmd *cobra.Command, argsTypeNa
170179
c.logger.Warn(logTag, "Unknown Args Type %s, command %s", argsTypeName, cmd.Name())
171180
}
172181
}
173-
174-
type CapturedResult struct {
175-
Lines []string
176-
Command *cobra.Command
177-
}

cmd/completion/completion_test.go

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,25 @@
11
package completion_test
22

33
import (
4-
"os"
54
"strings"
65

7-
"github.com/cloudfoundry/bosh-utils/logger"
6+
boshlog "github.com/cloudfoundry/bosh-utils/logger"
87
. "github.com/onsi/ginkgo/v2"
98
. "github.com/onsi/gomega"
109

1110
"github.com/cloudfoundry/bosh-cli/v7/cmd/completion"
1211
)
1312

1413
var _ = Describe("Completion Integration Tests", func() {
15-
var (
16-
boshComplete *completion.BoshComplete
17-
)
14+
var boshComplete *completion.BoshComplete
1815

1916
BeforeEach(func() {
20-
testLogger := logger.NewWriterLogger(logger.LevelInfo, os.Stderr)
17+
testLogger := boshlog.NewWriterLogger(boshlog.LevelInfo, GinkgoWriter)
2118
fakeCmdCtx := &completion.CmdContext{}
2219
fakeDq := completion.NewDirectorQueryFake(fakeCmdCtx)
23-
fakeCompletionFunctionMap := completion.NewCompleteFunctionsMap(testLogger, fakeDq)
20+
fakeCompletionFunctionMap :=
21+
completion.NewCompleteFunctionsMap(testLogger, fakeDq)
22+
2423
boshComplete = completion.NewBoshCompleteWithFunctions(testLogger, fakeCmdCtx, fakeCompletionFunctionMap)
2524
})
2625

@@ -130,9 +129,8 @@ func (tc testCase) check(boshComplete *completion.BoshComplete) {
130129
} else {
131130
Expect(err).ToNot(HaveOccurred())
132131
}
133-
if result == nil {
134-
Expect(result).ToNot(BeNil())
135-
}
132+
Expect(result).ToNot(BeNil())
133+
136134
if tc.wantStartsWith {
137135
for i, wantLine := range tc.wantRes {
138136
Expect(wantLine).To(Equal(result.Lines[i]))

0 commit comments

Comments
 (0)