feat: establish NekoNest Cloud control and relay
This commit is contained in:
@@ -0,0 +1,64 @@
|
||||
package purge
|
||||
|
||||
import (
|
||||
"context"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
"github.com/klarkxy/nekonest-cloud/relay/internal/controlplane"
|
||||
"github.com/klarkxy/nekonest-cloud/relay/internal/tenantfs"
|
||||
)
|
||||
|
||||
type fakeRegistry struct{ calls int }
|
||||
|
||||
func (registry *fakeRegistry) QuiesceForPurge(string, int64) error {
|
||||
registry.calls++
|
||||
return nil
|
||||
}
|
||||
|
||||
type fakeControl struct{ updates []controlplane.PurgeAdvance }
|
||||
|
||||
func (control *fakeControl) AdvancePurge(_ context.Context, update controlplane.PurgeAdvance) error {
|
||||
control.updates = append(control.updates, update)
|
||||
return nil
|
||||
}
|
||||
|
||||
func TestManagerQuiescesDeletesAndReportsEvidence(t *testing.T) {
|
||||
const tenantID = "tenant_0123456789abcdef0123456789abcdef"
|
||||
dataRoot := t.TempDir()
|
||||
backupRoot := t.TempDir()
|
||||
paths, err := tenantfs.Resolve(dataRoot, tenantID)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := os.WriteFile(paths.Database, []byte("data"), 0o600); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
backupTenant := filepath.Join(backupRoot, filepath.Base(paths.Root), "backup")
|
||||
if err := os.MkdirAll(backupTenant, 0o700); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
registry := &fakeRegistry{}
|
||||
control := &fakeControl{}
|
||||
manager, err := New(Config{
|
||||
DataRoot: dataRoot, BackupRoot: backupRoot, Registry: registry, ControlPlane: control,
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
assignment := controlplane.PurgeAssignment{
|
||||
PurgeID: "purge_0123456789abcdef0123456789abcdef",
|
||||
TenantID: tenantID, PlacementGeneration: 7,
|
||||
}
|
||||
if err := manager.process(context.Background(), assignment); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if registry.calls != 1 || len(control.updates) != 1 || control.updates[0].Action != "completed" ||
|
||||
len(control.updates[0].EvidenceSHA256) != 64 {
|
||||
t.Fatalf("registry=%d updates=%#v", registry.calls, control.updates)
|
||||
}
|
||||
if _, err := os.Lstat(paths.Root); !os.IsNotExist(err) {
|
||||
t.Fatalf("tenant data survived: %v", err)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user