TODO: add a test that talks to different alphas in the same cluster
(t *testing.T)
| 20 | |
| 21 | // TODO: add a test that talks to different alphas in the same cluster |
| 22 | func TestDropAll(t *testing.T) { |
| 23 | dc := dgraphtest.NewComposeCluster() |
| 24 | client, cleanup, err := dc.Client() |
| 25 | require.NoError(t, err) |
| 26 | defer cleanup() |
| 27 | |
| 28 | // Drop all data |
| 29 | require.NoError(t, client.Login(context.Background(), |
| 30 | dgraphapi.DefaultUser, dgraphapi.DefaultPassword)) |
| 31 | require.NoError(t, client.Dgraph.DropAll(context.Background())) |
| 32 | |
| 33 | // Create two namespaces |
| 34 | ctx := context.Background() |
| 35 | ns1, err := client.CreateNamespace(ctx) |
| 36 | require.NoError(t, err) |
| 37 | ns2, err := client.CreateNamespace(ctx) |
| 38 | require.NoError(t, err) |
| 39 | |
| 40 | nsMaps, err := client.ListNamespaces(ctx) |
| 41 | require.NoError(t, err) |
| 42 | ns1ID := nsMaps[ns1].Id |
| 43 | require.NotZero(t, ns1ID) |
| 44 | ns2ID := nsMaps[ns2].Id |
| 45 | require.NotZero(t, ns2ID) |
| 46 | |
| 47 | // namespace 1 |
| 48 | require.NoError(t, client.LoginIntoNamespace(ctx, |
| 49 | dgraphapi.DefaultUser, dgraphapi.DefaultPassword, ns1)) |
| 50 | require.NoError(t, client.SetSchema(ctx, `name: string @index(exact) .`)) |
| 51 | _, err = client.Mutate(&api.Mutation{ |
| 52 | SetNquads: []byte(`_:a <name> "Alice" .`), |
| 53 | CommitNow: true, |
| 54 | }) |
| 55 | require.NoError(t, err) |
| 56 | resp, err := client.Query(`{ q(func: has(name)) { name } }`) |
| 57 | require.NoError(t, err) |
| 58 | require.JSONEq(t, `{"q":[{"name":"Alice"}]}`, string(resp.GetJson())) |
| 59 | |
| 60 | // namespace 2 |
| 61 | require.NoError(t, client.LoginIntoNamespace(ctx, |
| 62 | dgraphapi.DefaultUser, dgraphapi.DefaultPassword, ns2)) |
| 63 | require.NoError(t, client.SetSchema(ctx, `name: string @index(exact) .`)) |
| 64 | _, err = client.Mutate(&api.Mutation{ |
| 65 | SetNquads: []byte(`_:a <name> "Bob" .`), |
| 66 | CommitNow: true, |
| 67 | }) |
| 68 | require.NoError(t, err) |
| 69 | resp, err = client.Query(`{ q(func: has(name)) { name } }`) |
| 70 | require.NoError(t, err) |
| 71 | require.JSONEq(t, `{"q":[{"name":"Bob"}]}`, string(resp.GetJson())) |
| 72 | |
| 73 | // Drop all data |
| 74 | require.NoError(t, client.Login(context.Background(), |
| 75 | dgraphapi.DefaultUser, dgraphapi.DefaultPassword)) |
| 76 | require.NoError(t, client.Dgraph.DropAll(context.Background())) |
| 77 | |
| 78 | resp, err = client.Query(`{ q(func: has(name)) { name } }`) |
| 79 | require.NoError(t, err) |
nothing calls this directly
no test coverage detected