mirror of
https://github.com/lukaszraczylo/go-simple-graphql.git
synced 2026-10-19 01:27:43 +00:00
fixup! Update dependencies Fix go mod version in mod file.
This commit is contained in:
+64
-1
@@ -1,6 +1,9 @@
|
|||||||
package gql
|
package gql
|
||||||
|
|
||||||
import "testing"
|
import (
|
||||||
|
"reflect"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
func (suite *Tests) Test_searchForKeysInMapStringInterface() {
|
func (suite *Tests) Test_searchForKeysInMapStringInterface() {
|
||||||
type args struct {
|
type args struct {
|
||||||
@@ -41,3 +44,63 @@ func (suite *Tests) Test_searchForKeysInMapStringInterface() {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (suite *Tests) TestBaseClient_decodeResponse() {
|
||||||
|
type args struct {
|
||||||
|
response []byte
|
||||||
|
}
|
||||||
|
tests := []struct {
|
||||||
|
name string
|
||||||
|
args args
|
||||||
|
want any
|
||||||
|
wantErr bool
|
||||||
|
setType string
|
||||||
|
wantType string
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "TestBaseClient_decodeResponse_mapstring",
|
||||||
|
args: args{
|
||||||
|
response: []byte(`{"data":{"viewer":{"login":"lukaszraczylo"}}}`),
|
||||||
|
},
|
||||||
|
want: map[string]interface{}{
|
||||||
|
"data": map[string]interface{}{
|
||||||
|
"viewer": map[string]interface{}{
|
||||||
|
"login": "lukaszraczylo",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
setType: "mapstring",
|
||||||
|
wantType: "map[string]interface {}",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "TestBaseClient_decodeResponse_string",
|
||||||
|
args: args{
|
||||||
|
response: []byte(`{"data":{"viewer":{"login":"lukaszraczylo"}}}`),
|
||||||
|
},
|
||||||
|
want: `{"data":{"viewer":{"login":"lukaszraczylo"}}}`,
|
||||||
|
setType: "string",
|
||||||
|
wantType: "string",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "TestBaseClient_decodeResponse_byte",
|
||||||
|
args: args{
|
||||||
|
response: []byte(`{"data":{"viewer":{"login":"lukaszraczylo"}}}`),
|
||||||
|
},
|
||||||
|
want: []byte(`{"data":{"viewer":{"login":"lukaszraczylo"}}}`),
|
||||||
|
setType: "byte",
|
||||||
|
wantType: "[]uint8",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
for _, tt := range tests {
|
||||||
|
suite.T().Run(tt.name, func(t *testing.T) {
|
||||||
|
b := NewConnection()
|
||||||
|
b.SetOutput(tt.setType)
|
||||||
|
got, err := b.decodeResponse(tt.args.response)
|
||||||
|
if (err != nil) != tt.wantErr {
|
||||||
|
t.Errorf("decodeResponse() error = %v, wantErr %v", err, tt.wantErr)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
assert.Equal(tt.wantType, reflect.TypeOf(got).String())
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -235,6 +235,20 @@ func (suite *Tests) TestBaseClient_Query() {
|
|||||||
wantReturned_value: []byte(`{"__type":null}`),
|
wantReturned_value: []byte(`{"__type":null}`),
|
||||||
wantErr: false,
|
wantErr: false,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "TestBaseClient_Query_tgbotapp_valid_query_string",
|
||||||
|
graphQLServer: "https://telegram-bot.app/v1/graphql",
|
||||||
|
wantType: "string",
|
||||||
|
args: args{
|
||||||
|
query: `query {
|
||||||
|
__type(name: "Query") {
|
||||||
|
name
|
||||||
|
}
|
||||||
|
}`,
|
||||||
|
},
|
||||||
|
wantReturned_value: string(`{"__type":null}`),
|
||||||
|
wantErr: false,
|
||||||
|
},
|
||||||
{
|
{
|
||||||
name: "TestBaseClient_Query_tgbotapp_valid_query_invalid_type",
|
name: "TestBaseClient_Query_tgbotapp_valid_query_invalid_type",
|
||||||
graphQLServer: "https://telegram-bot.app/v1/graphql",
|
graphQLServer: "https://telegram-bot.app/v1/graphql",
|
||||||
|
|||||||
Reference in New Issue
Block a user