Skip to content
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

issue view tests fails after 2021-01-23 #2841

Closed
cristiand391 opened this issue Jan 25, 2021 · 3 comments · Fixed by #2843
Closed

issue view tests fails after 2021-01-23 #2841

cristiand391 opened this issue Jan 25, 2021 · 3 comments · Fixed by #2843
Labels
bug Something isn't working

Comments

@cristiand391
Copy link
Contributor

cristiand391 commented Jan 25, 2021

Describe the bug

The current implementation of issue view tests doesn't mock the current time and makes test fail after 2021-01-23.

Steps to reproduce the behavior

  1. Clone cli/cli
  2. Type go test ./pkg/cmd/issue/view
  3. See
FAIL: TestIssueView_tty_Preview (0.00s)
    --- FAIL: TestIssueView_tty_Preview/Open_issue_with_empty_body (0.00s)
        view_test.go:267: output did not match regexp /Open.*marseilles opened about 9 years ago.*9 comments/
            > output
            ix of coins
            Open • marseilles opened about 10 years ago • 9 comments
            Labels: tarot

These tests started to fail 2 days ago because the dates in the test fixtures point to 2011-01-26

"createdAt": "2011-01-26T19:01:12Z",
, which makes
func printHumanIssuePreview(opts *ViewOptions, issue *api.Issue) error {
out := opts.IO.Out
now := time.Now()
ago := now.Sub(issue.CreatedAt)

output:
Open • marseilles opened about 10 years ago • 9 comments
instead of:
Open • marseilles opened about 9 years ago • 9 comments.

See: https://github.com/cli/cli/pull/2839/checks?check_run_id=1758707814#step:5:55

@cristiand391 cristiand391 added the bug Something isn't working label Jan 25, 2021
@cristiand391
Copy link
Contributor Author

I've tested the approach explained here: https://smartystreets.com/blog/2015/09/go-testing-part-5-testing-with-time and works as expected, but this can be easily fixed by changing the dates in test fixtures too.

See cristiand391@8ef5cfe

@mislav
Copy link
Contributor

mislav commented Jan 25, 2021

@cristiand391 Thank you for the report and for the proposed fix!

We used to take the overridable func approach in the past, but recently we avoid that approach since it doesn't lend itself well to parallel tests. We don't execute our tests in parallel yet, but we might want to do so in the future. I've opened a PR with an approach that freezes the current time per command run.

@cristiand391
Copy link
Contributor Author

No worries. Thanks for the quick fix!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants