@@ -43,187 +43,138 @@ func TestMain(m *testing.M) {
43
43
m .Run ()
44
44
}
45
45
46
+ func validatePrinted (t * testing.T , expected string ) {
47
+ actual := strings .TrimSpace (builder .String ())
48
+ if expected != actual {
49
+ t .Error ("Output does not match expected <" + expected + "> actual <" + actual + ">" )
50
+ }
51
+ }
52
+
46
53
func TestTextCopyHandler_OnMounted (t * testing.T ) {
47
- defer builder .Reset ()
48
- expected := "Mounted 0b442c23c1dd oci-image"
54
+ builder .Reset ()
49
55
ch := NewTextCopyHandler (printer , mockFetcher .Fetcher )
50
56
if ch .OnMounted (ctx , mockFetcher .OciImage ) != nil {
51
57
t .Error ("OnMounted() should not return an error" )
52
58
}
53
- actual := strings .TrimSpace (builder .String ())
54
- if expected != actual {
55
- t .Error ("Output does not match expected <" + expected + "> actual <" + actual + ">" )
56
- }
59
+ validatePrinted (t , "Mounted 0b442c23c1dd oci-image" )
57
60
}
58
61
59
62
func TestTextCopyHandler_OnCopySkipped (t * testing.T ) {
60
- defer builder .Reset ()
61
- expected := "Exists 0b442c23c1dd oci-image"
63
+ builder .Reset ()
62
64
ch := NewTextCopyHandler (printer , mockFetcher .Fetcher )
63
65
if ch .OnCopySkipped (ctx , mockFetcher .OciImage ) != nil {
64
66
t .Error ("OnCopySkipped() should not return an error" )
65
67
}
66
- actual := strings .TrimSpace (builder .String ())
67
- if expected != actual {
68
- t .Error ("Output does not match expected <" + expected + "> actual <" + actual + ">" )
69
- }
68
+ validatePrinted (t , "Exists 0b442c23c1dd oci-image" )
70
69
}
71
70
72
71
func TestTextCopyHandler_PostCopy (t * testing.T ) {
73
- defer builder .Reset ()
74
- expected := "Copied 0b442c23c1dd oci-image"
72
+ builder .Reset ()
75
73
ch := NewTextCopyHandler (printer , mockFetcher .Fetcher )
76
74
if ch .PostCopy (ctx , mockFetcher .OciImage ) != nil {
77
75
t .Error ("PostCopy() should not return an error" )
78
76
}
79
77
if ch .PostCopy (ctx , bogus ) == nil {
80
78
t .Error ("PostCopy() should return an error" )
81
79
}
82
- actual := strings .TrimSpace (builder .String ())
83
- if expected != actual {
84
- t .Error ("Output does not match expected <" + expected + "> actual <" + actual + ">" )
85
- }
80
+ validatePrinted (t , "Copied 0b442c23c1dd oci-image" )
86
81
}
87
82
88
83
func TestTextCopyHandler_PreCopy (t * testing.T ) {
89
- defer builder .Reset ()
90
- expected := "Copying 0b442c23c1dd oci-image"
84
+ builder .Reset ()
91
85
ch := NewTextCopyHandler (printer , mockFetcher .Fetcher )
92
86
if ch .PreCopy (ctx , mockFetcher .OciImage ) != nil {
93
87
t .Error ("PreCopy() should not return an error" )
94
88
}
95
- actual := strings .TrimSpace (builder .String ())
96
- if expected != actual {
97
- t .Error ("Output does not match expected <" + expected + "> actual <" + actual + ">" )
98
- }
89
+ validatePrinted (t , "Copying 0b442c23c1dd oci-image" )
99
90
}
100
91
101
92
func TestTextPullHandler_OnNodeDownloaded (t * testing.T ) {
102
- defer builder .Reset ()
103
- expected := "Downloaded 0b442c23c1dd oci-image"
93
+ builder .Reset ()
104
94
ph := NewTextPullHandler (printer )
105
95
if ph .OnNodeDownloaded (mockFetcher .OciImage ) != nil {
106
96
t .Error ("OnNodeDownloaded() should not return an error" )
107
97
}
108
- actual := strings .TrimSpace (builder .String ())
109
- if expected != actual {
110
- t .Error ("Output does not match expected <" + expected + "> actual <" + actual + ">" )
111
- }
98
+ validatePrinted (t , "Downloaded 0b442c23c1dd oci-image" )
112
99
}
113
100
114
101
func TestTextPullHandler_OnNodeDownloading (t * testing.T ) {
115
- defer builder .Reset ()
116
- expected := "Downloading 0b442c23c1dd oci-image"
102
+ builder .Reset ()
117
103
ph := NewTextPullHandler (printer )
118
104
if ph .OnNodeDownloading (mockFetcher .OciImage ) != nil {
119
105
t .Error ("OnNodeDownloading() should not return an error" )
120
106
}
121
- actual := strings .TrimSpace (builder .String ())
122
- if expected != actual {
123
- t .Error ("Output does not match expected <" + expected + "> actual <" + actual + ">" )
124
- }
107
+ validatePrinted (t , "Downloading 0b442c23c1dd oci-image" )
125
108
}
126
109
127
110
func TestTextPullHandler_OnNodeProcessing (t * testing.T ) {
128
- defer builder .Reset ()
129
- expected := "Processing 0b442c23c1dd oci-image"
111
+ builder .Reset ()
130
112
ph := NewTextPullHandler (printer )
131
113
if ph .OnNodeProcessing (mockFetcher .OciImage ) != nil {
132
114
t .Error ("OnNodeProcessing() should not return an error" )
133
115
}
134
- actual := strings .TrimSpace (builder .String ())
135
- if expected != actual {
136
- t .Error ("Output does not match expected <" + expected + "> actual <" + actual + ">" )
137
- }
116
+ validatePrinted (t , "Processing 0b442c23c1dd oci-image" )
138
117
}
139
118
140
119
func TestTextPullHandler_OnNodeRestored (t * testing.T ) {
141
- defer builder .Reset ()
142
- expected := "Restored 0b442c23c1dd oci-image"
120
+ builder .Reset ()
143
121
ph := NewTextPullHandler (printer )
144
122
if ph .OnNodeRestored (mockFetcher .OciImage ) != nil {
145
123
t .Error ("OnNodeRestored() should not return an error" )
146
124
}
147
- actual := strings .TrimSpace (builder .String ())
148
- if expected != actual {
149
- t .Error ("Output does not match expected <" + expected + "> actual <" + actual + ">" )
150
- }
125
+ validatePrinted (t , "Restored 0b442c23c1dd oci-image" )
151
126
}
152
127
153
128
func TestTextPullHandler_OnNodeSkipped (t * testing.T ) {
154
- defer builder .Reset ()
155
- expected := "Skipped 0b442c23c1dd oci-image"
129
+ builder .Reset ()
156
130
ph := NewTextPullHandler (printer )
157
131
if ph .OnNodeSkipped (mockFetcher .OciImage ) != nil {
158
132
t .Error ("OnNodeSkipped() should not return an error" )
159
133
}
160
- actual := strings .TrimSpace (builder .String ())
161
- if expected != actual {
162
- t .Error ("Output does not match expected <" + expected + "> actual <" + actual + ">" )
163
- }
134
+ validatePrinted (t , "Skipped 0b442c23c1dd oci-image" )
164
135
}
165
136
166
137
func TestTextPushHandler_OnCopySkipped (t * testing.T ) {
167
- defer builder .Reset ()
168
- expected := "Exists 0b442c23c1dd oci-image"
138
+ builder .Reset ()
169
139
ph := NewTextPushHandler (printer , mockFetcher .Fetcher )
170
140
if ph .OnCopySkipped (ctx , mockFetcher .OciImage ) != nil {
171
141
t .Error ("OnCopySkipped() should not return an error" )
172
142
}
173
- actual := strings .TrimSpace (builder .String ())
174
- if expected != actual {
175
- t .Error ("Output does not match expected <" + expected + "> actual <" + actual + ">" )
176
- }
143
+ validatePrinted (t , "Exists 0b442c23c1dd oci-image" )
177
144
}
178
145
179
146
func TestTextPushHandler_OnEmptyArtifact (t * testing.T ) {
180
- defer builder .Reset ()
181
- expected := "Uploading empty artifact"
147
+ builder .Reset ()
182
148
ph := NewTextPushHandler (printer , mockFetcher .Fetcher )
183
149
if ph .OnEmptyArtifact () != nil {
184
150
t .Error ("OnEmptyArtifact() should not return an error" )
185
151
}
186
- actual := strings .TrimSpace (builder .String ())
187
- if expected != actual {
188
- t .Error ("Output does not match expected <" + expected + "> actual <" + actual + ">" )
189
- }
152
+ validatePrinted (t , "Uploading empty artifact" )
190
153
}
191
154
192
155
func TestTextPushHandler_OnFileLoading (t * testing.T ) {
193
- defer builder .Reset ()
194
- expected := ""
156
+ builder .Reset ()
195
157
ph := NewTextPushHandler (printer , mockFetcher .Fetcher )
196
158
if ph .OnFileLoading ("name" ) != nil {
197
159
t .Error ("OnFileLoading() should not return an error" )
198
160
}
199
- actual := strings .TrimSpace (builder .String ())
200
- if expected != actual {
201
- t .Error ("Output does not match expected <" + expected + "> actual <" + actual + ">" )
202
- }
161
+ validatePrinted (t , "" )
203
162
}
204
163
205
164
func TestTextPushHandler_PostCopy (t * testing.T ) {
206
- defer builder .Reset ()
207
- expected := "Uploaded 0b442c23c1dd oci-image"
165
+ builder .Reset ()
208
166
ph := NewTextPushHandler (printer , mockFetcher .Fetcher )
209
167
if ph .PostCopy (ctx , mockFetcher .OciImage ) != nil {
210
168
t .Error ("PostCopy() should not return an error" )
211
169
}
212
- actual := strings .TrimSpace (builder .String ())
213
- if expected != actual {
214
- t .Error ("Output does not match expected <" + expected + "> actual <" + actual + ">" )
215
- }
170
+ validatePrinted (t , "Uploaded 0b442c23c1dd oci-image" )
216
171
}
217
172
218
173
func TestTextPushHandler_PreCopy (t * testing.T ) {
219
- defer builder .Reset ()
220
- expected := "Uploading 0b442c23c1dd oci-image"
174
+ builder .Reset ()
221
175
ph := NewTextPushHandler (printer , mockFetcher .Fetcher )
222
176
if ph .PreCopy (ctx , mockFetcher .OciImage ) != nil {
223
177
t .Error ("PreCopy() should not return an error" )
224
178
}
225
- actual := strings .TrimSpace (builder .String ())
226
- if expected != actual {
227
- t .Error ("Output does not match expected <" + expected + "> actual <" + actual + ">" )
228
- }
179
+ validatePrinted (t , "Uploading 0b442c23c1dd oci-image" )
229
180
}
0 commit comments