Skip to content

Commit

Permalink
planner: fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
xhebox committed Aug 26, 2020
1 parent 4a4f928 commit 0b1ca55
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions planner/core/preprocess_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -269,12 +269,26 @@ func (s *testValidatorSuite) TestValidator(c *C) {
func (s *testValidatorSuite) TestForeignKey(c *C) {
defer testleak.AfterTest(c)()

s.runSQL(c, "ALTER TABLE test.t ADD CONSTRAINT fk FOREIGN KEY (c2) REFERENCES t (c1)", false, nil)
_, err := s.se.Execute(context.Background(), "create table test.t1(a int, b int, c int)")
c.Assert(err, IsNil)

_, err := s.se.Execute(context.Background(), "use test")
_, err = s.se.Execute(context.Background(), "create table test.t2(c int)")
c.Assert(err, IsNil)

_, err = s.se.Execute(context.Background(), "create database test2")
c.Assert(err, IsNil)

_, err = s.se.Execute(context.Background(), "create table test2.t(c int)")
c.Assert(err, IsNil)

s.is = s.dom.InfoSchema()

s.runSQL(c, "ALTER TABLE test.t1 ADD CONSTRAINT fk FOREIGN KEY (a) REFERENCES t2 (c)", false, nil)

_, err = s.se.Execute(context.Background(), "use test")
c.Assert(err, IsNil)

s.runSQL(c, "ALTER TABLE test.t ADD CONSTRAINT fk FOREIGN KEY (c3) REFERENCES t (c1)", false, nil)
s.runSQL(c, "ALTER TABLE test.t1 ADD CONSTRAINT fk FOREIGN KEY (b) REFERENCES t2 (c)", false, nil)

s.runSQL(c, "ALTER TABLE test.t ADD CONSTRAINT fk FOREIGN KEY (c4) REFERENCES test.t(c1)", false, nil)
s.runSQL(c, "ALTER TABLE test.t1 ADD CONSTRAINT fk FOREIGN KEY (c) REFERENCES test2.t (c)", false, nil)
}

0 comments on commit 0b1ca55

Please sign in to comment.