// CheckVSchema runs the tests on the VSchema part of the API func CheckVSchema(ctx context.Context, t *testing.T, ts topo.Impl) { got, err := ts.GetVSchema(ctx) if err != nil { t.Error(err) } want := "{}" if got != want { t.Errorf("GetVSchema: %s, want %s", got, want) } err = ts.SaveVSchema(ctx, `{ "Keyspaces": {}}`) if err != nil { t.Error(err) } got, err = ts.GetVSchema(ctx) if err != nil { t.Error(err) } want = `{ "Keyspaces": {}}` if got != want { t.Errorf("GetVSchema: %s, want %s", got, want) } err = ts.SaveVSchema(ctx, `{ "Keyspaces": { "aa": { "Sharded": false}}}`) if err != nil { t.Error(err) } got, err = ts.GetVSchema(ctx) if err != nil { t.Error(err) } want = `{ "Keyspaces": { "aa": { "Sharded": false}}}` if got != want { t.Errorf("GetVSchema: %s, want %s", got, want) } err = ts.SaveVSchema(ctx, "invalid") want = "Unmarshal failed:" if err == nil || !strings.HasPrefix(err.Error(), want) { t.Errorf("SaveVSchema: %v, must start with %s", err, want) } }
// checkVSchema runs the tests on the VSchema part of the API func checkVSchema(t *testing.T, ts topo.Impl) { ctx := context.Background() if err := ts.CreateKeyspace(ctx, "test_keyspace", &topodatapb.Keyspace{}); err != nil { t.Fatalf("CreateKeyspace: %v", err) } shard := &topodatapb.Shard{ KeyRange: newKeyRange("b0-c0"), } if err := ts.CreateShard(ctx, "test_keyspace", "b0-c0", shard); err != nil { t.Fatalf("CreateShard: %v", err) } got, err := ts.GetVSchema(ctx, "test_keyspace") want := &vschemapb.Keyspace{} if err != topo.ErrNoNode { t.Error(err) } err = ts.SaveVSchema(ctx, "test_keyspace", &vschemapb.Keyspace{ Sharded: true, Vindexes: map[string]*vschemapb.Vindex{ "stfu1": { Type: "stfu", Params: map[string]string{ "stfu1": "1", }, Owner: "t1", }, "stln1": { Type: "stln", Owner: "t1", }, }, Tables: map[string]*vschemapb.Table{ "t1": { ColumnVindexes: []*vschemapb.ColumnVindex{ { Column: "c1", Name: "stfu1", }, { Column: "c2", Name: "stln1", }, }, }, }, }) if err != nil { t.Error(err) } got, err = ts.GetVSchema(ctx, "test_keyspace") if err != nil { t.Error(err) } want = &vschemapb.Keyspace{ Sharded: true, Vindexes: map[string]*vschemapb.Vindex{ "stfu1": { Type: "stfu", Params: map[string]string{ "stfu1": "1", }, Owner: "t1", }, "stln1": { Type: "stln", Owner: "t1", }, }, Tables: map[string]*vschemapb.Table{ "t1": { ColumnVindexes: []*vschemapb.ColumnVindex{ { Column: "c1", Name: "stfu1", }, { Column: "c2", Name: "stln1", }, }, }, }, } if !proto.Equal(got, want) { t.Errorf("GetVSchema: %s, want %s", got, want) } err = ts.SaveVSchema(ctx, "test_keyspace", &vschemapb.Keyspace{}) if err != nil { t.Error(err) } got, err = ts.GetVSchema(ctx, "test_keyspace") if err != nil { t.Error(err) } want = &vschemapb.Keyspace{} if !proto.Equal(got, want) { t.Errorf("GetVSchema: %s, want %s", got, want) } // Make sure the vschema is not returned as a shard name, // because they share the same directory location. shards, err := ts.GetShardNames(ctx, "test_keyspace") if err != nil { t.Errorf("GetShardNames: %v", err) } if len(shards) != 1 || shards[0] != "b0-c0" { t.Errorf(`GetShardNames: want [ "b0-c0" ], got %v`, shards) } }
// CheckVSchema runs the tests on the VSchema part of the API func CheckVSchema(ctx context.Context, t *testing.T, ts topo.Impl) { if err := ts.CreateKeyspace(ctx, "test_keyspace", &topodatapb.Keyspace{}); err != nil { t.Fatalf("CreateKeyspace: %v", err) } shard := &topodatapb.Shard{ KeyRange: newKeyRange("b0-c0"), } if err := ts.CreateShard(ctx, "test_keyspace", "b0-c0", shard); err != nil { t.Fatalf("CreateShard: %v", err) } got, err := ts.GetVSchema(ctx, "test_keyspace") if err != nil { t.Error(err) } want := "{}" if got != want { t.Errorf("GetVSchema: %s, want %s", got, want) } err = ts.SaveVSchema(ctx, "test_keyspace", `{ "Sharded": true }`) if err != nil { t.Error(err) } got, err = ts.GetVSchema(ctx, "test_keyspace") if err != nil { t.Error(err) } want = `{ "Sharded": true }` if got != want { t.Errorf("GetVSchema: %s, want %s", got, want) } err = ts.SaveVSchema(ctx, "test_keyspace", `{ "Sharded": false }`) if err != nil { t.Error(err) } got, err = ts.GetVSchema(ctx, "test_keyspace") if err != nil { t.Error(err) } want = `{ "Sharded": false }` if got != want { t.Errorf("GetVSchema: %s, want %s", got, want) } err = ts.SaveVSchema(ctx, "test_keyspace", "invalid") want = "Unmarshal failed:" if err == nil || !strings.HasPrefix(err.Error(), want) { t.Errorf("SaveVSchema: %v, must start with %s", err, want) } // Make sure the vschema is not returned as a shard name, // because they share the same directory location. shards, err := ts.GetShardNames(ctx, "test_keyspace") if err != nil { t.Errorf("GetShardNames: %v", err) } if len(shards) != 1 || shards[0] != "b0-c0" { t.Errorf(`GetShardNames: want [ "b0-c0" ], got %v`, shards) } }