@@ -1143,6 +1143,22 @@ func TestManualRollback(t *testing.T) {
1143
1143
},
1144
1144
additionalAsserts : nil ,
1145
1145
},
1146
+ {
1147
+ name : "update marker is malformed - rollback fails" ,
1148
+ setup : func (t * testing.T , topDir string , agent * infomocks.Agent , watcherHelper * MockWatcherHelper ) {
1149
+ err := os .WriteFile (markerFilePath (paths .DataFrom (topDir )), []byte ("this is not a proper YAML file" ), 0600 )
1150
+ require .NoError (t , err , "error setting up update marker" )
1151
+ locker := filelock .NewAppLocker (topDir , "watcher.lock" )
1152
+ err = locker .TryLock ()
1153
+ require .NoError (t , err , "error locking initial watcher AppLocker" )
1154
+ // there's no takeover watcher so no expectation on that or InvokeWatcher
1155
+ },
1156
+ artifactSettings : artifact .DefaultConfig (),
1157
+ upgradeSettings : configuration .DefaultUpgradeConfig (),
1158
+ version : "1.2.3" ,
1159
+ wantErr : assert .Error ,
1160
+ additionalAsserts : nil ,
1161
+ },
1146
1162
{
1147
1163
name : "update marker ok but rollback available is empty - error" ,
1148
1164
setup : func (t * testing.T , topDir string , agent * infomocks.Agent , watcherHelper * MockWatcherHelper ) {
@@ -1152,6 +1168,9 @@ func TestManualRollback(t *testing.T) {
1152
1168
err = locker .TryLock ()
1153
1169
require .NoError (t , err , "error locking initial watcher AppLocker" )
1154
1170
watcherHelper .EXPECT ().TakeOverWatcher (t .Context (), mock .Anything , topDir ).Return (locker , nil )
1171
+ newerWatcherExecutable := filepath .Join (topDir , "data" , "elastic-agent-4.5.6-newver" , "elastic-agent" )
1172
+ watcherHelper .EXPECT ().SelectWatcherExecutable (topDir , agentInstall123 , agentInstall456 ).Return (newerWatcherExecutable )
1173
+ watcherHelper .EXPECT ().InvokeWatcher (mock .Anything , newerWatcherExecutable ).Return (& exec.Cmd {Path : newerWatcherExecutable , Args : []string {"watch" , "for realsies" }}, nil )
1155
1174
},
1156
1175
artifactSettings : artifact .DefaultConfig (),
1157
1176
upgradeSettings : configuration .DefaultUpgradeConfig (),
@@ -1178,6 +1197,9 @@ func TestManualRollback(t *testing.T) {
1178
1197
err = locker .TryLock ()
1179
1198
require .NoError (t , err , "error locking initial watcher AppLocker" )
1180
1199
watcherHelper .EXPECT ().TakeOverWatcher (t .Context (), mock .Anything , topDir ).Return (locker , nil )
1200
+ newerWatcherExecutable := filepath .Join (topDir , "data" , "elastic-agent-4.5.6-newver" , "elastic-agent" )
1201
+ watcherHelper .EXPECT ().SelectWatcherExecutable (topDir , agentInstall123 , agentInstall456 ).Return (newerWatcherExecutable )
1202
+ watcherHelper .EXPECT ().InvokeWatcher (mock .Anything , newerWatcherExecutable ).Return (& exec.Cmd {Path : newerWatcherExecutable , Args : []string {"watch" , "for realsies" }}, nil )
1181
1203
},
1182
1204
artifactSettings : artifact .DefaultConfig (),
1183
1205
upgradeSettings : configuration .DefaultUpgradeConfig (),
@@ -1204,6 +1226,9 @@ func TestManualRollback(t *testing.T) {
1204
1226
err = locker .TryLock ()
1205
1227
require .NoError (t , err , "error locking initial watcher AppLocker" )
1206
1228
watcherHelper .EXPECT ().TakeOverWatcher (t .Context (), mock .Anything , topDir ).Return (locker , nil )
1229
+ newerWatcherExecutable := filepath .Join (topDir , "data" , "elastic-agent-4.5.6-newver" , "elastic-agent" )
1230
+ watcherHelper .EXPECT ().SelectWatcherExecutable (topDir , agentInstall123 , agentInstall456 ).Return (newerWatcherExecutable )
1231
+ watcherHelper .EXPECT ().InvokeWatcher (mock .Anything , newerWatcherExecutable ).Return (& exec.Cmd {Path : newerWatcherExecutable , Args : []string {"watch" , "for realsies" }}, nil )
1207
1232
},
1208
1233
artifactSettings : artifact .DefaultConfig (),
1209
1234
upgradeSettings : configuration .DefaultUpgradeConfig (),
0 commit comments