本文整理汇总了Golang中github.com/graphql-go/graphql/testutil.Diff函数的典型用法代码示例。如果您正苦于以下问题:Golang Diff函数的具体用法?Golang Diff怎么用?Golang Diff使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Diff函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: TestVariables_ObjectsAndNullability_UsingVariables_ErrorsOnIncorrectType
func TestVariables_ObjectsAndNullability_UsingVariables_ErrorsOnIncorrectType(t *testing.T) {
params := map[string]interface{}{
"input": "foo bar",
}
expected := &graphql.Result{
Data: nil,
Errors: []gqlerrors.FormattedError{
gqlerrors.FormattedError{
Message: `Variable "$input" expected value of type "TestInputObject" but ` +
`got: "foo bar".`,
Locations: []location.SourceLocation{
location.SourceLocation{
Line: 2, Column: 17,
},
},
},
},
}
ast := testVariables_ObjectsAndNullability_UsingVariables_GetAST(t)
// execute
ep := graphql.ExecuteParams{
Schema: variablesTestSchema,
AST: ast,
Args: params,
}
result := testutil.TestExecute(t, ep)
if len(result.Errors) != len(expected.Errors) {
t.Fatalf("Unexpected errors, Diff: %v", testutil.Diff(expected.Errors, result.Errors))
}
if !reflect.DeepEqual(expected, result) {
t.Fatalf("Unexpected result, Diff: %v", testutil.Diff(expected, result))
}
}
示例2: TestNonNull_NullsTheTopLevelIfSyncNonNullableFieldResolvesNull
func TestNonNull_NullsTheTopLevelIfSyncNonNullableFieldResolvesNull(t *testing.T) {
doc := `
query Q { nonNullPromise }
`
expected := &graphql.Result{
Data: nil,
Errors: []gqlerrors.FormattedError{
gqlerrors.FormattedError{
Message: `Cannot return null for non-nullable field DataType.nonNullPromise.`,
Locations: []location.SourceLocation{
location.SourceLocation{Line: 2, Column: 17},
},
},
},
}
// parse query
ast := testutil.TestParse(t, doc)
// execute
ep := graphql.ExecuteParams{
Schema: nonNullTestSchema,
AST: ast,
Root: nullingData,
}
result := testutil.TestExecute(t, ep)
if len(result.Errors) != len(expected.Errors) {
t.Fatalf("Unexpected errors, Diff: %v", testutil.Diff(expected.Errors, result.Errors))
}
if !reflect.DeepEqual(expected, result) {
t.Fatalf("Unexpected result, Diff: %v", testutil.Diff(expected, result))
}
}
示例3: TestVariables_UsesArgumentDefaultValues_WhenArgumentProvidedCannotBeParsed
func TestVariables_UsesArgumentDefaultValues_WhenArgumentProvidedCannotBeParsed(t *testing.T) {
doc := `
{
fieldWithDefaultArgumentValue(input: WRONG_TYPE)
}
`
expected := &graphql.Result{
Data: map[string]interface{}{
"fieldWithDefaultArgumentValue": `"Hello World"`,
},
}
ast := testutil.TestParse(t, doc)
// execute
ep := graphql.ExecuteParams{
Schema: variablesTestSchema,
AST: ast,
}
result := testutil.TestExecute(t, ep)
if len(result.Errors) != len(expected.Errors) {
t.Fatalf("Unexpected errors, Diff: %v", testutil.Diff(expected.Errors, result.Errors))
}
if !reflect.DeepEqual(expected, result) {
t.Fatalf("Unexpected result, Diff: %v", testutil.Diff(expected, result))
}
}
示例4: TestNonNull_NullsANullableFieldThatSynchronouslyReturnsNullInAPromise
func TestNonNull_NullsANullableFieldThatSynchronouslyReturnsNullInAPromise(t *testing.T) {
doc := `
query Q {
promise
}
`
expected := &graphql.Result{
Data: map[string]interface{}{
"promise": nil,
},
}
// parse query
ast := testutil.TestParse(t, doc)
// execute
ep := graphql.ExecuteParams{
Schema: nonNullTestSchema,
AST: ast,
Root: nullingData,
}
result := testutil.TestExecute(t, ep)
if len(result.Errors) != len(expected.Errors) {
t.Fatalf("Unexpected errors, Diff: %v", testutil.Diff(expected.Errors, result.Errors))
}
if !reflect.DeepEqual(expected.Data, result.Data) {
t.Fatalf("Unexpected result, Diff: %v", testutil.Diff(expected.Data, result.Data))
}
if !reflect.DeepEqual(expected.Errors, result.Errors) {
t.Fatalf("Unexpected result, Diff: %v", testutil.Diff(expected.Errors, result.Errors))
}
}
示例5: TestVariables_ListsAndNullability_AllowsNonNullListsOfNonNulsToContainValues
func TestVariables_ListsAndNullability_AllowsNonNullListsOfNonNulsToContainValues(t *testing.T) {
doc := `
query q($input: [String!]!) {
nnListNN(input: $input)
}
`
params := map[string]interface{}{
"input": []interface{}{"A"},
}
expected := &graphql.Result{
Data: map[string]interface{}{
"nnListNN": `["A"]`,
},
}
ast := testutil.TestParse(t, doc)
// execute
ep := graphql.ExecuteParams{
Schema: variablesTestSchema,
AST: ast,
Args: params,
}
result := testutil.TestExecute(t, ep)
if len(result.Errors) != len(expected.Errors) {
t.Fatalf("Unexpected errors, Diff: %v", testutil.Diff(expected.Errors, result.Errors))
}
if !reflect.DeepEqual(expected, result) {
t.Fatalf("Unexpected result, Diff: %v", testutil.Diff(expected, result))
}
}
示例6: TestVariables_ListsAndNullability_DoesNotAllowNonNullListsToBeNull
func TestVariables_ListsAndNullability_DoesNotAllowNonNullListsToBeNull(t *testing.T) {
doc := `
query q($input: [String]!) {
nnList(input: $input)
}
`
expected := &graphql.Result{
Data: nil,
Errors: []gqlerrors.FormattedError{
gqlerrors.FormattedError{
Message: `Variable "$input" of required type "[String]!" was not provided.`,
Locations: []location.SourceLocation{
location.SourceLocation{
Line: 2, Column: 17,
},
},
},
},
}
ast := testutil.TestParse(t, doc)
// execute
ep := graphql.ExecuteParams{
Schema: variablesTestSchema,
AST: ast,
}
result := testutil.TestExecute(t, ep)
if len(result.Errors) != len(expected.Errors) {
t.Fatalf("Unexpected errors, Diff: %v", testutil.Diff(expected.Errors, result.Errors))
}
if !reflect.DeepEqual(expected, result) {
t.Fatalf("Unexpected result, Diff: %v", testutil.Diff(expected, result))
}
}
示例7: TestPrinter_CorrectlyPrintsNonQueryOperationsWithoutName
func TestPrinter_CorrectlyPrintsNonQueryOperationsWithoutName(t *testing.T) {
// Test #1
queryAstShorthanded := `query { id, name }`
expected := `{
id
name
}
`
astDoc := parse(t, queryAstShorthanded)
results := printer.Print(astDoc)
if !reflect.DeepEqual(expected, results) {
t.Fatalf("Unexpected result, Diff: %v", testutil.Diff(results, expected))
}
// Test #2
mutationAst := `mutation { id, name }`
expected = `mutation {
id
name
}
`
astDoc = parse(t, mutationAst)
results = printer.Print(astDoc)
if !reflect.DeepEqual(expected, results) {
t.Fatalf("Unexpected result, Diff: %v", testutil.Diff(results, expected))
}
// Test #3
queryAstWithArtifacts := `query ($foo: TestType) @testDirective { id, name }`
expected = `query ($foo: TestType) @testDirective {
id
name
}
`
astDoc = parse(t, queryAstWithArtifacts)
results = printer.Print(astDoc)
if !reflect.DeepEqual(expected, results) {
t.Fatalf("Unexpected result, Diff: %v", testutil.Diff(results, expected))
}
// Test #4
mutationAstWithArtifacts := `mutation ($foo: TestType) @testDirective { id, name }`
expected = `mutation ($foo: TestType) @testDirective {
id
name
}
`
astDoc = parse(t, mutationAstWithArtifacts)
results = printer.Print(astDoc)
if !reflect.DeepEqual(expected, results) {
t.Fatalf("Unexpected result, Diff: %v", testutil.Diff(results, expected))
}
}
示例8: TestMutations_ExecutionOrdering_EvaluatesMutationsSerially
func TestMutations_ExecutionOrdering_EvaluatesMutationsSerially(t *testing.T) {
root := newTestRoot(6)
doc := `mutation M {
first: immediatelyChangeTheNumber(newNumber: 1) {
theNumber
},
second: promiseToChangeTheNumber(newNumber: 2) {
theNumber
},
third: immediatelyChangeTheNumber(newNumber: 3) {
theNumber
}
fourth: promiseToChangeTheNumber(newNumber: 4) {
theNumber
},
fifth: immediatelyChangeTheNumber(newNumber: 5) {
theNumber
}
}`
expected := &graphql.Result{
Data: map[string]interface{}{
"first": map[string]interface{}{
"theNumber": 1,
},
"second": map[string]interface{}{
"theNumber": 2,
},
"third": map[string]interface{}{
"theNumber": 3,
},
"fourth": map[string]interface{}{
"theNumber": 4,
},
"fifth": map[string]interface{}{
"theNumber": 5,
},
},
}
// parse query
ast := testutil.TestParse(t, doc)
// execute
ep := graphql.ExecuteParams{
Schema: mutationsTestSchema,
AST: ast,
Root: root,
}
result := testutil.TestExecute(t, ep)
if len(result.Errors) != len(expected.Errors) {
t.Fatalf("Unexpected errors, Diff: %v", testutil.Diff(expected.Errors, result.Errors))
}
if !reflect.DeepEqual(expected, result) {
t.Fatalf("Unexpected result, Diff: %v", testutil.Diff(expected, result))
}
}
示例9: TestUnionIntersectionTypes_ExecutesUnionTypesWithInlineFragments
func TestUnionIntersectionTypes_ExecutesUnionTypesWithInlineFragments(t *testing.T) {
// This is the valid version of the query in the above test.
doc := `
{
__typename
name
pets {
__typename
... on Dog {
name
barks
}
... on Cat {
name
meows
}
}
}
`
expected := &graphql.Result{
Data: map[string]interface{}{
"__typename": "Person",
"name": "John",
"pets": []interface{}{
map[string]interface{}{
"__typename": "Cat",
"name": "Garfield",
"meows": false,
},
map[string]interface{}{
"__typename": "Dog",
"name": "Odie",
"barks": true,
},
},
},
}
// parse query
ast := testutil.TestParse(t, doc)
// execute
ep := graphql.ExecuteParams{
Schema: unionInterfaceTestSchema,
AST: ast,
Root: john,
}
result := testutil.TestExecute(t, ep)
if len(result.Errors) != len(expected.Errors) {
t.Fatalf("Unexpected errors, Diff: %v", testutil.Diff(expected.Errors, result.Errors))
}
if !reflect.DeepEqual(expected, result) {
t.Fatalf("Unexpected result, Diff: %v", testutil.Diff(expected, result))
}
}
示例10: TestUnionIntersectionTypes_ExecutesUsingInterfaceTypes
func TestUnionIntersectionTypes_ExecutesUsingInterfaceTypes(t *testing.T) {
// NOTE: This is an *invalid* query, but it should be an *executable* query.
doc := `
{
__typename
name
friends {
__typename
name
barks
meows
}
}
`
expected := &graphql.Result{
Data: map[string]interface{}{
"__typename": "Person",
"name": "John",
"friends": []interface{}{
map[string]interface{}{
"__typename": "Person",
"name": "Liz",
},
map[string]interface{}{
"__typename": "Dog",
"name": "Odie",
"barks": true,
},
},
},
}
// parse query
ast := testutil.TestParse(t, doc)
// execute
ep := graphql.ExecuteParams{
Schema: unionInterfaceTestSchema,
AST: ast,
Root: john,
}
result := testutil.TestExecute(t, ep)
if len(result.Errors) != len(expected.Errors) {
t.Fatalf("Unexpected errors, Diff: %v", testutil.Diff(expected.Errors, result.Errors))
}
if !reflect.DeepEqual(expected, result) {
t.Fatalf("Unexpected result, Diff: %v", testutil.Diff(expected, result))
}
}
示例11: TestVariables_ObjectsAndNullability_UsingVariables_ExecutesWithComplexScalarInput
func TestVariables_ObjectsAndNullability_UsingVariables_ExecutesWithComplexScalarInput(t *testing.T) {
params := map[string]interface{}{
"input": map[string]interface{}{
"c": "foo",
"d": "SerializedValue",
},
}
expected := &graphql.Result{
Data: map[string]interface{}{
"fieldWithObjectInput": `{"c":"foo","d":"DeserializedValue"}`,
},
}
ast := testVariables_ObjectsAndNullability_UsingVariables_GetAST(t)
// execute
ep := graphql.ExecuteParams{
Schema: variablesTestSchema,
AST: ast,
Args: params,
}
result := testutil.TestExecute(t, ep)
if len(result.Errors) > 0 {
t.Fatalf("wrong result, unexpected errors: %v", result.Errors)
}
if !reflect.DeepEqual(expected, result) {
t.Fatalf("Unexpected result, Diff: %v", testutil.Diff(expected, result))
}
}
示例12: TestVariables_ObjectsAndNullability_UsingVariables_UsesDefaultValueWhenNotProvided
func TestVariables_ObjectsAndNullability_UsingVariables_UsesDefaultValueWhenNotProvided(t *testing.T) {
doc := `
query q($input: TestInputObject = {a: "foo", b: ["bar"], c: "baz"}) {
fieldWithObjectInput(input: $input)
}
`
expected := &graphql.Result{
Data: map[string]interface{}{
"fieldWithObjectInput": `{"a":"foo","b":["bar"],"c":"baz"}`,
},
}
withDefaultsAST := testutil.TestParse(t, doc)
// execute
ep := graphql.ExecuteParams{
Schema: variablesTestSchema,
AST: withDefaultsAST,
}
result := testutil.TestExecute(t, ep)
if len(result.Errors) > 0 {
t.Fatalf("wrong result, unexpected errors: %v", result.Errors)
}
if !reflect.DeepEqual(expected, result) {
t.Fatalf("Unexpected result, Diff: %v", testutil.Diff(expected, result))
}
}
示例13: TestDirectivesWorksOnInlineFragmentUnlessTrueIncludesInlineFragment
func TestDirectivesWorksOnInlineFragmentUnlessTrueIncludesInlineFragment(t *testing.T) {
query := `
query Q {
a
... on TestType @skip(if: true) {
b
}
}
fragment Frag on TestType {
b
}
`
expected := &graphql.Result{
Data: map[string]interface{}{
"a": "a",
},
}
result := executeDirectivesTestQuery(t, query)
if len(result.Errors) != 0 {
t.Fatalf("wrong result, unexpected errors: %v", result.Errors)
}
if !reflect.DeepEqual(expected, result) {
t.Fatalf("Unexpected result, Diff: %v", testutil.Diff(expected, result))
}
}
示例14: TestDirectives_DirectiveNameMustBeValid
func TestDirectives_DirectiveNameMustBeValid(t *testing.T) {
invalidDirective := graphql.NewDirective(graphql.DirectiveConfig{
Name: "123invalid name",
Locations: []string{
graphql.DirectiveLocationField,
},
})
_, err := graphql.NewSchema(graphql.SchemaConfig{
Query: graphql.NewObject(graphql.ObjectConfig{
Name: "TestType",
Fields: graphql.Fields{
"a": &graphql.Field{
Type: graphql.String,
},
},
}),
Directives: []*graphql.Directive{invalidDirective},
})
expectedErr := gqlerrors.FormattedError{
Message: `Names must match /^[_a-zA-Z][_a-zA-Z0-9]*$/ but "123invalid name" does not.`,
Locations: []location.SourceLocation{},
}
if !reflect.DeepEqual(expectedErr, err) {
t.Fatalf("Expected error to be equal, got: %v", testutil.Diff(expectedErr, err))
}
}
示例15: TestDirectives_DirectivesMustBeNamed
func TestDirectives_DirectivesMustBeNamed(t *testing.T) {
invalidDirective := graphql.NewDirective(graphql.DirectiveConfig{
Locations: []string{
graphql.DirectiveLocationField,
},
})
_, err := graphql.NewSchema(graphql.SchemaConfig{
Query: graphql.NewObject(graphql.ObjectConfig{
Name: "TestType",
Fields: graphql.Fields{
"a": &graphql.Field{
Type: graphql.String,
},
},
}),
Directives: []*graphql.Directive{invalidDirective},
})
expectedErr := gqlerrors.FormattedError{
Message: "Directive must be named.",
Locations: []location.SourceLocation{},
}
if !reflect.DeepEqual(expectedErr, err) {
t.Fatalf("Expected error to be equal, got: %v", testutil.Diff(expectedErr, err))
}
}