MCPcopy Create free account
hub / github.com/dank/rlapi / TestPsyNetRPC_BuildMessage

Function TestPsyNetRPC_BuildMessage

psynetrpc_test.go:524–573  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

522}
523
524func TestPsyNetRPC_BuildMessage(t *testing.T) {
525 rpc := &PsyNetRPC{}
526
527 t.Run("request with no body", func(t *testing.T) {
528 headers := map[string]string{"PsyPing": ""}
529 message, err := rpc.buildMessage(headers, nil)
530 if err != nil {
531 t.Fatalf("unexpected error: %v", err)
532 }
533
534 expected := "PsyPing: \r\n\r\n"
535 if message != expected {
536 t.Errorf("message = %q, want %q", message, expected)
537 }
538 })
539
540 t.Run("request with body", func(t *testing.T) {
541 headers := map[string]string{
542 "PsyService": "Shops/GetStandardShops",
543 "PsyRequestID": "PsyNetMessage_X_123",
544 }
545 requestData := map[string]interface{}{"test": "data"}
546
547 message, err := rpc.buildMessage(headers, requestData)
548 if err != nil {
549 t.Fatalf("unexpected error: %v", err)
550 }
551
552 // Should contain all headers including auto-generated PsySig
553 if !strings.Contains(message, "PsyService: Shops/GetStandardShops\r\n") {
554 t.Error("missing PsyService header")
555 }
556 if !strings.Contains(message, "PsyRequestID: PsyNetMessage_X_123\r\n") {
557 t.Error("missing PsyRequestID header")
558 }
559 if !strings.Contains(message, "PsySig:") {
560 t.Error("missing PsySig header")
561 }
562
563 // Should contain JSON body
564 if !strings.Contains(message, `{"test":"data"}`) {
565 t.Error("missing JSON body")
566 }
567
568 // Should have proper structure with delimiter
569 if !strings.Contains(message, "\r\n\r\n") {
570 t.Error("missing header/body delimiter")
571 }
572 })
573}
574
575func TestPsyNetRPC_IsConnected(t *testing.T) {
576 mockServer := NewMockWSServer()

Callers

nothing calls this directly

Calls 2

buildMessageMethod · 0.95
ErrorMethod · 0.80

Tested by

no test coverage detected