-
Notifications
You must be signed in to change notification settings - Fork 0
/
verify_test.go
69 lines (56 loc) · 1.54 KB
/
verify_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
// Copyright 2012, The gohg Authors. All rights reserved.
// Use of this source code is governed by a BSD style license
// that can be found in the LICENSE.md file.
package gohg
import (
"os"
"path/filepath"
"testing"
)
func TestHgClient_Verify_Healthy(t *testing.T) {
// GIVEN a new repo
hct := setup(t)
defer teardown(t, hct)
// AND the known result for 'hg verify' on a new repo
var expected string = "checking changesets\n" +
"checking manifests\n" +
"crosschecking files in changesets and manifests\n" +
"checking files\n" +
"0 files, 0 changesets, 0 total revisions\n"
// WHEN I call 'hg verify' on it
got, err := hct.Verify(nil, nil)
if err != nil {
t.Error(err)
}
// THEN it should not report any problem
if string(got) != expected {
t.Fatalf("Test Verify: expected:\n%s\n but got:\n%s\n", expected, got)
}
} // TestHgClient_Verify_Healthy
func TestHgClient_Verify_Sick(t *testing.T) {
// GIVEN a new repo
hct := setup(t)
defer teardown(t, hct)
// AND at least one cset in the repo
err := createAndCommitFile(t, hct, "/a", "aaa")
if err != nil {
t.Fatal(err)
}
// AND we cause a defect to the repo
// cause some integrity problem
var f string
f, err = filepath.Abs(hct.RepoRoot() + "/.hg/store/00manifest.i")
if err != nil {
t.Error(err)
}
err = os.Rename(f, f+"_BAK")
if err != nil {
t.Fatal(err)
}
// WHEN we call 'hg verify' on it
_, err = hct.Verify(nil, nil)
// THEN it should return an error
if err == nil {
t.Fatalf("Test Verify: did not get expected error")
}
} // TestHgClient_Verify_Sick