gunk-dev/the-valley

landing_test.go

source535d69c9a69emain's published tip history
1.2 KiB
1package change
2
3import (
4 "strings"
5 "testing"
6)
7
8// A landing record reads back as written, and reads as nothing else: a
9// record that does not parse binds no head to a landing.
10func TestALandingRecordReadsOnlyAsWritten(t *testing.T) {
11 l := Landing{Landed: strings.Repeat("a", 40), Request: "c-" + strings.Repeat("k", 32), Head: strings.Repeat("b", 40)}
12 got, err := ParseLanding(l.Format())
13 if err != nil || got != l {
14 t.Fatalf("ParseLanding(Format()) = %+v, %v; want %+v", got, err, l)
15 }
16 good := string(l.Format())
17 for what, text := range map[string]string{
18 "no final newline": strings.TrimSuffix(good, "\n"),
19 "a fourth line": good + "extra x\n",
20 "lines out of order": "request r\nlanded " + l.Landed + "\nhead " + l.Head + "\n",
21 "a short commit": strings.Replace(good, l.Landed, l.Landed[:39], 1),
22 "an uppercase head": strings.Replace(good, l.Head, strings.ToUpper(l.Head), 1),
23 "a space in a name": strings.Replace(good, l.Request, "c- x", 1),
24 "an empty name": strings.Replace(good, "request "+l.Request, "request ", 1),
25 } {
26 if got, err := ParseLanding([]byte(text)); err == nil {
27 t.Errorf("%s: read as %+v", what, got)
28 }
29 }
30}