test(sidecar): collapse scalar-forwarding RPC tests into a table

This commit is contained in:
pj committed 2026-06-06 13:43:01 +05:30
1 parent d6afef7d07
commit 3cd1319f90
1 file changed
+40 -52
+40 -52
View File
@@ -320,16 +320,47 @@ func TestClient_TapAndTapSelector(t *testing.T) {
} }
} }
func TestClient_InputText(t *testing.T) { // TestClient_ScalarForwardingRPCs pins that each single-payload RPC forwards
state := newHarness(t) // its argument unchanged to the captured request: a dropped/mistyped text,
client, _ := Dial(state.address) // idle duration, erase count, or logical key would change device behavior with
defer client.Close() // no other field to disambiguate it.
func TestClient_ScalarForwardingRPCs(t *testing.T) {
if err := client.InputText(context.Background(), "hello world"); err != nil { tests := []struct {
t.Fatal(err) name string
call func(c *Client) error
check func(t *testing.T, s *fakeServer)
}{
{"InputText", func(c *Client) error { return c.InputText(context.Background(), "hello world") }, func(t *testing.T, s *fakeServer) {
if len(s.inputs) != 1 || s.inputs[0] != "hello world" {
t.Errorf("inputs wrong: %v", s.inputs)
}
}},
{"WaitForIdle", func(c *Client) error { return c.WaitForIdle(context.Background(), 250*time.Millisecond) }, func(t *testing.T, s *fakeServer) {
if len(s.idleMillis) != 1 || s.idleMillis[0] != 250 {
t.Errorf("idleMillis wrong: %v", s.idleMillis)
}
}},
{"EraseText", func(c *Client) error { return c.EraseText(context.Background(), 7) }, func(t *testing.T, s *fakeServer) {
if len(s.erases) != 1 || s.erases[0] != 7 {
t.Errorf("erase count wrong: %v", s.erases)
}
}},
{"PressKey", func(c *Client) error { return c.PressKey(context.Background(), "back") }, func(t *testing.T, s *fakeServer) {
if len(s.pressedKeys) != 1 || s.pressedKeys[0] != "back" {
t.Errorf("pressed key wrong: %v", s.pressedKeys)
}
}},
} }
if len(state.fake.inputs) != 1 || state.fake.inputs[0] != "hello world" { for _, tt := range tests {
t.Errorf("inputs wrong: %v", state.fake.inputs) t.Run(tt.name, func(t *testing.T) {
state := newHarness(t)
client, _ := Dial(state.address)
defer client.Close()
if err := tt.call(client); err != nil {
t.Fatal(err)
}
tt.check(t, state.fake)
})
} }
} }
@@ -372,19 +403,6 @@ func TestClient_SnapshotPairsHierarchyAndScreenshot(t *testing.T) {
} }
} }
func TestClient_WaitForIdleForwardsMillis(t *testing.T) {
state := newHarness(t)
client, _ := Dial(state.address)
defer client.Close()
if err := client.WaitForIdle(context.Background(), 250*time.Millisecond); err != nil {
t.Fatal(err)
}
if len(state.fake.idleMillis) != 1 || state.fake.idleMillis[0] != 250 {
t.Errorf("idleMillis wrong: %v", state.fake.idleMillis)
}
}
// TestClient_RPCErrorSurfaces is the representative check that a gRPC error // TestClient_RPCErrorSurfaces is the representative check that a gRPC error
// status from the sidecar propagates out of an action RPC instead of being // status from the sidecar propagates out of an action RPC instead of being
// swallowed into a nil error. Per-method coverage of the sidecar-side status // swallowed into a nil error. Per-method coverage of the sidecar-side status
@@ -509,36 +527,6 @@ func TestClient_PointRPCsForwardCoordinates(t *testing.T) {
} }
} }
// TestClient_EraseTextForwardsCount catches a count dropped or mistyped on the
// way to EraseTextRequest.
func TestClient_EraseTextForwardsCount(t *testing.T) {
state := newHarness(t)
client, _ := Dial(state.address)
defer client.Close()
if err := client.EraseText(context.Background(), 7); err != nil {
t.Fatal(err)
}
if len(state.fake.erases) != 1 || state.fake.erases[0] != 7 {
t.Errorf("erase count wrong: %v", state.fake.erases)
}
}
// TestClient_PressKeyForwardsKey catches the logical key name being dropped or
// rewritten before it reaches the sidecar.
func TestClient_PressKeyForwardsKey(t *testing.T) {
state := newHarness(t)
client, _ := Dial(state.address)
defer client.Close()
if err := client.PressKey(context.Background(), "back"); err != nil {
t.Fatal(err)
}
if len(state.fake.pressedKeys) != 1 || state.fake.pressedKeys[0] != "back" {
t.Errorf("pressed key wrong: %v", state.fake.pressedKeys)
}
}
// TestClient_MetricsMapsResponseFields catches CPU/heap/total being read off // TestClient_MetricsMapsResponseFields catches CPU/heap/total being read off
// the wrong proto field, which would mislabel a memory regression as CPU. // the wrong proto field, which would mislabel a memory regression as CPU.
func TestClient_MetricsMapsResponseFields(t *testing.T) { func TestClient_MetricsMapsResponseFields(t *testing.T) {