testutil

package
v0.250524.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 24, 2025 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	//go:embed introspection-query.graphql
	IntrospectionQuery string

	//go:embed applied-directive-introspection-query.graphql
	AppliedDirectiveIntrospectionQuery string
)
View Source
var TestSchema *graphql.Schema

Functions

func ASTToJSON

func ASTToJSON(t *testing.T, a ast.Node) any

func ContainSubset

func ContainSubset(super map[string]any, sub map[string]any) bool

func ContainSubsetSlice

func ContainSubsetSlice(super []any, sub []any) bool

func ContextValue added in v0.0.3

func ContextValue(ctx context.Context, k string) any

ContextValue retrieves a value from the context.

func ContextWithValue added in v0.0.3

func ContextWithValue(ctx context.Context, k string, v any) context.Context

ContextWithValue inserts value into the context.

func Diff

func Diff(want, got any) []string

func EqualErrorMessage

func EqualErrorMessage(expected, result *graphql.Result, i int) bool

func EqualFormattedError

func EqualFormattedError(exp, act gqlerrors.FormattedError) bool

func EqualFormattedErrors

func EqualFormattedErrors(expected, actual []gqlerrors.FormattedError) bool

func EqualResults

func EqualResults(expected, result *graphql.Result) bool

func ExpectFailsRule

func ExpectFailsRule(t *testing.T, rule graphql.ValidationRuleFn, queryString string, expectedErrors []gqlerrors.FormattedError)

func ExpectFailsRuleWithSchema

func ExpectFailsRuleWithSchema(t *testing.T, schema *graphql.Schema, rule graphql.ValidationRuleFn, queryString string, expectedErrors []gqlerrors.FormattedError)

func ExpectPassesRule

func ExpectPassesRule(t *testing.T, rule graphql.ValidationRuleFn, queryString string)

func ExpectPassesRuleWithSchema

func ExpectPassesRuleWithSchema(t *testing.T, schema *graphql.Schema, rule graphql.ValidationRuleFn, queryString string)

func PathFromRoot added in v0.0.3

func PathFromRoot(t testing.TB, components ...string) string

PathFromRoot calls RootDir and creates a path with the result and the provided slice of path components.

func RootDir added in v0.0.3

func RootDir(t testing.TB) string

RootDir returns an absolute path to the root of the module. It fatally fails the test if the runtime information could not be obtained.

func RuleError

func RuleError(message string, locs ...int) gqlerrors.FormattedError

func RunSubscribe

func RunSubscribe(t *testing.T, test *TestSubscription)

RunSubscribe runs a single GraphQL subscription test case.

func RunSubscribes

func RunSubscribes(t *testing.T, tests []*TestSubscription)

RunSubscribes runs the given GraphQL subscription test cases as subtests.

func TestExecute

func TestExecute(t *testing.T, ep graphql.ExecuteParams) *graphql.Result

func TestParse

func TestParse(t *testing.T, query string) *ast.Document

Types

type TestResponse

type TestResponse struct {
	Data   string
	Errors []string
}

TestResponse models the expected response

type TestSubscription

type TestSubscription struct {
	Name            string
	Schema          graphql.Schema
	Query           string
	OperationName   string
	Variables       map[string]any
	ExpectedResults []TestResponse
}

TestSubscription is a GraphQL test case to be used with RunSubscribe.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL