DgraphClientWithCerts creates a Dgraph client with TLS configured using the given viper configuration. It is intended to be called from TestMain() to establish a Dgraph connection shared by all tests, so there is no testing.T instance for it to use.
(serviceAddr string, conf *viper.Viper)
| 348 | // It is intended to be called from TestMain() to establish a Dgraph connection shared |
| 349 | // by all tests, so there is no testing.T instance for it to use. |
| 350 | func DgraphClientWithCerts(serviceAddr string, conf *viper.Viper) (*dgo.Dgraph, error) { |
| 351 | tlsCfg, err := x.LoadClientTLSConfig(conf) |
| 352 | if err != nil { |
| 353 | return nil, err |
| 354 | } |
| 355 | |
| 356 | dialOpts := []grpc.DialOption{} |
| 357 | if tlsCfg != nil { |
| 358 | dialOpts = append(dialOpts, grpc.WithTransportCredentials(credentials.NewTLS(tlsCfg))) |
| 359 | } else { |
| 360 | dialOpts = append(dialOpts, grpc.WithTransportCredentials(insecure.NewCredentials())) |
| 361 | } |
| 362 | conn, err := grpc.NewClient(serviceAddr, dialOpts...) |
| 363 | if err != nil { |
| 364 | return nil, err |
| 365 | } |
| 366 | dg := dgo.NewDgraphClient(api.NewDgraphClient(conn)) |
| 367 | return dg, nil |
| 368 | } |
| 369 | |
| 370 | // DropAll drops all the data in the Dgraph instance associated with the given client. |
| 371 | func DropAll(t *testing.T, dg *dgo.Dgraph) { |