@@ -29,15 +29,15 @@ import (
29
29
"github.com/elastic/elastic-agent/internal/pkg/agent/errors"
30
30
"github.com/elastic/elastic-agent/internal/pkg/config"
31
31
"github.com/elastic/elastic-agent/internal/pkg/fleetapi"
32
- "github.com/elastic/elastic-agent/internal/pkg/fleetapi/acker"
33
32
"github.com/elastic/elastic-agent/internal/pkg/release"
34
33
v1 "github.com/elastic/elastic-agent/pkg/api/v1"
35
34
"github.com/elastic/elastic-agent/pkg/control/v2/client"
36
35
"github.com/elastic/elastic-agent/pkg/control/v2/cproto"
37
36
"github.com/elastic/elastic-agent/pkg/core/logger"
38
37
"github.com/elastic/elastic-agent/pkg/core/logger/loggertest"
39
38
agtversion "github.com/elastic/elastic-agent/pkg/version"
40
- mocks "github.com/elastic/elastic-agent/testing/mocks/pkg/control/v2/client"
39
+ ackermocks "github.com/elastic/elastic-agent/testing/mocks/internal_/pkg/fleetapi/acker"
40
+ clientmocks "github.com/elastic/elastic-agent/testing/mocks/pkg/control/v2/client"
41
41
)
42
42
43
43
func Test_CopyFile (t * testing.T ) {
@@ -239,7 +239,7 @@ func TestIsInProgress(t *testing.T) {
239
239
t .Run (name , func (t * testing.T ) {
240
240
// Expect client.State() call to be made only if no Upgrade Watcher PIDs
241
241
// are returned (i.e. no Upgrade Watcher is found to be running).
242
- mc := mocks .NewClient (t )
242
+ mc := clientmocks .NewClient (t )
243
243
if test .watcherPIDsFetcher != nil {
244
244
pids , _ := test .watcherPIDsFetcher ()
245
245
if len (pids ) == 0 {
@@ -293,37 +293,31 @@ func TestUpgraderAckAction(t *testing.T) {
293
293
require .Nil (t , u .AckAction (t .Context (), nil , action ))
294
294
})
295
295
t .Run ("AckAction with acker" , func (t * testing.T ) {
296
- acker := & fakeAcker {}
297
- acker . On ( " Ack" , mock .Anything , action ).Return (nil )
298
- acker . On ( " Commit" , mock .Anything ).Return (nil )
296
+ mockAcker := ackermocks . NewAcker ( t )
297
+ mockAcker . EXPECT (). Ack ( mock .Anything , action ).Return (nil )
298
+ mockAcker . EXPECT (). Commit ( mock .Anything ).Return (nil )
299
299
300
- require .Nil (t , u .AckAction (t .Context (), acker , action ))
301
- acker .AssertCalled (t , "Ack" , mock .Anything , action )
302
- acker .AssertCalled (t , "Commit" , mock .Anything )
300
+ require .Nil (t , u .AckAction (t .Context (), mockAcker , action ))
303
301
})
304
302
305
303
t .Run ("AckAction with acker - failing commit" , func (t * testing.T ) {
306
- acker := & fakeAcker {}
304
+ mockAcker := ackermocks . NewAcker ( t )
307
305
308
306
errCommit := errors .New ("failed commit" )
309
- acker . On ( " Ack" , mock .Anything , action ).Return (nil )
310
- acker . On ( " Commit" , mock .Anything ).Return (errCommit )
307
+ mockAcker . EXPECT (). Ack ( mock .Anything , action ).Return (nil )
308
+ mockAcker . EXPECT (). Commit ( mock .Anything ).Return (errCommit )
311
309
312
- require .ErrorIs (t , u .AckAction (t .Context (), acker , action ), errCommit )
313
- acker .AssertCalled (t , "Ack" , mock .Anything , action )
314
- acker .AssertCalled (t , "Commit" , mock .Anything )
310
+ require .ErrorIs (t , u .AckAction (t .Context (), mockAcker , action ), errCommit )
315
311
})
316
312
317
313
t .Run ("AckAction with acker - failed ack" , func (t * testing.T ) {
318
- acker := & fakeAcker {}
314
+ mockAcker := ackermocks . NewAcker ( t )
319
315
320
316
errAck := errors .New ("ack error" )
321
- acker .On ("Ack" , mock .Anything , action ).Return (errAck )
322
- acker .On ("Commit" , mock .Anything ).Return (nil )
323
-
324
- require .ErrorIs (t , u .AckAction (t .Context (), acker , action ), errAck )
325
- acker .AssertCalled (t , "Ack" , mock .Anything , action )
326
- acker .AssertNotCalled (t , "Commit" , mock .Anything )
317
+ mockAcker .EXPECT ().Ack (mock .Anything , action ).Return (errAck )
318
+ // no expectation on Commit() since it shouldn't be called after an error during Ack()
319
+
320
+ require .ErrorIs (t , u .AckAction (t .Context (), mockAcker , action ), errAck )
327
321
})
328
322
}
329
323
@@ -1276,19 +1270,3 @@ func TestIsSameReleaseVersion(t *testing.T) {
1276
1270
})
1277
1271
}
1278
1272
}
1279
-
1280
- var _ acker.Acker = & fakeAcker {}
1281
-
1282
- type fakeAcker struct {
1283
- mock.Mock
1284
- }
1285
-
1286
- func (f * fakeAcker ) Ack (ctx context.Context , action fleetapi.Action ) error {
1287
- args := f .Called (ctx , action )
1288
- return args .Error (0 )
1289
- }
1290
-
1291
- func (f * fakeAcker ) Commit (ctx context.Context ) error {
1292
- args := f .Called (ctx )
1293
- return args .Error (0 )
1294
- }
0 commit comments