57 lines
1.6 KiB
Go
57 lines
1.6 KiB
Go
package onvif
|
|
|
|
import (
|
|
"context"
|
|
"path/filepath"
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
func TestFakeMapsProfilesStreamAndClockSync(t *testing.T) {
|
|
t.Parallel()
|
|
fake, err := LoadFakeFixture(filepath.Join("testdata", "scenarios.json"))
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
target := Target{EndpointRef: "onvif://camera-ok", CredentialRef: "secret://camera-ok"}
|
|
result, err := fake.Probe(context.Background(), target)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if len(result.Profiles) != 2 || result.StreamURI != "rtsp://media.invalid/camera-ok" {
|
|
t.Fatalf("unexpected fixture mapping: %+v", result)
|
|
}
|
|
if err := fake.SetSystemDateAndTime(context.Background(), target, time.Now()); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if fake.ProbeCalls(target.EndpointRef) != 1 || fake.ClockSyncCalls(target.EndpointRef) != 1 {
|
|
t.Fatal("expected one probe and one clock-sync call")
|
|
}
|
|
}
|
|
|
|
func TestFakeMapsAuthenticationFailure(t *testing.T) {
|
|
t.Parallel()
|
|
fake, err := LoadFakeFixture(filepath.Join("testdata", "scenarios.json"))
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
_, err = fake.Probe(context.Background(), Target{EndpointRef: "onvif://camera-auth"})
|
|
if CodeOf(err) != ErrorAuthentication {
|
|
t.Fatalf("expected authentication error, got %v", err)
|
|
}
|
|
}
|
|
|
|
func TestFakeHonorsCancellationAsTimeout(t *testing.T) {
|
|
t.Parallel()
|
|
fake, err := LoadFakeFixture(filepath.Join("testdata", "scenarios.json"))
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Millisecond)
|
|
defer cancel()
|
|
_, err = fake.Probe(ctx, Target{EndpointRef: "onvif://camera-slow"})
|
|
if CodeOf(err) != ErrorTimeout {
|
|
t.Fatalf("expected timeout error, got %v", err)
|
|
}
|
|
}
|