github.com/cockroachdb/cockroach@v20.2.0-alpha.1+incompatible/pkg/sql/mutations/mutations_test.go (about) 1 // Copyright 2020 The Cockroach Authors. 2 // 3 // Use of this software is governed by the Business Source License 4 // included in the file licenses/BSL.txt. 5 // 6 // As of the Change Date specified in that file, in accordance with 7 // the Business Source License, use of this software will be governed 8 // by the Apache License, Version 2.0, included in the file 9 // licenses/APL.txt. 10 11 package mutations 12 13 import ( 14 "strings" 15 "testing" 16 17 "github.com/cockroachdb/cockroach/pkg/util/randutil" 18 ) 19 20 func TestPostgresMutator(t *testing.T) { 21 q := ` 22 CREATE TABLE t (s STRING FAMILY fam1, b BYTES, FAMILY fam2 (b), PRIMARY KEY (s ASC, b DESC), INDEX (s) STORING (b)) 23 PARTITION BY LIST (s) 24 ( 25 PARTITION europe_west VALUES IN ('a', 'b') 26 ); 27 ALTER TABLE table1 INJECT STATISTICS 'blah'; 28 SET CLUSTER SETTING "sql.stats.automatic_collection.enabled" = false; 29 ` 30 31 rng, _ := randutil.NewPseudoRand() 32 { 33 mutated, changed := ApplyString(rng, q, PostgresMutator) 34 if !changed { 35 t.Fatal("expected changed") 36 } 37 mutated = strings.TrimSpace(mutated) 38 expect := `CREATE TABLE t (s TEXT, b BYTEA, PRIMARY KEY (s ASC, b DESC), INDEX (s) INCLUDE (b));` 39 if mutated != expect { 40 t.Fatalf("unexpected: %s", mutated) 41 } 42 } 43 { 44 mutated, changed := ApplyString(rng, q, PostgresCreateTableMutator, PostgresMutator) 45 if !changed { 46 t.Fatal("expected changed") 47 } 48 mutated = strings.TrimSpace(mutated) 49 expect := "CREATE TABLE t (s TEXT, b BYTEA, PRIMARY KEY (s, b));\nCREATE INDEX ON t (s) INCLUDE (b);" 50 if mutated != expect { 51 t.Fatalf("unexpected: %s", mutated) 52 } 53 } 54 }