Skip to content

Commit bc7ea71

Browse files
committed
test(rhc-server): add unit tests for backend implementation
Add comprehensive unit tests for the Backend struct and its Test method in cmd/rhc-server. Tests cover various input scenarios. Signed-off-by: mjcr99 <[email protected]> Assisted-by: Claude Code
1 parent 25a42c4 commit bc7ea71

1 file changed

Lines changed: 96 additions & 0 deletions

File tree

cmd/rhc-server/rhc-server_test.go

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
package main
2+
3+
import (
4+
"testing"
5+
6+
"github.com/google/go-cmp/cmp"
7+
8+
"github.com/redhatinsights/rhc/varlink/internalapi"
9+
)
10+
11+
func TestNewBackend(t *testing.T) {
12+
backend := NewBackend()
13+
14+
if backend == nil {
15+
t.Fatal("NewBackend() returned nil")
16+
}
17+
}
18+
19+
func TestBackend_Test(t *testing.T) {
20+
tests := []struct {
21+
description string
22+
input *internalapi.TestIn
23+
want *internalapi.TestOut
24+
}{
25+
{
26+
description: "simple message",
27+
input: &internalapi.TestIn{
28+
Input: "hello",
29+
},
30+
want: &internalapi.TestOut{
31+
Output: "Echo from rhc-server: hello",
32+
},
33+
},
34+
{
35+
description: "empty string",
36+
input: &internalapi.TestIn{
37+
Input: "",
38+
},
39+
want: &internalapi.TestOut{
40+
Output: "Echo from rhc-server: ",
41+
},
42+
},
43+
{
44+
description: "message with special characters",
45+
input: &internalapi.TestIn{
46+
Input: "hello!@#$%^&*()",
47+
},
48+
want: &internalapi.TestOut{
49+
Output: "Echo from rhc-server: hello!@#$%^&*()",
50+
},
51+
},
52+
{
53+
description: "message with newlines",
54+
input: &internalapi.TestIn{
55+
Input: "line1\nline2\nline3",
56+
},
57+
want: &internalapi.TestOut{
58+
Output: "Echo from rhc-server: line1\nline2\nline3",
59+
},
60+
},
61+
{
62+
description: "message with unicode",
63+
input: &internalapi.TestIn{
64+
Input: "Hello 世界 🌍",
65+
},
66+
want: &internalapi.TestOut{
67+
Output: "Echo from rhc-server: Hello 世界 🌍",
68+
},
69+
},
70+
{
71+
description: "very long message",
72+
input: &internalapi.TestIn{
73+
Input: string(make([]byte, 10000)),
74+
},
75+
want: &internalapi.TestOut{
76+
Output: "Echo from rhc-server: " + string(make([]byte, 10000)),
77+
},
78+
},
79+
}
80+
81+
backend := NewBackend()
82+
83+
for _, test := range tests {
84+
t.Run(test.description, func(t *testing.T) {
85+
got, err := backend.Test(test.input)
86+
87+
if err != nil {
88+
t.Errorf("Backend.Test(%v) unexpected error: %v", test.input, err)
89+
}
90+
91+
if !cmp.Equal(got, test.want) {
92+
t.Errorf("Backend.Test(%v) = %v; want %v", test.input, got, test.want)
93+
}
94+
})
95+
}
96+
}

0 commit comments

Comments
 (0)