-
Notifications
You must be signed in to change notification settings - Fork 76
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
We should refactor the agent cli output (#311)
* We should refactor the agent cli output Signed-off-by: chen hui <[email protected]>
- Loading branch information
1 parent
26b4bc2
commit a01750c
Showing
3 changed files
with
68 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// Copyright 2021 VMware, Inc. All Rights Reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package main | ||
|
||
import ( | ||
"os/exec" | ||
"strings" | ||
|
||
. "github.com/onsi/ginkgo" | ||
. "github.com/onsi/gomega" | ||
"github.com/onsi/gomega/gexec" | ||
) | ||
|
||
var _ = Describe("Help flag for host agent", func() { | ||
Context("When the help flag is provided", func() { | ||
var ( | ||
expectedOptions = []string{ | ||
"-downloadpath string", | ||
"-kubeconfig string", | ||
"-label value", | ||
"-metricsbindaddress string", | ||
"-namespace string", | ||
"-skip-installation", | ||
} | ||
) | ||
|
||
It("should output the expected option", func() { | ||
command := exec.Command(pathToHostAgentBinary, "--help") | ||
session, err := gexec.Start(command, GinkgoWriter, GinkgoWriter) | ||
Expect(err).NotTo(HaveOccurred()) | ||
Eventually(session, "5s").Should(gexec.Exit(0)) | ||
|
||
output := string(session.Err.Contents()) | ||
for _, line := range strings.Split(strings.TrimRight(output, "\n"), "\n") { | ||
line = strings.TrimSpace(line) | ||
if !strings.HasPrefix(line, "-") { | ||
continue | ||
} | ||
// Any option not belongs to expectedOptions is not allowed. | ||
Expect(line).To(BeElementOf(expectedOptions)) | ||
} | ||
|
||
}) | ||
|
||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters