-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #88263 from knz/backport22.2-88009-88098
- Loading branch information
Showing
13 changed files
with
236 additions
and
117 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
// Copyright 2022 The Cockroach Authors. | ||
// | ||
// Use of this software is governed by the Business Source License | ||
// included in the file licenses/BSL.txt. | ||
// | ||
// As of the Change Date specified in that file, in accordance with | ||
// the Business Source License, use of this software will be governed | ||
// by the Apache License, Version 2.0, included in the file | ||
// licenses/APL.txt. | ||
|
||
package sql_test | ||
|
||
import ( | ||
"context" | ||
gosql "database/sql" | ||
"testing" | ||
|
||
"github.com/cockroachdb/cockroach/pkg/sql/tests" | ||
"github.com/cockroachdb/cockroach/pkg/testutils/serverutils" | ||
"github.com/cockroachdb/cockroach/pkg/util/leaktest" | ||
"github.com/cockroachdb/cockroach/pkg/util/log" | ||
"github.com/cockroachdb/errors" | ||
) | ||
|
||
func TestCommentOnSchema(t *testing.T) { | ||
defer leaktest.AfterTest(t)() | ||
defer log.Scope(t).Close(t) | ||
|
||
params, _ := tests.CreateTestServerParams() | ||
s, db, _ := serverutils.StartServer(t, params) | ||
defer s.Stopper().Stop(context.Background()) | ||
|
||
if _, err := db.Exec(` | ||
CREATE SCHEMA d; | ||
`); err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
testCases := []struct { | ||
exec string | ||
query string | ||
expect gosql.NullString | ||
}{ | ||
{ | ||
`COMMENT ON SCHEMA d IS 'foo'`, | ||
`SELECT obj_description(oid, 'pg_namespace') FROM pg_namespace WHERE nspname = 'd'`, | ||
gosql.NullString{String: `foo`, Valid: true}, | ||
}, | ||
{ | ||
`ALTER SCHEMA d RENAME TO d2`, | ||
`SELECT obj_description(oid, 'pg_namespace') FROM pg_namespace WHERE nspname = 'd2'`, | ||
gosql.NullString{String: `foo`, Valid: true}, | ||
}, | ||
{ | ||
`COMMENT ON SCHEMA d2 IS NULL`, | ||
`SELECT obj_description(oid, 'pg_namespace') FROM pg_namespace WHERE nspname = 'd2'`, | ||
gosql.NullString{Valid: false}, | ||
}, | ||
} | ||
|
||
for _, tc := range testCases { | ||
if _, err := db.Exec(tc.exec); err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
row := db.QueryRow(tc.query) | ||
var comment gosql.NullString | ||
if err := row.Scan(&comment); err != nil { | ||
t.Fatal(err) | ||
} | ||
if tc.expect != comment { | ||
t.Fatalf("expected comment %v, got %v", tc.expect, comment) | ||
} | ||
} | ||
} | ||
|
||
func TestCommentOnSchemaWhenDrop(t *testing.T) { | ||
defer leaktest.AfterTest(t)() | ||
defer log.Scope(t).Close(t) | ||
|
||
params, _ := tests.CreateTestServerParams() | ||
s, db, _ := serverutils.StartServer(t, params) | ||
defer s.Stopper().Stop(context.Background()) | ||
|
||
if _, err := db.Exec(` | ||
CREATE SCHEMA d; | ||
`); err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
if _, err := db.Exec(`COMMENT ON SCHEMA d IS 'foo'`); err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
if _, err := db.Exec(`DROP SCHEMA d`); err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
row := db.QueryRow(`SELECT comment FROM system.comments LIMIT 1`) | ||
var comment string | ||
err := row.Scan(&comment) | ||
if !errors.Is(err, gosql.ErrNoRows) { | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
t.Fatal("comment remaining in system.comments despite drop") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.