MCPcopy Index your code
hub / github.com/bytebase/bytebase / TestGitOpsCheckVersionedDependency

Function TestGitOpsCheckVersionedDependency

backend/tests/gitops_test.go:1621–1800  ·  view source on GitHub ↗

TestGitOpsCheckVersionedDependency tests that CheckRelease SQL review handles dependencies between migration files correctly. Test case 1: Create table t1, then alter table t1 - should pass with no SQL review errors Test case 2: Create table t1, then alter table t2 - should have SQL review error (t2

(t *testing.T)

Source from the content-addressed store, hash-verified

1619// Test case 1: Create table t1, then alter table t1 - should pass with no SQL review errors
1620// Test case 2: Create table t1, then alter table t2 - should have SQL review error (t2 doesn't exist)
1621func TestGitOpsCheckVersionedDependency(t *testing.T) {
1622 t.Parallel()
1623
1624 testCases := []struct {
1625 name string
1626 files []*v1pb.Release_File
1627 expectError bool
1628 }{
1629 {
1630 name: "alter_same_table_should_pass",
1631 files: []*v1pb.Release_File{
1632 {
1633 Path: "migrations/001__create_t1.sql",
1634 Version: "001",
1635 Statement: []byte(`CREATE TABLE t1 (
1636 id SERIAL PRIMARY KEY,
1637 name VARCHAR(255) NOT NULL
1638);`),
1639 },
1640 {
1641 Path: "migrations/002__alter_t1.sql",
1642 Version: "002",
1643 Statement: []byte(`ALTER TABLE t1 ADD COLUMN email VARCHAR(255);`),
1644 },
1645 },
1646 expectError: false,
1647 },
1648 {
1649 name: "alter_nonexistent_table_should_error",
1650 files: []*v1pb.Release_File{
1651 {
1652 Path: "migrations/001__create_t1.sql",
1653 Version: "001",
1654 Statement: []byte(`CREATE TABLE t1 (
1655 id SERIAL PRIMARY KEY,
1656 name VARCHAR(255) NOT NULL
1657);`),
1658 },
1659 {
1660 Path: "migrations/002__alter_t2.sql",
1661 Version: "002",
1662 Statement: []byte(`ALTER TABLE t2 ADD COLUMN email VARCHAR(255);`),
1663 },
1664 },
1665 expectError: true,
1666 },
1667 }
1668
1669 for _, tc := range testCases {
1670 tc := tc
1671 t.Run(tc.name, func(t *testing.T) {
1672 t.Parallel()
1673 a := require.New(t)
1674 ctx := context.Background()
1675 ctl := &controller{}
1676 ctx, err := ctl.StartServerWithExternalPg(ctx)
1677 a.NoError(err)
1678 defer ctl.Close(ctx)

Callers

nothing calls this directly

Calls 13

CloseMethod · 0.95
createDatabaseMethod · 0.95
FormatReviewConfigFunction · 0.92
generateRandomStringFunction · 0.85
getPgContainerFunction · 0.85
CreateProjectMethod · 0.65
CreateReviewConfigMethod · 0.65
CreatePolicyMethod · 0.65
CloseMethod · 0.65
CreateInstanceMethod · 0.65
CheckReleaseMethod · 0.65

Tested by

no test coverage detected