From 6b909cbfab09205ba8410c3a0470c38b5b8b7fab Mon Sep 17 00:00:00 2001
From: a <a@tuxpa.in>
Date: Wed, 7 Jun 2023 23:34:19 -0500
Subject: [PATCH] recvg

---
 pkg/jrpctest/testdata.go      | 40 ++++++++++++++++++-----------------
 pkg/jrpctest/testdata_test.go |  7 ++----
 2 files changed, 23 insertions(+), 24 deletions(-)

diff --git a/pkg/jrpctest/testdata.go b/pkg/jrpctest/testdata.go
index eab23a5..5000d90 100644
--- a/pkg/jrpctest/testdata.go
+++ b/pkg/jrpctest/testdata.go
@@ -40,9 +40,6 @@ func (td *TestData) AddTestData(name string, rd io.Reader) *TestData {
 		Name: name,
 	}
 	td.Files = append(td.Files, t)
-	currentPair := &TestPair{
-		Request: nil,
-	}
 	var (
 		arrowRight = []byte("-->")
 		arrowLeft  = []byte("<--")
@@ -58,24 +55,22 @@ func (td *TestData) AddTestData(name string, rd io.Reader) *TestData {
 			continue
 		}
 		if bytes.HasPrefix(txt, arrowRight) {
-			if currentPair.Request != nil {
-				t.Pairs = append(t.Pairs, currentPair)
-			}
-			currentPair = &TestPair{
-				Request: nil,
+			currentPair := &TestAction{
+				Direction: DirectionSend,
 			}
-			currentPair.Request = bytes.TrimSpace(bytes.TrimPrefix(txt, arrowRight))
+			currentPair.Data = bytes.TrimSpace(bytes.TrimPrefix(txt, arrowRight))
+			t.Action = append(t.Action, currentPair)
 			continue
 		}
 		if bytes.HasPrefix(txt, arrowLeft) {
-			xs := bytes.TrimSpace(bytes.TrimPrefix(txt, arrowLeft))
-			currentPair.Responses = append(currentPair.Responses, xs)
+			currentPair := &TestAction{
+				Direction: DirectionRecv,
+			}
+			currentPair.Data = bytes.TrimSpace(bytes.TrimPrefix(txt, arrowLeft))
+			t.Action = append(t.Action, currentPair)
 			continue
 		}
 	}
-	if currentPair.Request != nil {
-		t.Pairs = append(t.Pairs, currentPair)
-	}
 	return nil
 }
 
@@ -84,11 +79,18 @@ type TestData struct {
 }
 
 type TestFile struct {
-	Name  string
-	Pairs []*TestPair
+	Name   string
+	Action []*TestAction
 }
 
-type TestPair struct {
-	Request   json.RawMessage
-	Responses []json.RawMessage
+type TestDirection string
+
+const (
+	DirectionSend = TestDirection("send")
+	DirectionRecv = TestDirection("recv")
+)
+
+type TestAction struct {
+	Direction TestDirection
+	Data      json.RawMessage
 }
diff --git a/pkg/jrpctest/testdata_test.go b/pkg/jrpctest/testdata_test.go
index ac0ff19..e63c775 100644
--- a/pkg/jrpctest/testdata_test.go
+++ b/pkg/jrpctest/testdata_test.go
@@ -12,11 +12,8 @@ func TestLoadTestData(t *testing.T) {
 	log.Println(jrpctest.OriginalTestData)
 	for _, file := range jrpctest.OriginalTestData.Files {
 		fmt.Printf("file %s:\n", file.Name)
-		for idx, pair := range file.Pairs {
-			fmt.Printf(" %d --> %s\n", idx, string(pair.Request))
-			for _, v := range pair.Responses {
-				fmt.Printf("   <-- %s\n", string(v))
-			}
+		for idx, pair := range file.Action {
+			fmt.Printf(" %d %s %s\n", idx, pair.Direction, string(pair.Data))
 		}
 	}
 }
-- 
GitLab