Skip to content

Commit 8f9e4d0

Browse files
authored
Merge pull request #3 from jsr-probitas/copilot/fix-echo-partial-error
fix(echo-graphql): echoPartialError substring matching
2 parents 2d34ceb + a3ae579 commit 8f9e4d0

2 files changed

Lines changed: 58 additions & 2 deletions

File tree

echo-graphql/graph/resolver_test.go

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,8 @@ func TestEchoPartialError_ReturnsMixedResults(t *testing.T) {
105105
}
106106
if resp.EchoPartialError[1].Error == nil {
107107
t.Error("expected second error to be non-nil")
108+
} else if *resp.EchoPartialError[1].Error != "message contains 'error'" {
109+
t.Errorf("expected error message 'message contains 'error'', got %q", *resp.EchoPartialError[1].Error)
108110
}
109111

110112
// Third result: "world" - should have message, no error
@@ -116,6 +118,59 @@ func TestEchoPartialError_ReturnsMixedResults(t *testing.T) {
116118
}
117119
}
118120

121+
func TestEchoPartialError_ContainsErrorSubstring(t *testing.T) {
122+
c := setupTestClient(t)
123+
124+
testCases := []struct {
125+
input string
126+
shouldError bool
127+
}{
128+
{"success", false},
129+
{"error", true},
130+
{"ERROR", true},
131+
{"this is an error message", true},
132+
{"errorHandling", true},
133+
{"no problem here", false},
134+
{"Error: something went wrong", true},
135+
}
136+
137+
for _, tc := range testCases {
138+
t.Run(tc.input, func(t *testing.T) {
139+
var resp struct {
140+
EchoPartialError []struct {
141+
Message *string
142+
Error *string
143+
}
144+
}
145+
query := `query { echoPartialError(messages: ["` + tc.input + `"]) { message error } }`
146+
c.MustPost(query, &resp)
147+
148+
if len(resp.EchoPartialError) != 1 {
149+
t.Fatalf("expected 1 result, got %d", len(resp.EchoPartialError))
150+
}
151+
152+
result := resp.EchoPartialError[0]
153+
if tc.shouldError {
154+
if result.Message != nil {
155+
t.Errorf("expected message to be nil for %q, got %v", tc.input, *result.Message)
156+
}
157+
if result.Error == nil {
158+
t.Errorf("expected error to be non-nil for %q", tc.input)
159+
} else if *result.Error != "message contains 'error'" {
160+
t.Errorf("expected error message 'message contains 'error'', got %q", *result.Error)
161+
}
162+
} else {
163+
if result.Message == nil || *result.Message != tc.input {
164+
t.Errorf("expected message to be %q, got %v", tc.input, result.Message)
165+
}
166+
if result.Error != nil {
167+
t.Errorf("expected error to be nil for %q, got %v", tc.input, *result.Error)
168+
}
169+
}
170+
})
171+
}
172+
}
173+
119174
func TestEchoWithExtensions_ReturnsMessage(t *testing.T) {
120175
c := setupTestClient(t)
121176

echo-graphql/graph/schema.resolvers.go

Lines changed: 3 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)