Skip to content

Commit 2869fbb

Browse files
committed
graphql_test: adds Result.ErrorsJoined 100& test coverage unit tests
1 parent 3b34f75 commit 2869fbb

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

graphql_test.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@ package graphql_test
22

33
import (
44
"context"
5+
"errors"
56
"reflect"
67
"testing"
78

89
"github.com/graphql-go/graphql"
10+
"github.com/graphql-go/graphql/gqlerrors"
911
"github.com/graphql-go/graphql/testutil"
1012
)
1113

@@ -268,3 +270,32 @@ func TestEmptyStringIsNotNull(t *testing.T) {
268270
t.Errorf("wrong result, query: %v, graphql result diff: %v", query, testutil.Diff(expected, result))
269271
}
270272
}
273+
274+
func TestResultErrorsJoinedFailure(t *testing.T) {
275+
r := graphql.Result{}
276+
277+
if err := r.ErrorsJoined(); err != nil {
278+
t.Fatalf("wrong result, want: nil, got: %v", err)
279+
}
280+
}
281+
282+
func TestResultErrorsJoinedSuccess(t *testing.T) {
283+
r := graphql.Result{
284+
Errors: []gqlerrors.FormattedError{
285+
{Message: "first error"},
286+
{Message: "second error"},
287+
},
288+
}
289+
290+
expected := errors.New("second error: first error")
291+
292+
if err := r.ErrorsJoined(); err != nil {
293+
if !reflect.DeepEqual(err.Error(), expected.Error()) {
294+
t.Fatalf("wrong result, want: %v, got: %v", expected, err)
295+
}
296+
297+
return
298+
}
299+
300+
t.Fatalf("wrong result, got: nil, want: %v", expected)
301+
}

0 commit comments

Comments
 (0)