vole
Clone
Read only, no credentials:
https://rodent.software/vole.git
Write over SSH with a registered key:
git clone ssh://git@rodent.software:2222/vole.git
A free and open-source forge that lives in your Git repo.
refactor
c5902451905acdaa478f8476844ccd4a510d9ca9 · Keenan Nemetz · 17d ago · parent ec2aba4b
internal/requests/requests_test.go → metadata/requests_test.go +26−26
| @@ -1,4 +1,4 @@ | |||
| 1 | package requests | ||
| 1 | package metadata | ||
| 2 | 2 | ||
| 3 | 3 | // A review thread lives in the same tree as the request it discusses, so the | |
| 4 | 4 | // parser is also the boundary that decides what a comment file may look like. | |
| @@ -12,10 +12,10 @@ import ( | |||
| 12 | 12 | ) | |
| 13 | 13 | ||
| 14 | 14 | const ( | |
| 15 | idA = "01M5JR2JK29KKMAA1T9MDNTRB1" // the request | ||
| 16 | idB = "01M5JR2JK29KKMAA1T9MDNTRB2" // a comment | ||
| 17 | idC = "01M5JR2JK29KKMAA1T9MDNTRB3" // the author's account, and what the writer last saw | ||
| 18 | idD = "01M5JR2JK29KKMAA1T9MDNTRB4" // an approver who is not the author | ||
| 15 | reqIDA = "01M5JR2JK29KKMAA1T9MDNTRB1" // the request | ||
| 16 | reqIDB = "01M5JR2JK29KKMAA1T9MDNTRB2" // a comment | ||
| 17 | reqIDC = "01M5JR2JK29KKMAA1T9MDNTRB3" // the author's account, and what the writer last saw | ||
| 18 | reqIDD = "01M5JR2JK29KKMAA1T9MDNTRB4" // an approver who is not the author | ||
| 19 | 19 | ) | |
| 20 | 20 | ||
| 21 | 21 | func requestBody(head string) string { | |
| @@ -23,7 +23,7 @@ func requestBody(head string) string { | |||
| 23 | 23 | `title: "Land the retry"` + "\n" + | |
| 24 | 24 | "state: open\n" + | |
| 25 | 25 | "author: keenan\n" + | |
| 26 | "author_id: " + idC + "\n" + | ||
| 26 | "author_id: " + reqIDC + "\n" + | ||
| 27 | 27 | "base: main\n" + | |
| 28 | 28 | "head: " + head + "\n" + | |
| 29 | 29 | "created: 2026-10-22T22:00:00Z\n" + | |
| @@ -38,11 +38,11 @@ const ( | |||
| 38 | 38 | ||
| 39 | 39 | func TestParseReadsTheDiscussion(t *testing.T) { | |
| 40 | 40 | t.Parallel() | |
| 41 | list, err := Parse(map[string]string{ | ||
| 42 | Dir + "/" + idA + "/request.md": requestBody(headSHA), | ||
| 43 | Dir + "/" + idA + "/comments/" + idB + ".md": "---\nauthor: wilbur\ncreated: 2026-10-22T23:00:00Z\n---\nOne question.\n", | ||
| 44 | Dir + "/" + idA + "/approvals/" + idD + ".md": "---\nbase: main\nhead: " + headSHA + "\ncreated: 2026-10-22T23:10:00Z\n---\n", | ||
| 45 | Dir + "/" + idA + "/comments/01M5JR2JK29KKMAA1T9MDNTRBZ.md": "---\nauthor: keenan\ncreated: 2026-10-22T23:05:00Z\n---\nEarlier.\n", | ||
| 41 | list, err := ParseRequests(map[string]string{ | ||
| 42 | RequestsDir + "/" + reqIDA + "/request.md": requestBody(headSHA), | ||
| 43 | RequestsDir + "/" + reqIDA + "/comments/" + reqIDB + ".md": "---\nauthor: wilbur\ncreated: 2026-10-22T23:00:00Z\n---\nOne question.\n", | ||
| 44 | RequestsDir + "/" + reqIDA + "/approvals/" + reqIDD + ".md": "---\nbase: main\nhead: " + headSHA + "\ncreated: 2026-10-22T23:10:00Z\n---\n", | ||
| 45 | RequestsDir + "/" + reqIDA + "/comments/01M5JR2JK29KKMAA1T9MDNTRBZ.md": "---\nauthor: keenan\ncreated: 2026-10-22T23:05:00Z\n---\nEarlier.\n", | ||
| 46 | 46 | }) | |
| 47 | 47 | if err != nil { | |
| 48 | 48 | t.Fatalf("unexpected error: %v", err) | |
| @@ -62,7 +62,7 @@ func TestParseReadsTheDiscussion(t *testing.T) { | |||
| 62 | 62 | if strings.TrimSpace(req.Comments[0].Body) != "One question." { | |
| 63 | 63 | t.Fatalf("body = %q", req.Comments[0].Body) | |
| 64 | 64 | } | |
| 65 | if len(req.Approvals) != 1 || req.Approvals[0].Principal != idD { | ||
| 65 | if len(req.Approvals) != 1 || req.Approvals[0].Principal != reqIDD { | ||
| 66 | 66 | t.Fatalf("approvals = %+v", req.Approvals) | |
| 67 | 67 | } | |
| 68 | 68 | } | |
| @@ -76,16 +76,16 @@ func TestCommentNeedsAnAuthorAndATime(t *testing.T) { | |||
| 76 | 76 | {"no frontmatter", "just text\n", "a comment is frontmatter with author and created"}, | |
| 77 | 77 | } | |
| 78 | 78 | for _, c := range cases { | |
| 79 | _, err := Parse(map[string]string{ | ||
| 80 | Dir + "/" + idA + "/request.md": requestBody(headSHA), | ||
| 81 | Dir + "/" + idA + "/comments/" + idB + ".md": c.body, | ||
| 79 | _, err := ParseRequests(map[string]string{ | ||
| 80 | RequestsDir + "/" + reqIDA + "/request.md": requestBody(headSHA), | ||
| 81 | RequestsDir + "/" + reqIDA + "/comments/" + reqIDB + ".md": c.body, | ||
| 82 | 82 | }) | |
| 83 | 83 | ve, ok := err.(*ValidationError) | |
| 84 | 84 | if !ok { | |
| 85 | 85 | t.Fatalf("%s: accepted: %v", c.name, err) | |
| 86 | 86 | } | |
| 87 | 87 | joined := strings.Join(ve.Problems, "; ") | |
| 88 | if !strings.Contains(joined, "comments/"+idB+".md") || !strings.Contains(joined, c.want) { | ||
| 88 | if !strings.Contains(joined, "comments/"+reqIDB+".md") || !strings.Contains(joined, c.want) { | ||
| 89 | 89 | t.Fatalf("%s: unhelpful refusal: %v", c.name, ve.Problems) | |
| 90 | 90 | } | |
| 91 | 91 | } | |
| @@ -96,9 +96,9 @@ func TestCommentNeedsAnAuthorAndATime(t *testing.T) { | |||
| 96 | 96 | // file the web silently ignores. | |
| 97 | 97 | func TestUnknownFileInARequestIsRefused(t *testing.T) { | |
| 98 | 98 | t.Parallel() | |
| 99 | _, err := Parse(map[string]string{ | ||
| 100 | Dir + "/" + idA + "/request.md": requestBody(headSHA), | ||
| 101 | Dir + "/" + idA + "/review.md": "---\nauthor: wilbur\ncreated: 2026-10-22T23:00:00Z\n---\nnote\n", | ||
| 99 | _, err := ParseRequests(map[string]string{ | ||
| 100 | RequestsDir + "/" + reqIDA + "/request.md": requestBody(headSHA), | ||
| 101 | RequestsDir + "/" + reqIDA + "/review.md": "---\nauthor: wilbur\ncreated: 2026-10-22T23:00:00Z\n---\nnote\n", | ||
| 102 | 102 | }) | |
| 103 | 103 | ve, ok := err.(*ValidationError) | |
| 104 | 104 | if !ok { | |
| @@ -114,19 +114,19 @@ func TestUnknownFileInARequestIsRefused(t *testing.T) { | |||
| 114 | 114 | ||
| 115 | 115 | func TestCommentPaths(t *testing.T) { | |
| 116 | 116 | t.Parallel() | |
| 117 | path := CommentPath(idA, idB) | ||
| 118 | if path != "requests/"+idA+"/comments/"+idB+".md" { | ||
| 117 | path := RequestCommentPath(reqIDA, reqIDB) | ||
| 118 | if path != "requests/"+reqIDA+"/comments/"+reqIDB+".md" { | ||
| 119 | 119 | t.Fatalf("path = %q", path) | |
| 120 | 120 | } | |
| 121 | if !IsCommentPath(path) { | ||
| 121 | if !IsRequestCommentPath(path) { | ||
| 122 | 122 | t.Fatal("a comment path was not recognised") | |
| 123 | 123 | } | |
| 124 | 124 | for _, other := range []string{ | |
| 125 | "requests/" + idA + "/request.md", | ||
| 126 | "requests/" + idA + "/approvals/" + idB + ".md", | ||
| 127 | "issues/" + idA + "/comments/" + idB + ".md", | ||
| 125 | "requests/" + reqIDA + "/request.md", | ||
| 126 | "requests/" + reqIDA + "/approvals/" + reqIDB + ".md", | ||
| 127 | "issues/" + reqIDA + "/comments/" + reqIDB + ".md", | ||
| 128 | 128 | } { | |
| 129 | if IsCommentPath(other) { | ||
| 129 | if IsRequestCommentPath(other) { | ||
| 130 | 130 | t.Fatalf("%q was mistaken for a request comment", other) | |
| 131 | 131 | } | |
| 132 | 132 | } | |