Skip to content

Commit 1d4e2a3

Browse files
nataraj-hates-MS-for-stealing-githubCommitfest Bot
authored andcommitted
Extra tests
Add more tests for ternary reloptions in dummy_index_am module
1 parent c23f0a5 commit 1d4e2a3

File tree

6 files changed

+81
-18
lines changed

6 files changed

+81
-18
lines changed

src/test/modules/dummy_index_am/README

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ access method, whose code is kept a maximum simple.
66

77
This includes tests for all relation option types:
88
- boolean
9+
- ternary
910
- enum
1011
- integer
1112
- real

src/test/modules/dummy_index_am/dummy_index_am.c

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
PG_MODULE_MAGIC;
2323

2424
/* parse table for fillRelOptions */
25-
static relopt_parse_elt di_relopt_tab[6];
25+
static relopt_parse_elt di_relopt_tab[8];
2626

2727
/* Kind of relation options for dummy index */
2828
static relopt_kind di_relopt_kind;
@@ -40,6 +40,8 @@ typedef struct DummyIndexOptions
4040
int option_int;
4141
double option_real;
4242
bool option_bool;
43+
ternary option_ternary1;
44+
ternary option_ternary2;
4345
DummyAmEnum option_enum;
4446
int option_string_val_offset;
4547
int option_string_null_offset;
@@ -96,23 +98,37 @@ create_reloptions_table(void)
9698
di_relopt_tab[2].opttype = RELOPT_TYPE_BOOL;
9799
di_relopt_tab[2].offset = offsetof(DummyIndexOptions, option_bool);
98100

101+
add_ternary_reloption(di_relopt_kind, "option_ternary1",
102+
"First ternary option for dummy_index_am",
103+
TERNARY_UNSET, NULL, AccessExclusiveLock);
104+
di_relopt_tab[3].optname = "option_ternary1";
105+
di_relopt_tab[3].opttype = RELOPT_TYPE_TERNARY;
106+
di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_ternary1);
107+
108+
add_ternary_reloption(di_relopt_kind, "option_ternary2",
109+
"Second ternary option for dummy_index_am",
110+
TERNARY_TRUE, "do_not_know_yet", AccessExclusiveLock);
111+
di_relopt_tab[4].optname = "option_ternary2";
112+
di_relopt_tab[4].opttype = RELOPT_TYPE_TERNARY;
113+
di_relopt_tab[4].offset = offsetof(DummyIndexOptions, option_ternary2);
114+
99115
add_enum_reloption(di_relopt_kind, "option_enum",
100116
"Enum option for dummy_index_am",
101117
dummyAmEnumValues,
102118
DUMMY_AM_ENUM_ONE,
103119
"Valid values are \"one\" and \"two\".",
104120
AccessExclusiveLock);
105-
di_relopt_tab[3].optname = "option_enum";
106-
di_relopt_tab[3].opttype = RELOPT_TYPE_ENUM;
107-
di_relopt_tab[3].offset = offsetof(DummyIndexOptions, option_enum);
121+
di_relopt_tab[5].optname = "option_enum";
122+
di_relopt_tab[5].opttype = RELOPT_TYPE_ENUM;
123+
di_relopt_tab[5].offset = offsetof(DummyIndexOptions, option_enum);
108124

109125
add_string_reloption(di_relopt_kind, "option_string_val",
110126
"String option for dummy_index_am with non-NULL default",
111127
"DefaultValue", &validate_string_option,
112128
AccessExclusiveLock);
113-
di_relopt_tab[4].optname = "option_string_val";
114-
di_relopt_tab[4].opttype = RELOPT_TYPE_STRING;
115-
di_relopt_tab[4].offset = offsetof(DummyIndexOptions,
129+
di_relopt_tab[6].optname = "option_string_val";
130+
di_relopt_tab[6].opttype = RELOPT_TYPE_STRING;
131+
di_relopt_tab[6].offset = offsetof(DummyIndexOptions,
116132
option_string_val_offset);
117133

118134
/*
@@ -123,9 +139,9 @@ create_reloptions_table(void)
123139
NULL, /* description */
124140
NULL, &validate_string_option,
125141
AccessExclusiveLock);
126-
di_relopt_tab[5].optname = "option_string_null";
127-
di_relopt_tab[5].opttype = RELOPT_TYPE_STRING;
128-
di_relopt_tab[5].offset = offsetof(DummyIndexOptions,
142+
di_relopt_tab[7].optname = "option_string_null";
143+
di_relopt_tab[7].opttype = RELOPT_TYPE_STRING;
144+
di_relopt_tab[7].offset = offsetof(DummyIndexOptions,
129145
option_string_null_offset);
130146
}
131147

