forked from dolthub/dolt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdiff.bats
328 lines (304 loc) · 10.8 KB
/
diff.bats
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
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
#!/usr/bin/env bats
load $BATS_TEST_DIRNAME/helper/common.bash
setup() {
setup_common
}
teardown() {
teardown_common
}
@test "diff summary comparing working table to last commit" {
dolt sql <<SQL
CREATE TABLE test (
pk BIGINT NOT NULL COMMENT 'tag:0',
c1 BIGINT COMMENT 'tag:1',
c2 BIGINT COMMENT 'tag:2',
c3 BIGINT COMMENT 'tag:3',
c4 BIGINT COMMENT 'tag:4',
c5 BIGINT COMMENT 'tag:5',
PRIMARY KEY (pk)
);
SQL
dolt sql -q "insert into test values (0, 0, 0, 0, 0, 0)"
dolt sql -q "insert into test values (1, 1, 1, 1, 1, 1)"
dolt add test
dolt commit -m "table created"
dolt sql -q "insert into test values (2, 11, 0, 0, 0, 0)"
dolt sql -q "insert into test values (3, 11, 0, 0, 0, 0)"
run dolt diff --summary
[ "$status" -eq 0 ]
[[ "$output" =~ "2 Rows Unmodified (100.00%)" ]] || false
[[ "$output" =~ "2 Rows Added (100.00%)" ]] || false
[[ "$output" =~ "0 Rows Deleted (0.00%)" ]] || false
[[ "$output" =~ "0 Rows Modified (0.00%)" ]] || false
[[ "$output" =~ "0 Cells Modified (0.00%)" ]] || false
[[ "$output" =~ "(2 Entries vs 4 Entries)" ]] || false
dolt add test
dolt commit -m "added two rows"
dolt sql -q "replace into test values (0, 11, 0, 0, 0, 6)"
run dolt diff --summary
[ "$status" -eq 0 ]
[[ "$output" =~ "3 Rows Unmodified (75.00%)" ]] || false
[[ "$output" =~ "0 Rows Added (0.00%)" ]] || false
[[ "$output" =~ "0 Rows Deleted (0.00%)" ]] || false
[[ "$output" =~ "1 Row Modified (25.00%)" ]] || false
[[ "$output" =~ "2 Cells Modified (8.33%)" ]] || false
[[ "$output" =~ "(4 Entries vs 4 Entries)" ]] || false
dolt add test
dolt commit -m "modified first row"
dolt sql -q "delete from test where pk = 0"
run dolt diff --summary
[ "$status" -eq 0 ]
[[ "$output" =~ "3 Rows Unmodified (75.00%)" ]] || false
[[ "$output" =~ "0 Rows Added (0.00%)" ]] || false
[[ "$output" =~ "1 Row Deleted (25.00%)" ]] || false
[[ "$output" =~ "0 Rows Modified (0.00%)" ]] || false
[[ "$output" =~ "0 Cells Modified (0.00%)" ]] || false
[[ "$output" =~ "(4 Entries vs 3 Entries)" ]] || false
}
@test "diff summary comparing row with a deleted cell and an added cell" {
dolt sql <<SQL
CREATE TABLE test (
pk BIGINT NOT NULL COMMENT 'tag:0',
c1 BIGINT COMMENT 'tag:1',
c2 BIGINT COMMENT 'tag:2',
c3 BIGINT COMMENT 'tag:3',
c4 BIGINT COMMENT 'tag:4',
c5 BIGINT COMMENT 'tag:5',
PRIMARY KEY (pk)
);
SQL
dolt add test
dolt commit -m "create table"
dolt sql -q "insert into test values (0, 1, 2, 3, 4, 5)"
dolt add test
dolt commit -m "put row"
dolt sql -q "replace into test (pk, c1, c3, c4, c5) values (0, 1, 3, 4, 5)"
run dolt diff --summary
[ "$status" -eq 0 ]
[[ "$output" =~ "0 Rows Unmodified (0.00%)" ]] || false
[[ "$output" =~ "0 Rows Added (0.00%)" ]] || false
[[ "$output" =~ "0 Rows Deleted (0.00%)" ]] || false
[[ "$output" =~ "1 Row Modified (100.00%)" ]] || false
[[ "$output" =~ "1 Cell Modified (16.67%)" ]] || false
[[ "$output" =~ "(1 Entry vs 1 Entry)" ]] || false
dolt add test
dolt commit -m "row modified"
dolt sql -q "replace into test values (0, 1, 2, 3, 4, 5)"
run dolt diff --summary
[ "$status" -eq 0 ]
[[ "$output" =~ "0 Rows Unmodified (0.00%)" ]] || false
[[ "$output" =~ "0 Rows Added (0.00%)" ]] || false
[[ "$output" =~ "0 Rows Deleted (0.00%)" ]] || false
[[ "$output" =~ "1 Row Modified (100.00%)" ]] || false
[[ "$output" =~ "1 Cell Modified (16.67%)" ]] || false
[[ "$output" =~ "(1 Entry vs 1 Entry)" ]] || false
}
@test "diff summary comparing two branches" {
dolt checkout -b firstbranch
dolt sql <<SQL
CREATE TABLE test (
pk BIGINT NOT NULL COMMENT 'tag:0',
c1 BIGINT COMMENT 'tag:1',
c2 BIGINT COMMENT 'tag:2',
c3 BIGINT COMMENT 'tag:3',
c4 BIGINT COMMENT 'tag:4',
c5 BIGINT COMMENT 'tag:5',
PRIMARY KEY (pk)
);
SQL
dolt sql -q "insert into test values (0, 0, 0, 0, 0, 0)"
dolt add test
dolt commit -m "Added one row"
dolt checkout -b newbranch
dolt sql -q "insert into test values (1, 1, 1, 1, 1, 1)"
dolt add test
dolt commit -m "Added another row"
run dolt diff --summary newbranch firstbranch
[ "$status" -eq 0 ]
[[ "$output" =~ "1 Row Unmodified (100.00%)" ]] || false
[[ "$output" =~ "1 Row Added (100.00%)" ]] || false
[[ "$output" =~ "0 Rows Deleted (0.00%)" ]] || false
[[ "$output" =~ "0 Rows Modified (0.00%)" ]] || false
[[ "$output" =~ "0 Cells Modified (0.00%)" ]] || false
[[ "$output" =~ "(1 Entry vs 2 Entries)" ]] || false
}
@test "diff summary shows correct changes after schema change" {
dolt table import -c -s=`batshelper employees-sch.sql` employees `batshelper employees-tbl.json`
dolt add employees
dolt commit -m "Added employees table with data"
dolt sql -q "alter table employees add city longtext"
dolt sql -q "insert into employees values (3, 'taylor', 'bantle', 'software engineer', '', '', 'Santa Monica')"
run dolt diff --summary
[ "$status" -eq 0 ]
[[ "$output" =~ "3 Rows Unmodified (100.00%)" ]] || false
[[ "$output" =~ "1 Row Added (33.33%)" ]] || false
[[ "$output" =~ "0 Rows Deleted (0.00%)" ]] || false
[[ "$output" =~ "0 Rows Modified (0.00%)" ]] || false
[[ "$output" =~ "0 Cells Modified (0.00%)" ]] || false
[[ "$output" =~ "(3 Entries vs 4 Entries)" ]] || false
dolt sql -q "replace into employees values (0, 'tim', 'sehn', 'ceo', '2 years ago', '', 'Santa Monica')"
run dolt diff --summary
[ "$status" -eq 0 ]
[[ "$output" =~ "2 Rows Unmodified (66.67%)" ]] || false
[[ "$output" =~ "1 Row Added (33.33%)" ]] || false
[[ "$output" =~ "0 Rows Deleted (0.00%)" ]] || false
[[ "$output" =~ "1 Row Modified (33.33%)" ]] || false
[[ "$output" =~ "2 Cells Modified (11.11%)" ]] || false
[[ "$output" =~ "(3 Entries vs 4 Entries)" ]] || false
}
@test "diff summary gets summaries for all tables with changes" {
dolt sql <<SQL
CREATE TABLE test (
pk BIGINT NOT NULL,
c1 BIGINT,
c2 BIGINT,
c3 BIGINT,
c4 BIGINT,
c5 BIGINT,
PRIMARY KEY (pk)
);
SQL
dolt sql -q "insert into test values (0, 0, 0, 0, 0, 0)"
dolt sql -q "insert into test values (1, 1, 1, 1, 1, 1)"
dolt sql <<SQL
CREATE TABLE employees (
\`id\` LONGTEXT NOT NULL,
\`first name\` LONGTEXT,
\`last name\` LONGTEXT,
\`title\` LONGTEXT,
\`start date\` LONGTEXT,
\`end date\` LONGTEXT,
PRIMARY KEY (id)
);
SQL
dolt sql -q "insert into employees values (0, 'tim', 'sehn', 'ceo', '', '')"
dolt add test employees
dolt commit -m "test tables created"
dolt sql -q "insert into test values (2, 11, 0, 0, 0, 0)"
dolt sql -q "insert into employees values (1, 'brian', 'hendriks', 'founder', '', '')"
run dolt diff --summary
[ "$status" -eq 0 ]
[[ "$output" =~ "diff --dolt a/test b/test" ]] || false
[[ "$output" =~ "--- a/test @" ]] || false
[[ "$output" =~ "+++ b/test @" ]] || false
[[ "$output" =~ "diff --dolt a/employees b/employees" ]] || false
[[ "$output" =~ "--- a/employees @" ]] || false
[[ "$output" =~ "+++ b/employees @" ]] || false
}
@test "diff with where clause" {
dolt sql <<SQL
CREATE TABLE test (
pk BIGINT NOT NULL COMMENT 'tag:0',
c1 BIGINT COMMENT 'tag:1',
c2 BIGINT COMMENT 'tag:2',
c3 BIGINT COMMENT 'tag:3',
c4 BIGINT COMMENT 'tag:4',
c5 BIGINT COMMENT 'tag:5',
PRIMARY KEY (pk)
);
SQL
dolt sql -q "insert into test values (0, 0, 0, 0, 0, 0)"
dolt sql -q "insert into test values (1, 1, 1, 1, 1, 1)"
dolt add test
dolt commit -m "table created"
dolt sql -q "insert into test values (2, 22, 0, 0, 0, 0)"
dolt sql -q "insert into test values (3, 33, 0, 0, 0, 0)"
run dolt diff --where "pk=2"
[ "$status" -eq 0 ]
[[ "$output" =~ "22" ]] || false
! [[ "$output" =~ "33" ]] || false
dolt add test
dolt commit -m "added two rows"
dolt checkout -b test1
dolt sql -q "insert into test values (4, 44, 0, 0, 0, 0)"
dolt add .
dolt commit -m "committed to branch test1"
dolt checkout master
dolt checkout -b test2
dolt sql -q "insert into test values (5, 55, 0, 0, 0, 0)"
dolt add .
dolt commit -m "committed to branch test2"
dolt checkout master
run dolt diff test1 test2
[ "$status" -eq 0 ]
[[ "$output" =~ "44" ]] || false
[[ "$output" =~ "55" ]] || false
run dolt diff test1 test2 --where "pk=4"
[ "$status" -eq 0 ]
[[ "$output" =~ "44" ]] || false
! [[ "$output" =~ "55" ]] || false
run dolt diff test1 test2 --where "to_pk=4"
[ "$status" -eq 0 ]
[[ "$output" =~ "44" ]] || false
! [[ "$output" =~ "55" ]] || false
run dolt diff test1 test2 --where "to_pk=5"
[ "$status" -eq 0 ]
! [[ "$output" =~ "44" ]] || false
! [[ "$output" =~ "55" ]] || false
run dolt diff test1 test2 --where "from_pk=5"
[ "$status" -eq 0 ]
[[ "$output" =~ "55" ]] || false
! [[ "$output" =~ "44" ]] || false
run dolt diff test1 test2 --where "from_pk=4"
[ "$status" -eq 0 ]
! [[ "$output" =~ "44" ]] || false
! [[ "$output" =~ "55" ]] || false
}
@test "diff with where clause errors" {
dolt sql <<SQL
CREATE TABLE test (
pk BIGINT NOT NULL COMMENT 'tag:0',
c1 BIGINT COMMENT 'tag:1',
c2 BIGINT COMMENT 'tag:2',
c3 BIGINT COMMENT 'tag:3',
c4 BIGINT COMMENT 'tag:4',
c5 BIGINT COMMENT 'tag:5',
PRIMARY KEY (pk)
);
SQL
dolt sql -q "insert into test values (0, 0, 0, 0, 0, 0)"
dolt sql -q "insert into test values (1, 1, 1, 1, 1, 1)"
dolt add test
dolt commit -m "table created"
dolt sql -q "insert into test values (2, 22, 0, 0, 0, 0)"
dolt sql -q "insert into test values (3, 33, 0, 0, 0, 0)"
run dolt diff --where "poop=0"
[ "$status" -eq 1 ]
[[ "$output" =~ "failed to parse where clause" ]] || false
dolt add test
dolt commit -m "added two rows"
run dolt diff --where "poop=0"
skip "Bad where clause not found because the argument parsing logic is only triggered on existance of a diff"
[ "$status" -eq 1 ]
[[ "$output" =~ "failed to parse where clause" ]] || false
}
@test "diff --cached" {
dolt sql <<SQL
CREATE TABLE test (
pk BIGINT NOT NULL COMMENT 'tag:0',
c1 BIGINT COMMENT 'tag:1',
c2 BIGINT COMMENT 'tag:2',
c3 BIGINT COMMENT 'tag:3',
c4 BIGINT COMMENT 'tag:4',
c5 BIGINT COMMENT 'tag:5',
PRIMARY KEY (pk)
);
SQL
skip "diff --cached not supported"
run dolt diff --cached
[ $status -wq 0 ]
[ $output -eq "" ]
dolt add test
run dolt diff --cached
[ $status -wq 0 ]
[[ $output =~ "added table" ]] || false
dolt commit -m "First commit"
dolt sql -q "insert into test values (0, 0, 0, 0, 0, 0)"
run dolt diff
[ $status -eq 0 ]
CORRECT_DIFF=$output
dolt add test
run dolt diff --cached
[ $status -eq 0 ]
[ $output -eq $CORRECT_DIFF ]
}