internal/deps/report_test.go
43 lines · 1195 bytes
1 symbol in this file
1package deps
2
3import (
4 "strings"
5 "testing"
6
7 "gitbay.org/gitbay/internal/store"
8)
9
10// The body is read as a rendered table on the web and as the plain text of
11// the notification mail, so every row has to line up on its own.
12func TestBodyAlignsColumns(t *testing.T) {
13 body := Body("main", []store.DepReport{
14 {Ecosystem: EcoGo, Name: "go.yaml.in/yaml/v3", Current: "v3.0.4", Latest: "v3.0.5"},
15 {Ecosystem: EcoGo, Name: "golang.org/x/net", Current: "v0.57.0", Latest: "v0.58.0"},
16 {Ecosystem: EcoNPM, Name: "react", Current: "18.2.0", Latest: "19.0.0"},
17 })
18 var pipes []int
19 for _, line := range strings.Split(body, "\n") {
20 if !strings.HasPrefix(line, "|") {
21 pipes = append(pipes, -1) // section break
22 continue
23 }
24 pipes = append(pipes, len(line))
25 }
26 // Within a run of table lines every line is the same length.
27 var run []int
28 for _, n := range append(pipes, -1) {
29 if n == -1 {
30 for _, w := range run {
31 if w != run[0] {
32 t.Fatalf("ragged table in:\n%s", body)
33 }
34 }
35 run = nil
36 continue
37 }
38 run = append(run, n)
39 }
40 if !strings.Contains(body, "| `golang.org/x/net` | v0.57.0 | v0.58.0 |") {
41 t.Errorf("row not padded to its column:\n%s", body)
42 }
43}