MCPcopy
hub / github.com/sourcegraph/checkup / TestCheckAndStore

Function TestCheckAndStore

checkup_test.go:14–67  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

12)
13
14func TestCheckAndStore(t *testing.T) {
15 f := new(fake)
16 c := Checkup{
17 Storage: f,
18 Checkers: []Checker{f, f},
19 ConcurrentChecks: 1,
20 Timestamp: time.Now(),
21 Notifiers: []Notifier{f, f},
22 }
23
24 err := c.CheckAndStore()
25 if err != nil {
26 t.Errorf("Didn't expect an error: %v", err)
27 }
28 if got, want := f.checked, 2; got != want {
29 t.Errorf("Expected %d checks to be executed, but had: %d", want, got)
30 }
31 if got, want := len(f.stored), 2; got != want {
32 t.Errorf("Expected %d checks to be stored, but had: %d", want, got)
33 }
34 for i := range f.stored {
35 if i > 0 && f.stored[i].Timestamp != f.stored[i-1].Timestamp {
36 t.Error("Expected timestamps to be the same, but they weren't")
37 }
38 }
39 if got, want := f.notified, 2; got != want {
40 t.Errorf("Expected Notify() to be called %d time, called %d times", want, got)
41 }
42 if got, want := f.maintained, 1; got != want {
43 t.Errorf("Expected Maintain() to be called %d time, called %d times", want, got)
44 }
45
46 // Check error handling
47 f.returnErr = true
48 err = c.CheckAndStore()
49 if err == nil {
50 t.Error("Expected an error, didn't get one")
51 }
52 if got, want := err.Error(), "i'm an error; i'm an error"; got != want {
53 t.Errorf(`Expected error string "%s" but got: "%s"`, want, got)
54 }
55
56 c.ConcurrentChecks = -1
57 _, err = c.Check()
58 if err == nil {
59 t.Error("Expected an error with ConcurrentChecks < 0, didn't get one")
60 }
61 c.ConcurrentChecks = 0
62 c.Storage = nil
63 err = c.CheckAndStore()
64 if err == nil {
65 t.Error("Expected an error with no storage, didn't get one")
66 }
67}
68
69func TestCheckAndStoreEvery(t *testing.T) {
70 f := new(fake)

Callers

nothing calls this directly

Calls 3

CheckAndStoreMethod · 0.95
CheckMethod · 0.95
ErrorMethod · 0.80

Tested by

no test coverage detected