github.com/operandinc/gqlgen@v0.16.1/codegen/testserver/singlefile/v-ok_test.go (about)

     1  package singlefile
     2  
     3  import (
     4  	"context"
     5  	"testing"
     6  
     7  	"github.com/stretchr/testify/require"
     8  
     9  	"github.com/operandinc/gqlgen/client"
    10  	"github.com/operandinc/gqlgen/graphql/handler"
    11  )
    12  
    13  func TestOk(t *testing.T) {
    14  	resolver := &Stub{}
    15  	resolver.QueryResolver.VOkCaseValue = func(ctx context.Context) (*VOkCaseValue, error) {
    16  		return &VOkCaseValue{}, nil
    17  	}
    18  	resolver.QueryResolver.VOkCaseNil = func(ctx context.Context) (*VOkCaseNil, error) {
    19  		return &VOkCaseNil{}, nil
    20  	}
    21  
    22  	c := client.New(handler.NewDefaultServer(
    23  		NewExecutableSchema(Config{Resolvers: resolver}),
    24  	))
    25  
    26  	t.Run("v ok case value", func(t *testing.T) {
    27  		var resp struct {
    28  			VOkCaseValue struct {
    29  				Value string
    30  			}
    31  		}
    32  		err := c.Post(`query { vOkCaseValue { value } }`, &resp)
    33  		require.NoError(t, err)
    34  		require.Equal(t, resp.VOkCaseValue.Value, "hi")
    35  	})
    36  
    37  	t.Run("v ok case nil", func(t *testing.T) {
    38  		var resp struct {
    39  			VOkCaseNil struct {
    40  				Value *string
    41  			}
    42  		}
    43  		err := c.Post(`query { vOkCaseNil { value } }`, &resp)
    44  		require.NoError(t, err)
    45  		require.Equal(t, true, resp.VOkCaseNil.Value == nil)
    46  	})
    47  }