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

Function TestDropData

edgraph/alter_test.go:87–134  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

85}
86
87func TestDropData(t *testing.T) {
88 dc := dgraphtest.NewComposeCluster()
89 client, cleanup, err := dc.Client()
90 require.NoError(t, err)
91 defer cleanup()
92
93 // Drop all data
94 require.NoError(t, client.Login(context.Background(),
95 dgraphapi.DefaultUser, dgraphapi.DefaultPassword))
96 require.NoError(t, client.Dgraph.DropAll(context.Background()))
97
98 // Create two namespaces
99 ctx := context.Background()
100 ns1, err := client.CreateNamespace(ctx)
101 require.NoError(t, err)
102 ns2, err := client.CreateNamespace(ctx)
103 require.NoError(t, err)
104
105 nsMaps, err := client.ListNamespaces(ctx)
106 require.NoError(t, err)
107 ns1ID := nsMaps[ns1].Id
108 require.NotZero(t, ns1ID)
109 ns2ID := nsMaps[ns2].Id
110 require.NotZero(t, ns2ID)
111
112 // namespace 1
113 require.NoError(t, client.LoginIntoNamespace(ctx,
114 dgraphapi.DefaultUser, dgraphapi.DefaultPassword, ns1))
115 require.NoError(t, client.SetSchema(ctx, `name: string @index(exact) .`))
116 _, err = client.Mutate(&api.Mutation{
117 SetNquads: []byte(`_:a <name> "Alice" .`),
118 CommitNow: true,
119 })
120 require.NoError(t, err)
121 resp, err := client.Query(`{ q(func: has(name)) { name } }`)
122 require.NoError(t, err)
123 require.JSONEq(t, `{"q":[{"name":"Alice"}]}`, string(resp.GetJson()))
124
125 require.NoError(t, client.DropData(context.Background()))
126
127 resp, err = client.Query(`{ q(func: has(name)) { name } }`)
128 require.NoError(t, err)
129 require.JSONEq(t, `{"q":[]}`, string(resp.GetJson()))
130
131 resp, err = client.Query(`schema{}`)
132 require.NoError(t, err)
133 require.Contains(t, string(resp.GetJson()), `"predicate":"name"`)
134}
135
136func TestDropPredicate(t *testing.T) {
137 dc := dgraphtest.NewComposeCluster()

Callers

nothing calls this directly

Calls 10

ClientMethod · 0.95
NewComposeClusterFunction · 0.92
cleanupFunction · 0.85
LoginMethod · 0.80
DropAllMethod · 0.80
CreateNamespaceMethod · 0.80
LoginIntoNamespaceMethod · 0.80
MutateMethod · 0.65
ListNamespacesMethod · 0.45
QueryMethod · 0.45

Tested by

no test coverage detected