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
convert sync tests to go #1389
convert sync tests to go #1389
Conversation
# Conflicts: # Makefile
In case it helps, since there are so many sync tests, it might be more manageable to do one pull request per subdirectory. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@charlierudolph I really don't know how you always do this and am in awe. You have converted at least as many specs as I have over the last months, but you did in a couple of days. Some suggestions below, curious what you think.
@@ -61,6 +61,13 @@ func (builder *CommitTableBuilder) Add(commit Commit, location string) { | |||
} | |||
} | |||
|
|||
// AddMany registers the given commits from the given location into this table. | |||
func (builder *CommitTableBuilder) AddMany(commits []Commit, location string) { | |||
for _, commit := range commits { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This type of loop creates a copy of the current commit in each loop iteration. Which is fine for small values like when iterating lists of int
. Commits are, however, pretty large objects that consist of several strings. Here is a version that uses the commits in the list, i.e. avoids making a copy:
for c := range commits {
builder.Add(commits[c], location)
}
Probably not particularly relevant in this context, just wanted to share.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense. Hmm, would using an array of commit pointers be equivalent in efficiency? If so, I think I'd prefer we switch to that
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd prefer to not switch to pointers for everything. They have other side effects like additional indirection on access (=slowness), and possibly more work for the garbage collector. Plus, on 64 bit systems pointers require an additional 8 bytes for every entry.
I think it's better to use the loop it was designed in Go: with the loop index as the primary element, and using the optional copy of the current item only when that makes sense.
err = result.DeveloperRepo.Fetch() | ||
if err != nil { | ||
return &result, fmt.Errorf("cannot fetch: %w", err) | ||
for _, repo := range []GitRepository{result.DeveloperRepo, result.CoworkerRepo} { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since coworker repos are extremely rarely used, what do you think about creating them only when needed? This could be done via an AddCoworker
method of GitEnvironment
, similar to AddUpstream.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good
func (env GitEnvironment) CreateTags(table *messages.PickleStepArgument_PickleTable) error { | ||
columnNames := helpers.TableFields(table) | ||
if columnNames[0] != "NAME" && columnNames[1] != "LOCATION" { | ||
return fmt.Errorf("tag table must have columns NAME and LOCATION") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice that you do this check and provide a helpful error message!
@@ -279,6 +298,15 @@ func (repo *GitRepository) CurrentBranch() (result string, err error) { | |||
return strings.TrimSpace(outcome.OutputSanitized()), nil | |||
} | |||
|
|||
// CurrentFileContent provides the current content of a file. | |||
func (repo *GitRepository) CurrentFileContent(filename string) (result string, err error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thoughts about naming this FileContent
? We already have FileContentInCommit(she, filename)
, FilesInCommit(sha)
, and FilesInBranch
. I think a FileContent
method fits naturally in here, and the name makes clear that this is the content of the given file in the given repo.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay that works
if err != nil { | ||
return result, fmt.Errorf("cannot determine files in branch %q in repo %q: %w", branch, repo.Dir, err) | ||
} | ||
for _, line := range strings.Split(strings.TrimSpace(outcome.OutputSanitized()), "\n") { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FYI Result.OutputSanitized already runs strings.TrimSpace
on the output. Since this is wrong in a lot of my code as well (and you probably followed it as a reference here), I am cleaning this up in #1403, so nothing to do here except to accept my apologies.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the cleanup!
|
||
// TagSteps defines Gherkin step implementations around merges. | ||
func TagSteps(suite *godog.Suite, fs *FeatureState) { | ||
suite.Step(`^I have the following tags$`, func(table *messages.PickleStepArgument_PickleTable) error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
People don't have tags 🙂 Thoughts about renaming this to my repo has the following tags
? Also okay to do efficiently as a search-and-replace once the conversion is done.
@@ -0,0 +1,61 @@ | |||
package test |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typo in filename tag_table_bulider.go
result := TagTableBuilder{ | ||
tagToLocations: make(map[string]helpers.OrderedStringSet), | ||
} | ||
return result |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could inline the result
variable.
|
||
// AddMany registers the given tags from the given location into this table. | ||
func (builder *TagTableBuilder) AddMany(tags []string, location string) { | ||
for _, tag := range tags { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider more efficient loop here.
// Table provides the data accumulated by this TagTableBuilder as a DataTable. | ||
func (builder *TagTableBuilder) Table() (result DataTable) { | ||
result.AddRow("NAME", "LOCATION") | ||
tags := make([]string, len(builder.tagToLocations)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice preallocation at the correct length!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Linter made me do it haha
Opening for visibility, not ready for review