New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(tests): Refactored go-expect tests to support better error reporting #2298

Merged
merged 1 commit into from Nov 22, 2018

Conversation

Projects
None yet
6 participants
@agentgonzo
Copy link
Member

agentgonzo commented Nov 21, 2018

Submitter checklist

  • Change is code complete and matches issue description.
  • Change is covered by existing or new tests.

Description

This refactors the go-expect tests by hiding the actual console behind a wrapper. The wrapper will automatically assert that there are no errors as a result of the Expect clauses (previously almost-all errors were not assigned to any variable and just discarded).

Previously, if a go-expect test failed, the output would be:

panic: Test: TestUninstallOptions_Run_ContextSpecifiedViaCli_FailsWhenContextNamesDoNotMatch Timeout waiting for Terminal output: "\x1b[0G\x1b[2K\x1b[1;92m? \x1b[0m\x1b[1;99mEnter the current context name to confirm uninstalllation of the Jenkins X platform from the ns namespace: \x1b[0m\x1b[36m[? for help]\x1b[0m \x1b[?25l\x1b7\x1b[999;999f\x1b[6n\x1b8\x1b[?25h"

goroutine 56 [running]:
github.com/jenkins-x/jx/pkg/tests.expectNoTimeoutError.func1(0x0, 0x0, 0xc0005543c0, 0xbf, 0x204d4c0, 0xc000177b60)
        /home/steve/code/jx/jx/pkg/tests/helpers.go:122 +0x1e3
github.com/Netflix/go-expect.(*Console).Expect.func1(0xc000582840, 0xc000603ea0, 0xc000276000, 0xc000603eb0)
        /home/steve/go/pkg/mod/github.com/!netflix/go-expect@v0.0.0-20180814212900-124a37274874/expect.go:72 +0x8a
github.com/Netflix/go-expect.(*Console).Expect(0xc000582840, 0xc0000d1f70, 0x1, 0x1, 0xc000554300, 0xbf, 0x204d4c0, 0xc000177b60)
        /home/steve/go/pkg/mod/github.com/!netflix/go-expect@v0.0.0-20180814212900-124a37274874/expect.go:92 +0x85a
github.com/Netflix/go-expect.(*Console).ExpectString(0xc000582840, 0x1dc9d52, 0x1d, 0x0, 0x0, 0x0, 0x0)
        /home/steve/go/pkg/mod/github.com/!netflix/go-expect@v0.0.0-20180814212900-124a37274874/expect.go:35 +0xac
command-line-arguments_test.TestUninstallOptions_Run_ContextSpecifiedViaCli_FailsWhenContextNamesDoNotMatch.func1(0xc000538960, 0xc000582840)
        /home/steve/code/jx/jx/pkg/jx/cmd/uninstall_test.go:105 +0x6a
created by command-line-arguments_test.TestUninstallOptions_Run_ContextSpecifiedViaCli_FailsWhenContextNamesDoNotMatch
        /home/steve/code/jx/jx/pkg/jx/cmd/uninstall_test.go:103 +0xc6

With this PR, the output is now:

--- FAIL: TestUninstallOptions_Run_ContextSpecifiedViaCli_FailsWhenContextNamesDoNotMatch (1.01s)
    console_wrapper.go:24:
                Error Trace:    console_wrapper.go:24
                                                        uninstall_test.go:103
                                                        asm_amd64.s:1333
                Error:          Received unexpected error:
                                read |0: i/o timeout
                Test:           TestUninstallOptions_Run_ContextSpecifiedViaCli_FailsWhenContextNamesDoNotMatch
                Messages:       Expected string: "Expected text defined in test"
                                Actual string: "This is the actual text on the command line as returned by the jx executable"

Special notes for the reviewer(s)

The expectNoTimeoutError method has been removed because because it's no longer needed.

Which issue this PR fixes

fixes #

@agentgonzo agentgonzo requested a review from i0n Nov 21, 2018

@jenkins-x-bot jenkins-x-bot requested review from jstrachan and jtnord Nov 21, 2018

@agentgonzo

This comment has been minimized.

Copy link
Member

agentgonzo commented Nov 21, 2018

/assign @i0n

@rawlingsj

This comment has been minimized.

Copy link
Member

rawlingsj commented Nov 22, 2018

/lgtm

@jtnord

This comment has been minimized.

Copy link
Member

jtnord commented Nov 22, 2018

/lgtm

@jtnord

jtnord approved these changes Nov 22, 2018

@jenkins-x-bot

This comment has been minimized.

Copy link
Contributor

jenkins-x-bot commented Nov 22, 2018

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: jtnord, rawlingsj

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@jenkins-x-bot jenkins-x-bot merged commit 967c056 into jenkins-x:master Nov 22, 2018

3 checks passed

Hound No violations found. Woof!
serverless-jenkins succeeded
tide In merge pool.
Details

@agentgonzo agentgonzo deleted the agentgonzo:expect-output branch Nov 27, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment