| 1 | package protocol |
| 2 | |
| 3 | import ( |
| 4 | "net/http" |
| 5 | "testing" |
| 6 | ) |
| 7 | |
| 8 | func TestCompat(t *testing.T) { |
| 9 | cases := []struct { |
| 10 | bg, bgMin, bk, bkMin int |
| 11 | want string |
| 12 | }{ |
| 13 | {1, 1, 1, 1, CompatOK}, |
| 14 | {2, 1, 1, 1, CompatOK}, |
| 15 | {1, 1, 2, 1, CompatOK}, |
| 16 | {3, 2, 1, 1, CompatBackupTooOld}, |
| 17 | {1, 1, 3, 2, CompatBlueGitTooOld}, |
| 18 | } |
| 19 | for _, c := range cases { |
| 20 | if got := Compat(c.bg, c.bgMin, c.bk, c.bkMin); got != c.want { |
| 21 | t.Errorf("Compat(%d,%d,%d,%d) = %s, wil %s", c.bg, c.bgMin, c.bk, c.bkMin, got, c.want) |
| 22 | } |
| 23 | } |
| 24 | } |
| 25 | |
| 26 | func TestBlueGitFromHeader(t *testing.T) { |
| 27 | if p, ok := BlueGitFromHeader(http.Header{}); ok || p.Protocol != 1 || p.MinProtocol != 1 { |
| 28 | t.Fatalf("zonder koppen: %+v", p) |
| 29 | } |
| 30 | h := http.Header{} |
| 31 | h.Set(HeaderBlueGitProtocol, "4") |
| 32 | h.Set(HeaderBlueGitMinProtocol, "3") |
| 33 | h.Set(HeaderBlueGitVersion, "abc<def") |
| 34 | p, ok := BlueGitFromHeader(h) |
| 35 | if !ok || p.Protocol != 4 || p.MinProtocol != 3 || p.Version != "abcdef" { |
| 36 | t.Fatalf("%+v", p) |
| 37 | } |
| 38 | if p.Compat() != CompatBackupTooOld { |
| 39 | t.Fatalf("BlueGit 4 vraagt 3, wij spreken 1: %s", p.Compat()) |
| 40 | } |
| 41 | } |