Initial commit.

This commit is contained in:
2021-10-02 16:46:19 +01:00
parent fc7dff7efc
commit 7ad04d7750
10 changed files with 845 additions and 259 deletions
+66
View File
@@ -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()
})
}
}