(t *testing.T)
| 45 | } |
| 46 | |
| 47 | func TestVectorDropAll(t *testing.T) { |
| 48 | conf := dgraphtest.NewClusterConfig().WithNumAlphas(1).WithNumZeros(1).WithReplicas(1).WithACL(time.Hour) |
| 49 | c, err := dgraphtest.NewLocalCluster(conf) |
| 50 | require.NoError(t, err) |
| 51 | defer func() { c.Cleanup(t.Failed()) }() |
| 52 | require.NoError(t, c.Start()) |
| 53 | |
| 54 | gc, cleanup, err := c.Client() |
| 55 | require.NoError(t, err) |
| 56 | defer cleanup() |
| 57 | require.NoError(t, gc.LoginIntoNamespace(context.Background(), |
| 58 | dgraphapi.DefaultUser, dgraphapi.DefaultPassword, x.RootNamespace)) |
| 59 | |
| 60 | hc, err := c.HTTPClient() |
| 61 | require.NoError(t, err) |
| 62 | require.NoError(t, hc.LoginIntoNamespace(dgraphapi.DefaultUser, |
| 63 | dgraphapi.DefaultPassword, x.RootNamespace)) |
| 64 | |
| 65 | numVectors := 100 |
| 66 | |
| 67 | testVectorSimilarTo := func(vectors [][]float32) { |
| 68 | for _, vector := range vectors { |
| 69 | _, err := gc.QueryMultipleVectorsUsingSimilarTo(vector, pred, 100) |
| 70 | require.ErrorContains(t, err, "is not indexed") |
| 71 | break |
| 72 | } |
| 73 | } |
| 74 | |
| 75 | for i := 0; i < 10; i++ { |
| 76 | require.NoError(t, gc.SetupSchema(testSchema)) |
| 77 | rdfs, vectors := dgraphapi.GenerateRandomVectors(0, numVectors, 100, pred) |
| 78 | mu := &api.Mutation{SetNquads: []byte(rdfs), CommitNow: true} |
| 79 | _, err = gc.Mutate(mu) |
| 80 | require.NoError(t, err) |
| 81 | |
| 82 | query := `{ |
| 83 | vector(func: has(project_description_v)) { |
| 84 | count(uid) |
| 85 | } |
| 86 | }` |
| 87 | result, err := gc.Query(query) |
| 88 | require.NoError(t, err) |
| 89 | require.JSONEq(t, fmt.Sprintf(`{"vector":[{"count":%v}]}`, numVectors), string(result.GetJson())) |
| 90 | |
| 91 | testVectorQuery(t, gc, vectors, rdfs, pred, numVectors) |
| 92 | t.Log("dropping data \n") |
| 93 | |
| 94 | require.NoError(t, gc.DropAll()) |
| 95 | |
| 96 | result, err = gc.Query(query) |
| 97 | require.NoError(t, err) |
| 98 | require.JSONEq(t, fmt.Sprintf(`{"vector":[{"count":%v}]}`, 0), string(result.GetJson())) |
| 99 | testVectorSimilarTo(vectors) |
| 100 | } |
| 101 | } |
| 102 | |
| 103 | func TestVectorSnapshot(t *testing.T) { |
| 104 | conf := dgraphtest.NewClusterConfig().WithNumAlphas(3).WithNumZeros(3).WithReplicas(3).WithACL(time.Hour) |
nothing calls this directly
no test coverage detected