47 lines
1.9 KiB
Go
47 lines
1.9 KiB
Go
package admission
|
|
|
|
import (
|
|
"context"
|
|
"encoding/base64"
|
|
"testing"
|
|
"yovision.local/sense/app/sense/adapters/onvif"
|
|
"yovision.local/sense/app/sense/adapters/rtsp"
|
|
"yovision.local/sense/app/sense/device"
|
|
"yovision.local/sense/app/sense/identity"
|
|
"yovision.local/sense/internal/platform"
|
|
)
|
|
|
|
type fakeONVIF struct{}
|
|
|
|
func (fakeONVIF) Profiles(context.Context, string, onvif.Credential) ([]onvif.Profile, error) {
|
|
return []onvif.Profile{{Token: "main", Name: "主码流", Width: 1920, Height: 1080, Encoding: "H264", StreamURI: "rtsp://camera.invalid/main"}, {Token: "sub", Name: "子码流", Width: 640, Height: 360, Encoding: "H264", StreamURI: "rtsp://camera.invalid/sub"}}, nil
|
|
}
|
|
|
|
type fakeRTSP struct{}
|
|
|
|
func (fakeRTSP) Verify(context.Context, string, rtsp.Credential) (rtsp.Result, error) {
|
|
return rtsp.Result{Status: "ready"}, nil
|
|
}
|
|
func TestProbeProfilesWithoutCredentialURI(t *testing.T) {
|
|
vault, err := device.NewCredentialVault(base64.StdEncoding.EncodeToString([]byte("0123456789abcdef0123456789abcdef")), false)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
store := device.NewMemoryStore()
|
|
deviceService := device.NewService(store, vault)
|
|
module := device.NewModule(deviceService)
|
|
module.Register(platform.NewApp(platform.Config{DatabaseMode: platform.DatabaseModeMemory}, nil, nil))
|
|
item, err := deviceService.Create(context.Background(), identity.Principal{}, "camera", "", device.ModalityVideo, nil)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if _, err = deviceService.SetCredential(context.Background(), identity.Principal{}, item.ID, "fixture-user", "fixture-password"); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
service := NewService(fakeONVIF{}, fakeRTSP{}, "")
|
|
result, err := service.Probe(context.Background(), identity.Principal{}, item.ID, "http://camera.invalid/onvif/device_service")
|
|
if err != nil || result.Status != "ready" || result.Profiles[0].Kind != "main" || result.Profiles[1].Kind != "sub" {
|
|
t.Fatalf("result=%#v err=%v", result, err)
|
|
}
|
|
}
|