Repository navigation
fix: stop get trail table output panicking on partial commit info #1365
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
Merged
+93
−8
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
55db21f
Show missing commit fields as N/A in get trail table output
tooky 8777215
no-mistakes(test): Hide url row when commit url is null or empty
tooky 84b2cec
Show missing commit author and message as N/A in get trail markdown o…
tooky 04ff10b
Match get trail table test output with regexps instead of fixed padding
tooky f31f718
no-mistakes(ci): The markdown Sha1 cell now shows N/A when sha1 is mi…
tooky File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| package main | ||
|
|
||
| import ( | ||
| "bytes" | ||
| "testing" | ||
|
|
||
| "github.com/stretchr/testify/require" | ||
| ) | ||
|
|
||
| // TestPrintTrailAsTableCommitInfo checks that the table renderer tolerates | ||
| // commit info with only some of its fields, which the API accepts for trails. | ||
| func TestPrintTrailAsTableCommitInfo(t *testing.T) { | ||
| t.Setenv("KOSLI_TESTS", "true") // makes formattedTimestamp use a fixed time | ||
|
|
||
| for _, tc := range []struct { | ||
| name string | ||
| commitInfo string | ||
| want []string | ||
| notWant []string | ||
| }{ | ||
| { | ||
| name: "only sha1", | ||
| commitInfo: `{"sha1": "abc1234def"}`, | ||
| want: []string{`Sha1:\s+abc1234def`, `Author:\s+N/A`, `Timestamp:\s+N/A`, `message:\s+N/A`}, | ||
|
tooky marked this conversation as resolved.
Resolved
|
||
| }, | ||
| { | ||
| name: "sha1 and branch", | ||
| commitInfo: `{"sha1": "abc1234def", "branch": "main"}`, | ||
| want: []string{"abc1234def", `Author:\s+N/A`, `Timestamp:\s+N/A`, `message:\s+N/A`}, | ||
| }, | ||
| { | ||
| // the server returns absent commit fields as explicit nulls | ||
| name: "only sha1 with null fields", | ||
| commitInfo: `{"sha1": "abc1234def", "message": null, "author": null, "branch": null, "timestamp": null, "url": null}`, | ||
| want: []string{`Sha1:\s+abc1234def`, `Author:\s+N/A`, `Timestamp:\s+N/A`, `message:\s+N/A`}, | ||
| notWant: []string{"%!", "url:"}, | ||
| }, | ||
| { | ||
| name: "full commit info", | ||
| commitInfo: `{"sha1": "abc1234def", "author": "Jane <jane@example.com>", "timestamp": 1452902400, "url": "https://example.com/c/abc1234def", "message": "first line\nsecond line", "branch": "main"}`, | ||
| want: []string{"abc1234def", `Jane <jane@example\.com>`, `Timestamp:\s+Sat, 16 Jan 2016`, `url:\s+https://example\.com/c/abc1234def`, `message:\s+first line\n\s+second line`}, | ||
| }, | ||
| } { | ||
| t.Run(tc.name, func(t *testing.T) { | ||
| raw := `{"name": "t1", "description": "d", "compliance_state": "INCOMPLETE", | ||
| "last_modified_at": 1452902400, "git_commit_info": ` + tc.commitInfo + `, "events": []}` | ||
|
|
||
| var buf bytes.Buffer | ||
| require.NoError(t, printTrailAsTable(raw, &buf, 0)) | ||
| for _, w := range tc.want { | ||
| require.Regexp(t, w, buf.String()) | ||
| } | ||
| for _, nw := range tc.notWant { | ||
| require.NotContains(t, buf.String(), nw) | ||
| } | ||
| }) | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.