mirror of
https://github.com/lukaszraczylo/go-simple-graphql.git
synced 2026-10-12 00:45:31 +00:00
Initial commit.
This commit is contained in:
@@ -0,0 +1,66 @@
|
||||
package gql
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func Benchmark_connHandler_Query(t *testing.B) {
|
||||
type args struct {
|
||||
queryContent string
|
||||
queryVariables interface{}
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
endpoint string
|
||||
isLocal bool
|
||||
args args
|
||||
wantResult string
|
||||
mockedReply string
|
||||
wantErr bool
|
||||
}{
|
||||
{
|
||||
name: "Valid query",
|
||||
endpoint: "http://hasura.local/v1/graphql",
|
||||
isLocal: false,
|
||||
args: args{
|
||||
queryContent: `query listUserBots {
|
||||
tbl_bots(limit: 1) {
|
||||
bot_name
|
||||
}
|
||||
}`,
|
||||
queryVariables: nil,
|
||||
},
|
||||
wantResult: `{"tbl_bots":[{"bot_name":"littleMentionBot"}]}`,
|
||||
mockedReply: `{"data":{"tbl_bots":[{"bot_name":"littleMentionBot"}]}}`,
|
||||
wantErr: false,
|
||||
},
|
||||
{
|
||||
name: "Invalid query",
|
||||
endpoint: "http://hasura.local/v1/graphql",
|
||||
isLocal: false,
|
||||
args: args{
|
||||
queryContent: `query listUserBots {
|
||||
tbl_botz(limit: 1) {
|
||||
bot_name
|
||||
}
|
||||
}`,
|
||||
queryVariables: nil,
|
||||
},
|
||||
mockedReply: `{"errors":[{"message":"Unknown field \"tbl_botz\" on type \"Query\""}]}`,
|
||||
wantResult: ``,
|
||||
wantErr: true,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.B) {
|
||||
g := NewConnection()
|
||||
server, serverURL := mockGraphQLServerResponses(tt.mockedReply)
|
||||
g.Endpoint = serverURL
|
||||
for n := 0; n < t.N; n++ {
|
||||
g.Query(tt.args.queryContent, tt.args.queryVariables)
|
||||
}
|
||||
server.Close()
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user