feat: backend native executor implement
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
package backendupdate
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
"yms-daemon/internal/daemonapi"
|
||||
"yms-daemon/internal/transaction"
|
||||
)
|
||||
|
||||
func TestRestartRejectsUnfinishedBackendUpdate(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
store, err := transaction.OpenStore(ctx, filepath.Join(t.TempDir(), "transactions.db"))
|
||||
if err != nil {
|
||||
t.Fatalf("open transaction store: %v", err)
|
||||
}
|
||||
defer store.Close()
|
||||
request, err := json.Marshal(persistedRequest{InputType: daemonapi.InputTypeNativeJAR})
|
||||
if err != nil {
|
||||
t.Fatalf("encode unfinished update request: %v", err)
|
||||
}
|
||||
active, _, err := store.CreateTransaction(ctx, transaction.CreateRequest{
|
||||
ID: "unfinished-backend-update",
|
||||
IdempotencyKey: "backend:update:unfinished",
|
||||
Source: sourceLocalCLI,
|
||||
Service: serviceBackend,
|
||||
Request: request,
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("create unfinished update transaction: %v", err)
|
||||
}
|
||||
updater := &Updater{store: store}
|
||||
record, err := updater.Restart(ctx, nil)
|
||||
if !errors.Is(err, transaction.ErrActiveExists) || record.ID != active.ID {
|
||||
t.Fatalf("unexpected restart result with unfinished update: record=%+v err=%v", record, err)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user