package backup import ( "net/http" "testing" ) func TestCompat(t *testing.T) { cases := []struct { bg, bgMin, bk, bkMin int want string }{ {1, 1, 1, 1, CompatOK}, {2, 1, 1, 1, CompatOK}, // oudere backup server, nog ondersteund {1, 1, 2, 1, CompatOK}, // nieuwere backup server die BlueGit 1 nog kent {3, 2, 1, 1, CompatBackupTooOld}, // BlueGit vraagt minstens 2 {1, 1, 3, 2, CompatBlueGitTooOld}, } for _, c := range cases { if got := Compat(c.bg, c.bgMin, c.bk, c.bkMin); got != c.want { t.Errorf("Compat(%d,%d,%d,%d) = %s, wil %s", c.bg, c.bgMin, c.bk, c.bkMin, got, c.want) } } } func TestPeerFromHeader(t *testing.T) { p, ok := PeerFromHeader(http.Header{}) if ok || p.Protocol != 1 || p.MinProtocol != 1 { t.Fatalf("zonder koppen: %+v %v", p, ok) } h := http.Header{} h.Set(HeaderBackupProtocol, "3") h.Set(HeaderBackupMinProtocol, "2") h.Set(HeaderBackupVersion, "v0.2.0