MCPcopy
hub / github.com/dgraph-io/dgraph / TestMain

Function TestMain

dgraph/cmd/alpha/run_test.go:1678–1728  ·  view source on GitHub ↗
(m *testing.M)

Source from the content-addressed store, hash-verified

1676}
1677
1678func TestMain(m *testing.M) {
1679 conf := dgraphtest.NewClusterConfig().WithNumAlphas(1).WithNumZeros(1).WithReplicas(1).WithACL(time.Hour)
1680 c, err := dgraphtest.NewLocalCluster(conf)
1681
1682 x.Panic(err)
1683 x.Panic(c.Start())
1684 var cleanup func()
1685 dg, cleanup, err = c.Client()
1686 x.Panic(err)
1687 defer cleanup()
1688
1689 x.Panic(dg.Login(context.Background(), dgraphapi.DefaultUser, dgraphapi.DefaultPassword))
1690
1691 alphaGrpcPort, err := c.GetAlphaGrpcPublicPort(0)
1692 x.Panic(err)
1693
1694 alphaSockAdd = "0.0.0.0:" + alphaGrpcPort
1695 alphaSockAddHttp, err := c.GetAlphaHttpPublicPort(0)
1696 x.Panic(err)
1697 addr = "http://0.0.0.0:" + alphaSockAddHttp
1698 zeroSockAdd, err := c.GetZeroGrpcPublicPort(0)
1699 x.Panic(err)
1700
1701 // Increment lease, so that mutations work.
1702 conn, err := grpc.NewClient("0.0.0.0:"+zeroSockAdd, grpc.WithTransportCredentials(insecure.NewCredentials()))
1703 if err != nil {
1704 log.Fatal(err)
1705 }
1706 zc := pb.NewZeroClient(conn)
1707 if _, err := zc.AssignIds(context.Background(),
1708 &pb.Num{Val: 1e6, Type: pb.Num_UID}); err != nil {
1709 log.Fatal(err)
1710 }
1711 hc, err = c.HTTPClient()
1712 x.Panic(err)
1713
1714 x.Panic(hc.LoginIntoNamespace(dgraphapi.DefaultUser, dgraphapi.DefaultPassword, 0))
1715
1716 httpToken := hc.HttpToken
1717 token = &Token{
1718 token: httpToken,
1719 RWMutex: sync.RWMutex{},
1720 }
1721 code := m.Run()
1722 if code != 0 {
1723 c.Cleanup(true)
1724 } else {
1725 c.Cleanup(false)
1726 }
1727 os.Exit(code)
1728}

Callers

nothing calls this directly

Calls 15

StartMethod · 0.95
ClientMethod · 0.95
GetZeroGrpcPublicPortMethod · 0.95
AssignIdsMethod · 0.95
HTTPClientMethod · 0.95
CleanupMethod · 0.95
NewClusterConfigFunction · 0.92
NewLocalClusterFunction · 0.92
PanicFunction · 0.92
NewZeroClientFunction · 0.92

Tested by

no test coverage detected