mirror of
https://github.com/AvengeMedia/DankMaterialShell.git
synced 2025-12-07 22:15:38 -05:00
42 lines
763 B
Go
42 lines
763 B
Go
package bluez
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
func TestBrokerIntegration(t *testing.T) {
|
|
broker := NewSubscriptionBroker(nil)
|
|
ctx := context.Background()
|
|
|
|
req := PromptRequest{
|
|
DevicePath: "/org/bluez/test",
|
|
DeviceName: "TestDevice",
|
|
RequestType: "pin",
|
|
Fields: []string{"pin"},
|
|
}
|
|
|
|
token, err := broker.Ask(ctx, req)
|
|
if err != nil {
|
|
t.Fatalf("Ask failed: %v", err)
|
|
}
|
|
|
|
go func() {
|
|
time.Sleep(50 * time.Millisecond)
|
|
broker.Resolve(token, PromptReply{
|
|
Secrets: map[string]string{"pin": "1234"},
|
|
Accept: true,
|
|
})
|
|
}()
|
|
|
|
reply, err := broker.Wait(ctx, token)
|
|
if err != nil {
|
|
t.Fatalf("Wait failed: %v", err)
|
|
}
|
|
|
|
if reply.Secrets["pin"] != "1234" {
|
|
t.Errorf("expected pin=1234, got %s", reply.Secrets["pin"])
|
|
}
|
|
}
|