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

Function TestDropPredicate

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

Source from the content-addressed store, hash-verified

134}
135
136func TestDropPredicate(t *testing.T) {
137 dc := dgraphtest.NewComposeCluster()
138 client, cleanup, err := dc.Client()
139 require.NoError(t, err)
140 defer cleanup()
141
142 // Drop all data
143 require.NoError(t, client.Login(context.Background(),
144 dgraphapi.DefaultUser, dgraphapi.DefaultPassword))
145 require.NoError(t, client.DropAll())
146
147 // Create two namespaces
148 ctx := context.Background()
149 ns1, err := client.CreateNamespace(ctx)
150 require.NoError(t, err)
151 ns2, err := client.CreateNamespace(ctx)
152 require.NoError(t, err)
153
154 nsMaps, err := client.ListNamespaces(ctx)
155 require.NoError(t, err)
156 ns1ID := nsMaps[ns1].Id
157 require.NotZero(t, ns1ID)
158 ns2ID := nsMaps[ns2].Id
159 require.NotZero(t, ns2ID)
160
161 // namespace 1
162 require.NoError(t, client.LoginIntoNamespace(ctx,
163 dgraphapi.DefaultUser, dgraphapi.DefaultPassword, ns1))
164 require.NoError(t, client.SetSchema(ctx, `name: string @index(exact) .`))
165 _, err = client.Mutate(&api.Mutation{
166 SetNquads: []byte(`_:a <name> "Alice" .`),
167 CommitNow: true,
168 })
169 require.NoError(t, err)
170 resp, err := client.Query(`{ q(func: has(name)) { name } }`)
171 require.NoError(t, err)
172 require.JSONEq(t, `{"q":[{"name":"Alice"}]}`, string(resp.GetJson()))
173
174 require.NoError(t, client.Dgraph.DropPredicate(context.Background(), "name"))
175
176 resp, err = client.Query(`{ q(func: has(name)) { name } }`)
177 require.NoError(t, err)
178 require.JSONEq(t, `{"q":[]}`, string(resp.GetJson()))
179
180 resp, err = client.Query(`schema{}`)
181 require.NoError(t, err)
182 require.NotContains(t, string(resp.GetJson()), `"predicate":"name"`)
183}
184
185func TestDropType(t *testing.T) {
186 dc := dgraphtest.NewComposeCluster()

Callers

nothing calls this directly

Calls 11

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

Tested by

no test coverage detected