Matthias Andreas Benkard | 832a54e | 2019-01-29 09:27:38 +0100 | [diff] [blame] | 1 | package stenographer |
| 2 | |
| 3 | import ( |
| 4 | "sync" |
| 5 | |
| 6 | "github.com/onsi/ginkgo/types" |
| 7 | ) |
| 8 | |
| 9 | func NewFakeStenographerCall(method string, args ...interface{}) FakeStenographerCall { |
| 10 | return FakeStenographerCall{ |
| 11 | Method: method, |
| 12 | Args: args, |
| 13 | } |
| 14 | } |
| 15 | |
| 16 | type FakeStenographer struct { |
| 17 | calls []FakeStenographerCall |
| 18 | lock *sync.Mutex |
| 19 | } |
| 20 | |
| 21 | type FakeStenographerCall struct { |
| 22 | Method string |
| 23 | Args []interface{} |
| 24 | } |
| 25 | |
| 26 | func NewFakeStenographer() *FakeStenographer { |
| 27 | stenographer := &FakeStenographer{ |
| 28 | lock: &sync.Mutex{}, |
| 29 | } |
| 30 | stenographer.Reset() |
| 31 | return stenographer |
| 32 | } |
| 33 | |
| 34 | func (stenographer *FakeStenographer) Calls() []FakeStenographerCall { |
| 35 | stenographer.lock.Lock() |
| 36 | defer stenographer.lock.Unlock() |
| 37 | |
| 38 | return stenographer.calls |
| 39 | } |
| 40 | |
| 41 | func (stenographer *FakeStenographer) Reset() { |
| 42 | stenographer.lock.Lock() |
| 43 | defer stenographer.lock.Unlock() |
| 44 | |
| 45 | stenographer.calls = make([]FakeStenographerCall, 0) |
| 46 | } |
| 47 | |
| 48 | func (stenographer *FakeStenographer) CallsTo(method string) []FakeStenographerCall { |
| 49 | stenographer.lock.Lock() |
| 50 | defer stenographer.lock.Unlock() |
| 51 | |
| 52 | results := make([]FakeStenographerCall, 0) |
| 53 | for _, call := range stenographer.calls { |
| 54 | if call.Method == method { |
| 55 | results = append(results, call) |
| 56 | } |
| 57 | } |
| 58 | |
| 59 | return results |
| 60 | } |
| 61 | |
| 62 | func (stenographer *FakeStenographer) registerCall(method string, args ...interface{}) { |
| 63 | stenographer.lock.Lock() |
| 64 | defer stenographer.lock.Unlock() |
| 65 | |
| 66 | stenographer.calls = append(stenographer.calls, NewFakeStenographerCall(method, args...)) |
| 67 | } |
| 68 | |
| 69 | func (stenographer *FakeStenographer) AnnounceSuite(description string, randomSeed int64, randomizingAll bool, succinct bool) { |
| 70 | stenographer.registerCall("AnnounceSuite", description, randomSeed, randomizingAll, succinct) |
| 71 | } |
| 72 | |
| 73 | func (stenographer *FakeStenographer) AnnounceAggregatedParallelRun(nodes int, succinct bool) { |
| 74 | stenographer.registerCall("AnnounceAggregatedParallelRun", nodes, succinct) |
| 75 | } |
| 76 | |
| 77 | func (stenographer *FakeStenographer) AnnounceParallelRun(node int, nodes int, succinct bool) { |
| 78 | stenographer.registerCall("AnnounceParallelRun", node, nodes, succinct) |
| 79 | } |
| 80 | |
| 81 | func (stenographer *FakeStenographer) AnnounceNumberOfSpecs(specsToRun int, total int, succinct bool) { |
| 82 | stenographer.registerCall("AnnounceNumberOfSpecs", specsToRun, total, succinct) |
| 83 | } |
| 84 | |
| 85 | func (stenographer *FakeStenographer) AnnounceTotalNumberOfSpecs(total int, succinct bool) { |
| 86 | stenographer.registerCall("AnnounceTotalNumberOfSpecs", total, succinct) |
| 87 | } |
| 88 | |
| 89 | func (stenographer *FakeStenographer) AnnounceSpecRunCompletion(summary *types.SuiteSummary, succinct bool) { |
| 90 | stenographer.registerCall("AnnounceSpecRunCompletion", summary, succinct) |
| 91 | } |
| 92 | |
| 93 | func (stenographer *FakeStenographer) AnnounceSpecWillRun(spec *types.SpecSummary) { |
| 94 | stenographer.registerCall("AnnounceSpecWillRun", spec) |
| 95 | } |
| 96 | |
| 97 | func (stenographer *FakeStenographer) AnnounceBeforeSuiteFailure(summary *types.SetupSummary, succinct bool, fullTrace bool) { |
| 98 | stenographer.registerCall("AnnounceBeforeSuiteFailure", summary, succinct, fullTrace) |
| 99 | } |
| 100 | |
| 101 | func (stenographer *FakeStenographer) AnnounceAfterSuiteFailure(summary *types.SetupSummary, succinct bool, fullTrace bool) { |
| 102 | stenographer.registerCall("AnnounceAfterSuiteFailure", summary, succinct, fullTrace) |
| 103 | } |
| 104 | func (stenographer *FakeStenographer) AnnounceCapturedOutput(output string) { |
| 105 | stenographer.registerCall("AnnounceCapturedOutput", output) |
| 106 | } |
| 107 | |
| 108 | func (stenographer *FakeStenographer) AnnounceSuccesfulSpec(spec *types.SpecSummary) { |
| 109 | stenographer.registerCall("AnnounceSuccesfulSpec", spec) |
| 110 | } |
| 111 | |
| 112 | func (stenographer *FakeStenographer) AnnounceSuccesfulSlowSpec(spec *types.SpecSummary, succinct bool) { |
| 113 | stenographer.registerCall("AnnounceSuccesfulSlowSpec", spec, succinct) |
| 114 | } |
| 115 | |
| 116 | func (stenographer *FakeStenographer) AnnounceSuccesfulMeasurement(spec *types.SpecSummary, succinct bool) { |
| 117 | stenographer.registerCall("AnnounceSuccesfulMeasurement", spec, succinct) |
| 118 | } |
| 119 | |
| 120 | func (stenographer *FakeStenographer) AnnouncePendingSpec(spec *types.SpecSummary, noisy bool) { |
| 121 | stenographer.registerCall("AnnouncePendingSpec", spec, noisy) |
| 122 | } |
| 123 | |
| 124 | func (stenographer *FakeStenographer) AnnounceSkippedSpec(spec *types.SpecSummary, succinct bool, fullTrace bool) { |
| 125 | stenographer.registerCall("AnnounceSkippedSpec", spec, succinct, fullTrace) |
| 126 | } |
| 127 | |
| 128 | func (stenographer *FakeStenographer) AnnounceSpecTimedOut(spec *types.SpecSummary, succinct bool, fullTrace bool) { |
| 129 | stenographer.registerCall("AnnounceSpecTimedOut", spec, succinct, fullTrace) |
| 130 | } |
| 131 | |
| 132 | func (stenographer *FakeStenographer) AnnounceSpecPanicked(spec *types.SpecSummary, succinct bool, fullTrace bool) { |
| 133 | stenographer.registerCall("AnnounceSpecPanicked", spec, succinct, fullTrace) |
| 134 | } |
| 135 | |
| 136 | func (stenographer *FakeStenographer) AnnounceSpecFailed(spec *types.SpecSummary, succinct bool, fullTrace bool) { |
| 137 | stenographer.registerCall("AnnounceSpecFailed", spec, succinct, fullTrace) |
| 138 | } |
| 139 | |
| 140 | func (stenographer *FakeStenographer) SummarizeFailures(summaries []*types.SpecSummary) { |
| 141 | stenographer.registerCall("SummarizeFailures", summaries) |
| 142 | } |