Documentation
¶
Index ¶
- Variables
- func AssertSchemaUpdateCounterIncrement(t *testing.T, authority string, oldCounter uint64, header http.Header)
- func AssertUpdateGQLSchemaFailure(t *testing.T, authority, schema string, headers http.Header, ...)
- func BootstrapAuthData() ([]byte, []byte)
- func BootstrapServer(schema, data []byte)
- func CheckGraphQLStarted(url string) error
- func CreateNamespace(t *testing.T, headers http.Header, whichAlpha string) uint64
- func CreateNamespaces(t *testing.T, headers http.Header, whichAlpha string, count int) []uint64
- func DeleteGqlType(t *testing.T, typeName string, filter map[string]interface{}, ...)
- func DeleteNamespace(t *testing.T, id uint64, header http.Header, whichAlpha string)
- func DgraphDirectiveWithSpecialCharacters(t *testing.T)
- func GetJWT(t *testing.T, user, role interface{}, metaInfo *testutil.AuthMeta) http.Header
- func GetJWTForInterfaceAuth(t *testing.T, user, role string, ans bool, metaInfo *testutil.AuthMeta) http.Header
- func GetJWTWithNullUser(t *testing.T, role interface{}, metaInfo *testutil.AuthMeta) http.Header
- func GetXidFilter(xidKey string, xidVals []interface{}) map[string]interface{}
- func JSONEqGraphQL(t *testing.T, expected, actual string)
- func ListNamespaces(t *testing.T, jwtToken string, headers http.Header, whichAlpha string) []uint64
- func PopulateGraphQLData(client *dgo.Dgraph, data []byte) error
- func RequireNoGQLErrors(t *testing.T, resp *GraphQLResponse)
- func RunAll(t *testing.T)
- func RunGQLRequest(req *http.Request) ([]byte, error)
- func SafelyDropAll(t *testing.T)
- func SafelyDropAllWithGroot(t *testing.T)
- func SchemaTest(t *testing.T, expectedDgraphSchema string)
- type ErrorCase
- type GqlSchema
- func AssertGetGQLSchema(t *testing.T, authority string, header http.Header) *GqlSchema
- func AssertGetGQLSchemaRequireId(t *testing.T, authority string, header http.Header) *GqlSchema
- func AssertUpdateGQLSchemaSuccess(t *testing.T, authority, schema string, headers http.Header) *GqlSchema
- func SafelyUpdateGQLSchema(t *testing.T, authority, schema string, headers http.Header) *GqlSchema
- func SafelyUpdateGQLSchemaOnAlpha1(t *testing.T, schema string) *GqlSchema
- type GraphQLParams
- func (params *GraphQLParams) CreateGQLPost(url string) (*http.Request, error)
- func (params *GraphQLParams) Execute(t require.TestingT, req *http.Request) *GraphQLResponse
- func (params *GraphQLParams) ExecuteAsGet(t *testing.T, url string) *GraphQLResponse
- func (params *GraphQLParams) ExecuteAsPost(t require.TestingT, url string) *GraphQLResponse
- func (params *GraphQLParams) ExecuteAsPostApplicationGraphql(t *testing.T, url string) *GraphQLResponse
- type GraphQLResponse
- type GraphQLSubscriptionClient
- type ProbeGraphQLResp
- type Todo
- type Tweets
- type User
- type UserSecret
Constants ¶
This section is empty.
Variables ¶
var ( Alpha1HTTP = testutil.ContainerAddr("alpha1", 8080) Alpha1gRPC = testutil.ContainerAddr("alpha1", 9080) GraphqlURL = "http://" + Alpha1HTTP + "/graphql" GraphqlAdminURL = "http://" + Alpha1HTTP + "/admin" )
Functions ¶
func AssertSchemaUpdateCounterIncrement ¶
func AssertSchemaUpdateCounterIncrement(t *testing.T, authority string, oldCounter uint64, header http.Header)
AssertSchemaUpdateCounterIncrement asserts that the schemaUpdateCounter is greater than the oldCounter, indicating that the GraphQL schema has been updated. If it can't make the assertion with enough retries, it fails the test.
func AssertUpdateGQLSchemaFailure ¶
func AssertUpdateGQLSchemaFailure(t *testing.T, authority, schema string, headers http.Header, expectedErrors []string)
AssertUpdateGQLSchemaFailure tries to update the GraphQL schema and asserts that the update failed with all of the given errors.
func BootstrapAuthData ¶
func BootstrapServer ¶
func BootstrapServer(schema, data []byte)
func CheckGraphQLStarted ¶
func CreateNamespace ¶
func CreateNamespaces ¶
func DeleteGqlType ¶
func DeleteNamespace ¶
func GetJWTForInterfaceAuth ¶
func GetJWTWithNullUser ¶
func GetXidFilter ¶
func JSONEqGraphQL ¶
JSONEqGraphQL compares two JSON strings obtained from a /graphql response. To avoid issues, don't use space for indentation in expected input.
The comparison requirements for JSON reported by /graphql are following:
- The key order matters in object comparison, i.e. {"hello": "world", "foo": "bar"} is not same as: {"foo": "bar", "hello": "world"}
- A key missing in an object is not same as that key present with value null, i.e. {"hello": "world"} is not same as: {"hello": "world", "foo": null}
- Integers that are out of the [-(2^53)+1, (2^53)-1] precision range supported by JSON RFC, should still be encoded with full precision. i.e., the number 9007199254740993 ( = 2^53 + 1) should not get encoded as 9007199254740992 ( = 2^53). This happens in Go's standard JSON parser due to IEEE754 precision loss for floating point numbers.
The above requirements are not satisfied by the standard require.JSONEq or testutil.CompareJSON methods. In order to satisfy all these requirements, this implementation just requires that the input strings be equal after removing `\r`, `\n`, `\t` whitespace characters from the inputs. TODO:
Find a better way to do this such that order isn't mandated in list comparison. So that it is actually usable at places it is not used at present.
func ListNamespaces ¶
func PopulateGraphQLData ¶
func RequireNoGQLErrors ¶
func RequireNoGQLErrors(t *testing.T, resp *GraphQLResponse)
func RunGQLRequest ¶
RunGQLRequest runs a HTTP GraphQL request and returns the data or any errors.
func SafelyDropAll ¶
SafelyDropAll can be used in tests for doing DROP_ALL when ACL is disabled. This should be used after at least one schema update operation has succeeded. Once the control returns from it, one can be sure that the DROP_ALL has reached the GraphQL layer and the existing schema has been updated to an empty schema.
func SafelyDropAllWithGroot ¶
SafelyDropAllWithGroot can be used in tests for doing DROP_ALL when ACL is enabled. This should be used after at least one schema update operation has succeeded. Once the control returns from it, one can be sure that the DROP_ALL has reached the GraphQL layer and the existing schema has been updated to an empty schema.
func SchemaTest ¶
Types ¶
type ErrorCase ¶
type ErrorCase struct { Name string GQLRequest string GQLVariables string Errors x.GqlErrorList }
type GqlSchema ¶
func AssertGetGQLSchema ¶
AssertGetGQLSchema queries the current GraphQL schema using getGQLSchema query and asserts that the query doesn't give any errors. It returns a *GqlSchema received in response to the query.
func AssertGetGQLSchemaRequireId ¶
In addition to AssertGetGQLSchema, it also asserts that the response returned from the getGQLSchema query isn't nil and the Id in the response is actually a uid.
func AssertUpdateGQLSchemaSuccess ¶
func AssertUpdateGQLSchemaSuccess(t *testing.T, authority, schema string, headers http.Header) *GqlSchema
AssertUpdateGQLSchemaSuccess updates the GraphQL schema, asserts that the update succeeded and the returned response is correct. It returns a *GqlSchema it received in the response.
func SafelyUpdateGQLSchema ¶
SafelyUpdateGQLSchema can be safely used in tests to update the GraphQL schema. Once the control returns from it, one can be sure that the newly applied schema is the one being served by the GraphQL layer, and hence it is safe to make any queries as per the new schema. Note that if the schema being provided is same as the current schema in the GraphQL layer, then this function will fail the test with a fatal error.
type GraphQLParams ¶
type GraphQLParams struct { Query string `json:"query"` OperationName string `json:"operationName"` Variables map[string]interface{} `json:"variables"` Extensions *schema.RequestExtensions `json:"extensions,omitempty"` Headers http.Header // contains filtered or unexported fields }
func (*GraphQLParams) CreateGQLPost ¶
func (params *GraphQLParams) CreateGQLPost(url string) (*http.Request, error)
func (*GraphQLParams) Execute ¶
func (params *GraphQLParams) Execute(t require.TestingT, req *http.Request) *GraphQLResponse
Execute takes a HTTP request from either ExecuteAsPost or ExecuteAsGet and executes the request
func (*GraphQLParams) ExecuteAsGet ¶
func (params *GraphQLParams) ExecuteAsGet(t *testing.T, url string) *GraphQLResponse
ExecuteAsGet builds a HTTP GET request from the GraphQL input structure and executes the request to url.
func (*GraphQLParams) ExecuteAsPost ¶
func (params *GraphQLParams) ExecuteAsPost(t require.TestingT, url string) *GraphQLResponse
ExecuteAsPost builds a HTTP POST request from the GraphQL input structure and executes the request to url.
func (*GraphQLParams) ExecuteAsPostApplicationGraphql ¶
func (params *GraphQLParams) ExecuteAsPostApplicationGraphql(t *testing.T, url string) *GraphQLResponse
ExecuteAsPostApplicationGraphql builds an HTTP Post with type application/graphql Note, variables are not allowed
type GraphQLResponse ¶
type GraphQLResponse struct { Data json.RawMessage `json:"data,omitempty"` Errors x.GqlErrorList `json:"errors,omitempty"` Extensions map[string]interface{} `json:"extensions,omitempty"` }
GraphQLResponse GraphQL response structure. see https://graphql.github.io/graphql-spec/June2018/#sec-Response
func RetryUpdateGQLSchema ¶
func RetryUpdateGQLSchema(t *testing.T, authority, schema string, headers http.Header) *GraphQLResponse
RetryUpdateGQLSchema tries to update the GraphQL schema and if it receives a retryable error, it keeps retrying until it either receives no error or a non-retryable error. Then it returns the GraphQLResponse it received as a result of calling updateGQLSchema.
func (*GraphQLResponse) RequireNoGQLErrors ¶
func (gqlRes *GraphQLResponse) RequireNoGQLErrors(t *testing.T)
type GraphQLSubscriptionClient ¶
type GraphQLSubscriptionClient struct {
// contains filtered or unexported fields
}
GraphQLSubscriptionClient uses apollo subscription protocol to subscribe on GraphQL server.
func NewGraphQLSubscription ¶
func NewGraphQLSubscription(url string, req *schema.Request, subscriptionPayload string) ( *GraphQLSubscriptionClient, error)
NewGraphQLSubscription returns graphql subscription client.
func (*GraphQLSubscriptionClient) RecvMsg ¶
func (client *GraphQLSubscriptionClient) RecvMsg() ([]byte, error)
RecvMsg recives graphql update from the server.
func (*GraphQLSubscriptionClient) Terminate ¶
func (client *GraphQLSubscriptionClient) Terminate()
Terminate will terminate the subscription.