Skip to content

test(850): add tests for git-bug comment edit has no effect#855

Merged
smoyer64 merged 6 commits intomasterfrom
fix-850-ineffective-comment-edit
Aug 23, 2022
Merged

test(850): add tests for git-bug comment edit has no effect#855
smoyer64 merged 6 commits intomasterfrom
fix-850-ineffective-comment-edit

Conversation

@smoyer64
Copy link
Copy Markdown
Collaborator

This PR continues the work of adding unit tests to the CLI commands with the aim of solving the issue with the git-bug comment edit command not being recognized (#850). These tests have a bit of logging that should be removed before this PR is merged.

@smoyer64 smoyer64 marked this pull request as draft August 19, 2022 17:25
@MichaelMure
Copy link
Copy Markdown
Contributor

These tests have a bit of logging that should be removed before this PR is merged.

Reminds me, I think your previous PR had some logging as well. Should we remove those? It makes the test output a bit hard to parse.

@smoyer64
Copy link
Copy Markdown
Collaborator Author

smoyer64 commented Aug 19, 2022

Reminds me, I think your previous PR had some logging as well. Should we remove those? It makes the test output a bit hard to parse.

The tests do indeed result in output to stdout/stderr but it's a side-effect of the tests. Right now, you can't redirect either of those io.Writers in "core" so each time I create repositories for the tests, there are two new lines written (I'm not reusing the same repository for all the tests as that will make it hard to use t.Parallel() in the future.

Ignoring the extra logging I mentioned above and the failed test's output, running the CLI tests results in output like this:

Building identity cache... Done.
Building bug cache... Done.
Building identity cache... Done.
Building bug cache... Done.
Building identity cache... Done.
Building bug cache... Done.
Building identity cache... Done.
Building bug cache... Done.
Building identity cache... Done.
Building bug cache... Done.
Building identity cache... Done.
Building bug cache... Done.
Building identity cache... Done.
Building bug cache... Done.
Building identity cache... Done.
Building bug cache... Done.
Building identity cache... Done.
Building bug cache... Done.
Building identity cache... Done.
Building bug cache... Done.
Building identity cache... Done.
Building bug cache... Done.

Every time I add a test, there are two more lines and so it's been getting more annoying as more of the CLI has test coverage. I haven't really started covering the error paths yet! A couple days ago, I created #849 to address this in the "core" - that will result quiet (passing) tests when there's a failure or when the -v flag is used.

@MichaelMure
Copy link
Copy Markdown
Contributor

The tests do indeed result in output to stdout/stderr but it's a side-effect of the tests.

Now that I am on a computer ... I was actually thinking about this one: https://github.com/MichaelMure/git-bug/blob/master/commands/ls_test.go#L80

Regarding this specific issue, it might be something I noticed a while back in #664 but hasn't been merged yet: https://github.com/MichaelMure/git-bug/pull/664/files?show-deleted-files=true&show-viewed-files=true&file-filters%5B%5D=#diff-8ad691e03338c49c8ea10285bf2a59172fc5b230f161292b92931a66c06b5f6aR275-R282

I don't remember exactly why I made that change, but it looks like the combined Id need to be resolved to a comment/operation Id first. If the Id is incorrect, the operation will silently do nothing when applying as it's considered invalid.

@smoyer64
Copy link
Copy Markdown
Collaborator Author

smoyer64 commented Aug 19, 2022

Ugh ... you're right! That logging should have been removed but since it's a t.Log() I needed to use the v flag to see it (unless the test fails). Fixed in 2c2c449.

@smoyer64
Copy link
Copy Markdown
Collaborator Author

From what you've described, I think the following code (to be removed from the test) should be working:

	// TODO: remove this comment and everything between the "snip"
	//       comments when issue #850 is resolved.

	// ***** snip *****
	cache, err := env.env.backend.ResolveBugPrefix(bugID)
	require.NoError(t, err)
	bu, err := bug.Read(env.env.repo, cache.Id())
	require.NoError(t, err)
	for _, op := range bu.Operations() {
		t.Log("Operation: ", op)
	}
	t.Log("Compiled comments: ", bu.Compile().Comments)
	// ***** snip *****

Let me know if you see something that could be improved for debugging purposes!

@smoyer64 smoyer64 changed the title fix(850): resolves git-bug comment edit has no effect test(850): add tests for git-bug comment edit has no effect Aug 23, 2022
@smoyer64
Copy link
Copy Markdown
Collaborator Author

@MichaelMure - The problem described in #850 (git-bug comment edit has no effect) was closed by #664 so I've updated this PR to simply provide tests for the CLI comment add and comment edit commands.

@smoyer64 smoyer64 assigned smoyer64 and unassigned MichaelMure Aug 23, 2022
@smoyer64 smoyer64 requested a review from MichaelMure August 23, 2022 15:51
@MichaelMure MichaelMure marked this pull request as ready for review August 23, 2022 16:05
@smoyer64 smoyer64 merged commit ccb71fe into master Aug 23, 2022
@smoyer64 smoyer64 deleted the fix-850-ineffective-comment-edit branch August 23, 2022 18:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants