-
Notifications
You must be signed in to change notification settings - Fork 70
/
mock_status_reporter.go
142 lines (121 loc) · 4.14 KB
/
mock_status_reporter.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
package execution
import (
"github.com/newrelic/newrelic-cli/internal/install/types"
)
// MockStatusReporter is a mock implementation of the ExecutionStatusReporter
// interface that provides method spies for testing scenarios.
type MockStatusReporter struct {
RecipeAvailableErr error
RecipesAvailableErr error
RecipesSelectedErr error
RecipeFailedErr error
RecipeInstalledErr error
RecipeInstallingErr error
RecipeRecommendedErr error
RecipeSkippedErr error
InstallCompleteErr error
InstallCanceledErr error
DiscoveryCompleteErr error
RecipeAvailableCallCount int
RecipesAvailableCallCount int
RecipesSelectedCallCount int
RecipeFailedCallCount int
RecipeInstalledCallCount int
RecipeInstallingCallCount int
RecipeRecommendedCallCount int
RecipeSkippedCallCount int
InstallCompleteCallCount int
InstallCanceledCallCount int
DiscoveryCompleteCallCount int
ReportSkipped map[string]int
ReportInstalled map[string]int
ReportInstalling map[string]int
ReportRecommended map[string]int
ReportFailed map[string]int
ReportAvailable map[string]int
GUIDs []string
Durations []int64
RecipeGUID map[string]string
}
// NewMockStatusReporter returns a new instance of MockExecutionStatusReporter.
func NewMockStatusReporter() *MockStatusReporter {
return &MockStatusReporter{}
}
func (r *MockStatusReporter) RecipeFailed(status *InstallStatus, event RecipeStatusEvent) error {
r.RecipeFailedCallCount++
if len(r.ReportFailed) == 0 {
r.ReportFailed = make(map[string]int)
}
r.ReportFailed[event.Recipe.Name]++
return r.RecipeFailedErr
}
func (r *MockStatusReporter) RecipeInstalled(status *InstallStatus, event RecipeStatusEvent) error {
r.RecipeInstalledCallCount++
if len(r.ReportInstalled) == 0 {
r.ReportInstalled = make(map[string]int)
}
r.ReportInstalled[event.Recipe.Name]++
r.GUIDs = status.EntityGUIDs
if len(r.RecipeGUID) == 0 {
r.RecipeGUID = make(map[string]string)
}
for _, s := range status.Statuses {
r.RecipeGUID[s.Name] = s.EntityGUID
if s.ValidationDurationMilliseconds > 0 {
r.Durations = append(r.Durations, s.ValidationDurationMilliseconds)
}
}
return r.RecipeInstalledErr
}
func (r *MockStatusReporter) RecipeInstalling(status *InstallStatus, event RecipeStatusEvent) error {
r.RecipeInstallingCallCount++
if len(r.ReportInstalling) == 0 {
r.ReportInstalling = make(map[string]int)
}
r.ReportInstalling[event.Recipe.Name]++
return r.RecipeInstallingErr
}
func (r *MockStatusReporter) RecipeRecommended(status *InstallStatus, event RecipeStatusEvent) error {
r.RecipeRecommendedCallCount++
if len(r.ReportRecommended) == 0 {
r.ReportRecommended = make(map[string]int)
}
r.ReportRecommended[event.Recipe.Name]++
return r.RecipeRecommendedErr
}
func (r *MockStatusReporter) RecipeSkipped(status *InstallStatus, event RecipeStatusEvent) error {
r.RecipeSkippedCallCount++
if len(r.ReportSkipped) == 0 {
r.ReportSkipped = make(map[string]int)
}
r.ReportSkipped[event.Recipe.Name]++
return r.RecipeSkippedErr
}
func (r *MockStatusReporter) RecipeAvailable(status *InstallStatus, recipe types.OpenInstallationRecipe) error {
r.RecipeAvailableCallCount++
if len(r.ReportAvailable) == 0 {
r.ReportAvailable = make(map[string]int)
}
r.ReportAvailable[recipe.Name]++
return r.RecipeAvailableErr
}
func (r *MockStatusReporter) RecipesAvailable(status *InstallStatus, recipes []types.OpenInstallationRecipe) error {
r.RecipesAvailableCallCount++
return r.RecipesAvailableErr
}
func (r *MockStatusReporter) RecipesSelected(status *InstallStatus, recipes []types.OpenInstallationRecipe) error {
r.RecipesSelectedCallCount++
return r.RecipesSelectedErr
}
func (r *MockStatusReporter) InstallComplete(status *InstallStatus) error {
r.InstallCompleteCallCount++
return r.InstallCompleteErr
}
func (r *MockStatusReporter) InstallCanceled(status *InstallStatus) error {
r.InstallCanceledCallCount++
return r.InstallCanceledErr
}
func (r *MockStatusReporter) DiscoveryComplete(status *InstallStatus, dm types.DiscoveryManifest) error {
r.DiscoveryCompleteCallCount++
return r.DiscoveryCompleteErr
}