src/test/modules/dummy_index_am/expected/reloptions.out

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ SET client_min_messages TO 'notice';
1818
CREATE INDEX dummy_test_idx ON dummy_test_tab
1919
USING dummy_index_am (i) WITH (
2020
option_bool = false,
21+
option_ternary1,
22+
option_ternary2 = off,
2123
option_int = 5,
2224
option_real = 3.1,
2325
option_enum = 'two',
@@ -31,16 +33,20 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx';
3133
unnest
3234
------------------------
3335
option_bool=false
36+
option_ternary1=true
37+
option_ternary2=off
3438
option_int=5
3539
option_real=3.1
3640
option_enum=two
3741
option_string_val=null
3842
option_string_null=val
39-
(6 rows)
43+
(8 rows)
4044

4145
-- ALTER INDEX .. SET
4246
ALTER INDEX dummy_test_idx SET (option_int = 10);
4347
ALTER INDEX dummy_test_idx SET (option_bool = true);
48+
ALTER INDEX dummy_test_idx SET (option_ternary1 = false);
49+
ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET);
4450
ALTER INDEX dummy_test_idx SET (option_real = 3.2);
4551
ALTER INDEX dummy_test_idx SET (option_string_val = 'val2');
4652
ALTER INDEX dummy_test_idx SET (option_string_null = NULL);
@@ -49,19 +55,23 @@ ALTER INDEX dummy_test_idx SET (option_enum = 'three');
4955
ERROR: invalid value for enum option "option_enum": three
5056
DETAIL: Valid values are "one" and "two".
5157
SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx';
52-
unnest
53-
-------------------------
58+
unnest
59+
---------------------------------
5460
option_int=10
5561
option_bool=true
62+
option_ternary1=false
63+
option_ternary2=do_not_know_yet
5664
option_real=3.2
5765
option_string_val=val2
5866
option_string_null=null
5967
option_enum=one
60-
(6 rows)
68+
(8 rows)
6169

6270
-- ALTER INDEX .. RESET
6371
ALTER INDEX dummy_test_idx RESET (option_int);
6472
ALTER INDEX dummy_test_idx RESET (option_bool);
73+
ALTER INDEX dummy_test_idx RESET (option_ternary1);
74+
ALTER INDEX dummy_test_idx RESET (option_ternary2);
6575
ALTER INDEX dummy_test_idx RESET (option_real);
6676
ALTER INDEX dummy_test_idx RESET (option_enum);
6777
ALTER INDEX dummy_test_idx RESET (option_string_val);
@@ -100,6 +110,26 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx';
100110
(1 row)
101111

102112
ALTER INDEX dummy_test_idx RESET (option_bool);
113+
-- Ternary
114+
ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error
115+
ERROR: invalid value for ternary option "option_ternary1": 4
116+
ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true
117+
ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error
118+
ERROR: invalid value for ternary option "option_ternary1": 3.4
119+
ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error
120+
ERROR: invalid value for ternary option "option_ternary1": val4
121+
ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1
122+
ERROR: invalid value for ternary option "option_ternary1": do_not_know_yet
123+
ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok
124+
SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx';
125+
unnest
126+
---------------------------------
127+
option_ternary1=1
128+
option_ternary2=do_not_know_yet
129+
(2 rows)
130+
131+
ALTER INDEX dummy_test_idx RESET (option_ternary1);
132+
ALTER INDEX dummy_test_idx RESET (option_ternary2);
103133
-- Float
104134
ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok
105135
ALTER INDEX dummy_test_idx SET (option_real = true); -- error

