1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
//! How much a listing returns, and how a caller asks for more.
//!
//! # Why these proofs sit apart from their neighbours
//!
//! `coverage_structure_catalog.rs` proves that each listing tells the truth
//! about the objects it names. These prove something else about the same
//! commands: how wide the answer is, and whether the caller has any way of
//! changing that. The two questions were together and the file outgrew the
//! ceiling, so they are split along the seam the file's own opening declares.
//!
//! The depth used to be a truth value the manual never published, reachable on
//! six listings and on no other, while three listings carried extras in the
//! catalogue that no argument could ask for. What is proved here is the level
//! the manual does publish, on every listing that has one.
// Each file here uses the part of the shared module that it needs, so a helper
// unused by this one is not dead code.
#[allow(dead_code)]
mod support;
use support::server::{destination_or_skip, on_server};
use support::Sandbox;
/// The database every fixture of this file lives in.
const FIXTURE_DATABASE: &str = "shop";
/// FR-019. The search reaches a column and a database as well as a table, and
/// the detailed form of a match carries more than the short one.
///
/// The argv written here is the one the manual publishes: the pattern as
/// `--like` and the kind as `--type`. The build served a bare word and `--kind`
/// while the manual said otherwise, so a reader who copied the manual was
/// refused. The older spelling is kept as an alias and is exercised below, so
/// neither reader is left out.
///
/// # Why the reach is asserted and not only the pattern
///
/// Half of what a caller half-remembers is a column name, and a search that
/// silently looks at tables only answers an empty list for every one of those.
/// An empty list is indistinguishable from an absent object, so a kind left out
/// of the sweep is a wrong answer wearing the shape of a right one.
#[test]
fn the_search_reaches_a_column_and_a_database_and_deepens_on_request() {
let Some(dsn) = destination_or_skip("the reach of the search by name") else {
return;
};
let sandbox = Sandbox::new();
let column = on_server(
&sandbox,
&dsn,
&[
"schema",
"search",
"--database",
FIXTURE_DATABASE,
"--type",
"column",
"--like",
"amount%",
],
);
assert_eq!(column.code, 0, "the search over columns: {}", column.err);
let short = column.rows();
assert!(
short.iter().any(|row| row["kind"] == "column"),
"no column was reached by the search: {short:?}"
);
let database = on_server(
&sandbox,
&dsn,
&["schema", "search", "--kind", "database", FIXTURE_DATABASE],
);
assert_eq!(
database.code, 0,
"the search over databases: {}",
database.err
);
assert!(
database
.rows()
.iter()
.any(|row| row["name"] == FIXTURE_DATABASE),
"the database the fixtures live in was not reached: {:?}",
database.rows()
);
let deep = on_server(
&sandbox,
&dsn,
&[
"schema",
"search",
"--database",
FIXTURE_DATABASE,
"--type",
"column",
"--detail",
"full",
"--like",
"amount%",
],
);
assert_eq!(deep.code, 0, "the detailed search: {}", deep.err);
let deep_rows = deep.rows();
assert!(
!deep_rows.is_empty(),
"the detailed search found nothing to compare"
);
let widened = deep_rows[0]
.as_object()
.expect("a match is an object")
.len();
let narrow = short[0].as_object().expect("a match is an object").len();
assert!(
widened > narrow,
"asking for more returned the same {narrow} fields: {deep_rows:?}"
);
}
/// FR-015 and FR-091. The depth a caller asks for reaches the listings that had
/// no way of being asked, and a level outside the published domain is refused
/// rather than read as the default.
///
/// # Why this is worth a proof of its own
///
/// The catalogue entry for an index has always carried its method, its
/// cardinality, its prefix length and its comment. Nothing published a way of
/// asking for them, so the projection existed, was correct, and was unreachable
/// from the command line — which is indistinguishable, from outside, from not
/// existing at all.
#[test]
fn the_depth_reaches_the_listings_that_could_not_be_asked() {
let Some(dsn) = destination_or_skip("the depth of the index and link listings") else {
return;
};
let sandbox = Sandbox::new();
let short = on_server(
&sandbox,
&dsn,
&[
"schema",
"indexes",
"--database",
FIXTURE_DATABASE,
"--table",
"orders",
],
);
assert_eq!(short.code, 0, "the short listing: {}", short.err);
let deep = on_server(
&sandbox,
&dsn,
&[
"schema",
"indexes",
"--database",
FIXTURE_DATABASE,
"--table",
"orders",
"--detail",
"full",
],
);
assert_eq!(deep.code, 0, "the deep listing: {}", deep.err);
let narrow = short.rows();
let widened = deep.rows();
assert!(!narrow.is_empty(), "this table carries no index to deepen");
assert_eq!(
narrow.len(),
widened.len(),
"asking for depth changed which indexes exist"
);
let narrow_fields = narrow[0].as_object().expect("a row is an object");
let widened_fields = widened[0].as_object().expect("a row is an object");
assert!(
widened_fields.len() > narrow_fields.len(),
"asking for more returned the same fields: {widened_fields:?}"
);
for name in narrow_fields.keys() {
assert!(
widened_fields.contains_key(name),
"the deeper form dropped `{name}`, so asking for more returned less"
);
}
// The two listings that carry no fixture here are asserted to accept the
// level at all, which is the half that was missing from them.
for listing in ["keys", "partitions"] {
let taken = on_server(
&sandbox,
&dsn,
&[
"schema",
listing,
"--database",
FIXTURE_DATABASE,
"--table",
"orders",
"--detail",
"full",
],
);
assert_eq!(
taken.code, 0,
"`schema {listing}` must accept a level: {}",
taken.err
);
}
let refused = on_server(
&sandbox,
&dsn,
&[
"schema",
"indexes",
"--database",
FIXTURE_DATABASE,
"--detail",
"inexistente",
],
);
assert_eq!(
refused.code, 2,
"a level outside the domain must be refused: {}",
refused.out
);
}