func TestQuery(t *testing.T) {
	t.Parallel()
	ts := graphql_test.NewServer(t, true)
	t.Cleanup(ts.Close)
	client := NewClient(ts.URL, DefaultClientOptions)
	var GetEntity graphql_test.GetEntity
	operation := Operation{
		OperationType: &GetEntity,
		Fields:        nil,
		Variables:     GetEntity.Variables(),
	}
	if err := client.Query(context.Background(), &operation); err != nil {
		t.Fatalf("error running query: %v", err)
	}
	ts.DiffResponse(GetEntity.ExpectedResponse(), GetEntity)
}
TestQuery tests the Query pointer receiver function on the Client type. Since this is
mostly a pass-through function to *Client.doStruct, this test is intentionally kept
simple.
package goql
import (
	"context"
	"errors"
	"net/http"
	"reflect"
	"testing"
	"time"
	"github.com/getoutreach/goql/graphql_test"
)
func TestNewClient(t *testing.T) {
	specificError := errors.New("this is a specific error")
	tt := []struct {
		Name                    string
		URL                     string
		Options                 ClientOptions
		SpecificErrorFromMapper error
	}{
		{
			Name:    "GoodDefaultOptions",
			URL:     "http://localhost:3403/graphql",
			Options: DefaultClientOptions,
			SpecificErrorFromMapper: Errors{
				{
					Message: "foo",
				},
				{
					Message: "bar",
				},
			},
		},
		{
			Name: "GoodCustomOptions",
			URL:  "http://localhost:3403/graphql",
			Options: ClientOptions{
				HTTPClient: &http.Client{
					Timeout: time.Duration(465) * time.Second,
				},
				ErrorMapper: func(_ int, _ Errors) error {
					return specificError
				},
			},
			SpecificErrorFromMapper: specificError,
		},
	}
	for _, test := range tt {
		test := test
		fn := func(t *testing.T) {
			t.Parallel()
			client := NewClient(test.URL, test.Options)
			if e, a := test.URL, client.url; e != a {
				t.Errorf("expected url to be \"%s\", got \"%s\"", e, a)
			}
			if reflect.DeepEqual(test.Options, DefaultClientOptions) {
				if e, a := http.DefaultClient.Timeout, client.httpClient.Timeout; e != a {
					t.Errorf("expected client's http client timeout to be \"%s\", got \"%s\"", e.String(), a.String())
				}
				if e, a := test.SpecificErrorFromMapper.Error(), client.errorMapper(http.StatusBadRequest, test.SpecificErrorFromMapper.(Errors)).Error(); e != a {
					t.Errorf("expected error returned from error mapper to be \"%s\", got \"%s\"", e, a)
				}
				return
			}
			if e, a := test.Options.HTTPClient.Timeout, client.httpClient.Timeout; e != a {
				t.Errorf("expected client's http client timeout to be \"%s\", got \"%s\"", e.String(), a.String())
			}
			if e, a := test.SpecificErrorFromMapper.Error(), client.errorMapper(http.StatusBadRequest, Errors{}).Error(); e != a {
				t.Errorf("expected error returned from error mapper to be \"%s\", got \"%s\"", e, a)
			}
		}
		t.Run(test.Name, fn)
	}
}
func TestQueryWithHeaders(t *testing.T) {
	t.Parallel()
	ts := graphql_test.NewServer(t, true)
	t.Cleanup(ts.Close)
	client := NewClient(ts.URL, DefaultClientOptions)
	var GetEntity graphql_test.GetEntity
	operation := Operation{
		OperationType: &GetEntity,
		Fields:        nil,
		Variables:     GetEntity.Variables(),
	}
	headers := http.Header{}
	if err := client.QueryWithHeaders(context.Background(), &operation, headers); err != nil {
		t.Fatalf("error running query with headers: %v", err)
	}
	ts.DiffResponse(GetEntity.ExpectedResponse(), GetEntity)
}