src/test/modules/dummy_index_am/sql/reloptions.sql

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ SET client_min_messages TO 'notice';
1818
CREATE INDEX dummy_test_idx ON dummy_test_tab
1919
USING dummy_index_am (i) WITH (
2020
option_bool = false,
21+
option_ternary1,
22+
option_ternary2 = off,
2123
option_int = 5,
2224
option_real = 3.1,
2325
option_enum = 'two',
@@ -30,6 +32,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx';
3032
-- ALTER INDEX .. SET
3133
ALTER INDEX dummy_test_idx SET (option_int = 10);
3234
ALTER INDEX dummy_test_idx SET (option_bool = true);
35+
ALTER INDEX dummy_test_idx SET (option_ternary1 = false);
36+
ALTER INDEX dummy_test_idx SET (option_ternary2 = Do_Not_Know_YET);
3337
ALTER INDEX dummy_test_idx SET (option_real = 3.2);
3438
ALTER INDEX dummy_test_idx SET (option_string_val = 'val2');
3539
ALTER INDEX dummy_test_idx SET (option_string_null = NULL);
@@ -40,6 +44,8 @@ SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx';
4044
-- ALTER INDEX .. RESET
4145
ALTER INDEX dummy_test_idx RESET (option_int);
4246
ALTER INDEX dummy_test_idx RESET (option_bool);
47+
ALTER INDEX dummy_test_idx RESET (option_ternary1);
48+
ALTER INDEX dummy_test_idx RESET (option_ternary2);
4349
ALTER INDEX dummy_test_idx RESET (option_real);
4450
ALTER INDEX dummy_test_idx RESET (option_enum);
4551
ALTER INDEX dummy_test_idx RESET (option_string_val);
@@ -60,6 +66,16 @@ ALTER INDEX dummy_test_idx SET (option_bool = 3.4); -- error
6066
ALTER INDEX dummy_test_idx SET (option_bool = 'val4'); -- error
6167
SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx';
6268
ALTER INDEX dummy_test_idx RESET (option_bool);
69+
-- Ternary
70+
ALTER INDEX dummy_test_idx SET (option_ternary1 = 4); -- error
71+
ALTER INDEX dummy_test_idx SET (option_ternary1 = 1); -- ok, as true
72+
ALTER INDEX dummy_test_idx SET (option_ternary1 = 3.4); -- error
73+
ALTER INDEX dummy_test_idx SET (option_ternary1 = 'val4'); -- error
74+
ALTER INDEX dummy_test_idx SET (option_ternary1 = 'do_not_know_yet'); -- error. Valid for ternary2 not for ternary1
75+
ALTER INDEX dummy_test_idx SET (option_ternary2 = 'do_not_know_yet'); -- ok
76+
SELECT unnest(reloptions) FROM pg_class WHERE relname = 'dummy_test_idx';
77+
ALTER INDEX dummy_test_idx RESET (option_ternary1);
78+
ALTER INDEX dummy_test_idx RESET (option_ternary2);
6379
-- Float
6480
ALTER INDEX dummy_test_idx SET (option_real = 4); -- ok
6581
ALTER INDEX dummy_test_idx SET (option_real = true); -- error

src/test/regress/expected/reloptions.out

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass;
9898
{fillfactor=13,autovacuum_enabled=false}
9999
(1 row)
100100

101-
-- Tests for future (FIXME) ternary options
101+
-- Tests for ternary options
102102
-- behave as boolean option: accept unassigned name and truncated value
103103
DROP TABLE reloptions_test;
104104
CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate);
@@ -116,7 +116,7 @@ SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass;
116116
{vacuum_truncate=fals}
117117
(1 row)
118118

119-
-- preferred "true" alias is used when storing
119+
-- preferred "true" alias is stored in pg_class
120120
DROP TABLE reloptions_test;
121121
CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on);
122122
SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass;

src/test/regress/sql/reloptions.sql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ UPDATE pg_class
5959
ALTER TABLE reloptions_test RESET (illegal_option);
6060
SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass;
6161

62-
-- Tests for future (FIXME) ternary options
62+
-- Tests for ternary options
6363

6464
-- behave as boolean option: accept unassigned name and truncated value
6565
DROP TABLE reloptions_test;
@@ -70,7 +70,7 @@ DROP TABLE reloptions_test;
7070
CREATE TABLE reloptions_test(i INT) WITH (vacuum_truncate=FaLS);
7171
SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass;
7272

73-
-- preferred "true" alias is used when storing
73+
-- preferred "true" alias is stored in pg_class
7474
DROP TABLE reloptions_test;
7575
CREATE TABLE reloptions_test(i INT) WITH (vacuum_index_cleanup=on);
7676
SELECT reloptions FROM pg_class WHERE oid = 'reloptions_test'::regclass;

0 commit comments

Comments
 (0)