feat(sense): implement Control API v1 [T-011]
This commit is contained in:
@@ -15,6 +15,7 @@ import (
|
||||
type recordingMedia struct {
|
||||
calls int
|
||||
changed int
|
||||
deleted int
|
||||
paths map[string]string
|
||||
}
|
||||
|
||||
@@ -31,6 +32,15 @@ func (m *recordingMedia) EnsurePath(_ context.Context, name, source string) (boo
|
||||
return true, nil
|
||||
}
|
||||
|
||||
func (m *recordingMedia) DeletePath(_ context.Context, name string) error {
|
||||
m.calls++
|
||||
if m.paths != nil {
|
||||
delete(m.paths, name)
|
||||
}
|
||||
m.deleted++
|
||||
return nil
|
||||
}
|
||||
|
||||
func TestReconcileConvergesOnceAndPersistsGeneration(t *testing.T) {
|
||||
t.Parallel()
|
||||
repository := openRepository(t, filepath.Join(t.TempDir(), "sense.db"))
|
||||
@@ -132,6 +142,26 @@ func TestCancellationDoesNotPersistFailure(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestDisabledDeviceDeletesOnlyItsExactPath(t *testing.T) {
|
||||
repository := openRepository(t, filepath.Join(t.TempDir(), "sense.db"))
|
||||
createReconcileDevice(t, repository)
|
||||
media := &recordingMedia{paths: map[string]string{"camera-1": "source", "other": "keep"}}
|
||||
if err := repository.SetDesiredState(context.Background(), "camera-1", device.DesiredDisabled); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
reconciler := New(repository, onvif.NewFake(nil), media)
|
||||
if err := reconciler.RunOnce(context.Background()); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if media.deleted != 1 || media.paths["other"] != "keep" {
|
||||
t.Fatalf("disabled convergence touched the wrong paths: %+v", media.paths)
|
||||
}
|
||||
value, err := repository.GetDevice(context.Background(), "camera-1")
|
||||
if err != nil || value.ActualState != device.ActualOffline {
|
||||
t.Fatalf("disabled device did not converge offline: %+v %v", value, err)
|
||||
}
|
||||
}
|
||||
|
||||
func openRepository(t *testing.T, path string) *store.SQLite {
|
||||
t.Helper()
|
||||
repository, err := store.OpenSQLite(context.Background(), "file:"+filepath.ToSlash(path))
|
||||
|
||||
Reference in New Issue
Block a user