Skip to content

Commit

Permalink
Purposely set the log level to 0 in the integration tests
Browse files Browse the repository at this point in the history
This is to check that the welcoming messages are the first
to be displayed to the end users.

Ideally, changing the log level would be done right at the
command level in each of those tests (e.g.:, odo init -v 0),
but this unfortunately cannot be done at this time due to [1].

[1] redhat-developer#5513
  • Loading branch information
rm3l committed Mar 4, 2022
1 parent 45a4ff0 commit c4835b2
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
7 changes: 6 additions & 1 deletion tests/helper/helper_interactive.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ type Tester func(*expect.Console, *bytes.Buffer)

// RunInteractive runs the command in interactive mode and returns the output, and error.
// It takes command as array of strings, and a function `tester` that contains steps to run the test as an argument.
func RunInteractive(command []string, tester Tester) (string, error) {
// The command is executed as a separate process, the environment of which is controlled via the `env` argument.
// If `env` is `nil`, the command inherits the environment of the current process.
func RunInteractive(command []string, env []string, tester Tester) (string, error) {

ptm, pts, err := pty.Open()
if err != nil {
Expand All @@ -40,6 +42,9 @@ func RunInteractive(command []string, tester Tester) (string, error) {
cmd.Stdin = c.Tty()
cmd.Stdout = c.Tty()
cmd.Stderr = c.Tty()
if env != nil {
cmd.Env = env
}
err = cmd.Start()
if err != nil {
log.Fatal(err)
Expand Down
9 changes: 7 additions & 2 deletions tests/integration/interactive/cmd_init_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ var _ = Describe("odo init interactive command tests", func() {
It("should download correct devfile", func() {

command := []string{"odo", "init"}
output, err := helper.RunInteractive(command, func(c *expect.Console, output *bytes.Buffer) {
output, err := helper.RunInteractive(command, nil, func(c *expect.Console, output *bytes.Buffer) {

res := helper.ExpectString(c, "Select language")
fmt.Fprintln(output, res)
Expand Down Expand Up @@ -104,7 +104,12 @@ var _ = Describe("odo init interactive command tests", func() {

testRunner := func(language string, welcomingMsgs []string, tester helper.Tester) (string, error) {
command := []string{"odo", "init"}
return helper.RunInteractive(command, testFunc(language, welcomingMsgs, tester))
return helper.RunInteractive(command,
// Setting verbosity level to 0, because we would be asserting the welcoming message is the first
// message displayed to the end user. So we do not want any potential debug lines to be printed first.
// Using envvars here (and not via the -v flag), because of https://github.com/redhat-developer/odo/issues/5513
[]string{"ODO_LOG_LEVEL=0"},
testFunc(language, welcomingMsgs, tester))
}

When("directory is empty", func() {
Expand Down

0 comments on commit c4835b2

Please sign in to comment.