Repository navigation
Expand file tree
/
Copy pathpartial_test.go
More file actions
565 lines (472 loc) · 22.1 KB
/
Copy pathpartial_test.go
File metadata and controls
565 lines (472 loc) · 22.1 KB
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
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
package mark
import (
"context"
"os"
"path/filepath"
"runtime"
"strings"
"testing"
"github.com/kovetskiy/mark/v17/confluence"
"github.com/kovetskiy/mark/v17/confluence/confluencetest"
"github.com/kovetskiy/mark/v17/manifest"
"github.com/kovetskiy/mark/v17/report"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
// partialFixture publishes a.md, b.md and c.md under one pattern with
// --track-pages, as the run that owns them does.
func partialFixture(t *testing.T) (*confluencetest.Server, Config, string) {
t.Helper()
server, _ := docsSpace(t)
dir := t.TempDir()
for _, name := range []string{"a", "b", "c"} {
writeFile(t, dir, name+".md", markdownWithTitle("Page "+name))
}
full := trackingConfig(server, filepath.Join(dir, "*.md"))
require.NoError(t, Run(context.Background(), full))
return server, full, dir
}
// partialOf is the run a job publishing only some of full's files makes.
func partialOf(full Config, dir, files string) Config {
partial := full
partial.Files = filepath.Join(dir, files)
partial.Tracking.Partial = true
return partial
}
// pathsOf is the run a job naming only exact paths, deleted ones included,
// makes beside full, with --on-orphan delete.
func pathsOf(full Config, dir string, names ...string) Config {
partial := full
partial.Files = ""
partial.Paths = nil
for _, name := range names {
partial.Paths = append(partial.Paths, filepath.Join(dir, name))
}
partial.Tracking.Partial = true
partial.Tracking.OnOrphan = report.OnOrphanDelete
return partial
}
// tracked reads the manifest afresh: a store reads it once and keeps it.
func tracked(t *testing.T, server *confluencetest.Server, file string) (manifest.Entry, bool) {
t.Helper()
api := confluence.NewAPI(server.URL, confluence.Options{Username: "user", Password: "token"})
entry, ok, err := manifest.NewStore(api).Lookup(context.Background(), "DOCS", file)
require.NoError(t, err)
return entry, ok
}
// TestPartialRunReportsOnlyWhatItNames: a job given the paths a change
// touched, a deleted one among them, reports that one as gone and nothing
// else. Without --partial its pattern matches no entry, the owning run's
// pattern having recorded them all, so the deleted file is not reported, and
// with the owning run's pattern every file it left out would be.
func TestPartialRunReportsOnlyWhatItNames(t *testing.T) {
server, full, dir := partialFixture(t)
require.NoError(t, os.Remove(filepath.Join(dir, "b.md")))
logged := captureLog(t, func() {
require.NoError(t, Run(context.Background(), partialOf(full, dir, "{a,b}.md")))
})
reported := ""
for _, line := range strings.Split(logged, "\n") {
if strings.Contains(line, "had no matching source file") {
reported = line
}
}
assert.Contains(t, reported, "b.md")
assert.NotContains(t, reported, "c.md", "c.md is not this run's business")
_, ok := tracked(t, server, filepath.Join(dir, "c.md"))
assert.True(t, ok, "c.md is still tracked")
// Reporting leaves b.md to the run owning it, which deals with its page.
_, ok = tracked(t, server, filepath.Join(dir, "b.md"))
require.True(t, ok, "b.md was only reported, so still tracked")
bID := pageIDTitled(t, server, "Page b")
owner := full
owner.Tracking.OnOrphan = report.OnOrphanDelete
require.NoError(t, Run(context.Background(), owner))
assert.True(t, server.Page(bID).Trashed)
}
// TestPartialRunActsOnlyOnWhatItNames: --on-orphan in a partial run removes
// the page of a file the run names and finds gone, and no other.
func TestPartialRunActsOnlyOnWhatItNames(t *testing.T) {
server, full, dir := partialFixture(t)
bID := pageIDTitled(t, server, "Page b")
cID := pageIDTitled(t, server, "Page c")
require.NoError(t, os.Remove(filepath.Join(dir, "b.md")))
require.NoError(t, os.Remove(filepath.Join(dir, "c.md")))
require.NoError(t, Run(context.Background(), pathsOf(full, dir, "a.md", "b.md")))
assert.True(t, server.Page(bID).Trashed, "b.md was named and is gone")
assert.False(t, server.Page(cID).Trashed, "c.md was not named, and is left for the owning run")
_, ok := tracked(t, server, filepath.Join(dir, "c.md"))
assert.True(t, ok)
}
// TestPartialRunGivenTheOwningPatternLeavesItsFilesAlone: the owning run's own
// pattern with --partial, on a checkout holding only some of its files, would
// read every other file as deleted. Like a page outside --orphan-under they are
// not reported -- in the github format every one would be a warning on every
// such run -- and stay tracked for the owning run. A path named exactly beside
// the pattern is still reported.
func TestPartialRunGivenTheOwningPatternLeavesItsFilesAlone(t *testing.T) {
server, full, dir := partialFixture(t)
require.NoError(t, os.Remove(filepath.Join(dir, "b.md")))
require.NoError(t, os.Remove(filepath.Join(dir, "c.md")))
var out strings.Builder
sparse := partialOf(full, dir, "*.md")
sparse.Paths = []string{filepath.Join(dir, "b.md")}
sparse.Report.OutputFormat = report.FormatGitHub
sparse.Output = &out
logged := captureLog(t, func() {
require.NoError(t, Run(context.Background(), sparse))
})
assert.Contains(t, logged, "the pattern given to --partial")
var warnings []string
for _, line := range strings.Split(out.String(), "\n") {
if strings.HasPrefix(line, "::warning") {
warnings = append(warnings, line)
}
}
require.Len(t, warnings, 1, out.String())
assert.Contains(t, warnings[0], "b.md", "named exactly, so reported")
for _, name := range []string{"b.md", "c.md"} {
_, ok := tracked(t, server, filepath.Join(dir, name))
assert.True(t, ok, "%s stays tracked for the owning run", name)
}
}
// TestPartialRunRemovingRefusesAPattern: a wildcard under --partial reaches
// every tracked file it matches, another job's included, and on a checkout
// holding only some of them reads the rest as deleted. Told to archive or
// delete, a partial run takes only exact paths, and says so before publishing.
func TestPartialRunRemovingRefusesAPattern(t *testing.T) {
server, full, dir := partialFixture(t)
writeFile(t, dir, "a.md", markdownWithTitle("Page a")+"\nChanged.\n")
for _, action := range []report.OnOrphan{report.OnOrphanArchive, report.OnOrphanDelete} {
for _, files := range []string{"*.md", "{a,b}.md", "[ab].md", "a?md"} {
partial := partialOf(full, dir, files)
partial.Tracking.OnOrphan = action
err := Run(context.Background(), partial)
require.ErrorIs(t, err, ErrPartialPattern, files)
for _, name := range []string{
"Tracking.OnOrphan", "--on-orphan", "Tracking.Partial", "--partial",
"Files", "--files", "Paths", "--files-from",
} {
assert.ErrorContains(t, err, name)
}
}
}
aID := pageIDTitled(t, server, "Page a")
assert.NotContains(t, server.Page(aID).Body, "Changed", "refused before publishing")
// Reporting removes nothing, so a pattern is fine.
reporting := partialOf(full, dir, "*.md")
require.NoError(t, Run(context.Background(), reporting))
}
// TestPartialRunRemovingTakesOneFile: Files spelling one file, an escaped glob
// character included, names exactly that file, as Paths would. On Windows a
// backslash separates path elements, so nothing escapes "[": Files holding one
// is refused, and Paths names the file instead.
func TestPartialRunRemovingTakesOneFile(t *testing.T) {
server, full, dir := partialFixture(t)
bID := pageIDTitled(t, server, "Page b")
require.NoError(t, os.Remove(filepath.Join(dir, "b.md")))
writeFile(t, dir, "[x].md", markdownWithTitle("Page x"))
partial := partialOf(full, dir, "b.md")
partial.Tracking.OnOrphan = report.OnOrphanDelete
// Nothing to publish: the change only deleted b.md.
require.ErrorContains(t, Run(context.Background(), partial), "no files matched")
if runtime.GOOS == "windows" {
partial = partialOf(full, dir, "[x].md")
partial.Tracking.OnOrphan = report.OnOrphanDelete
err := Run(context.Background(), partial)
require.ErrorIs(t, err, ErrPartialPattern)
assert.ErrorContains(t, err, "--files-from")
require.NoError(t, Run(context.Background(), pathsOf(full, dir, "[x].md")))
} else {
partial = partialOf(full, dir, `\[x\].md`)
partial.Tracking.OnOrphan = report.OnOrphanDelete
require.NoError(t, Run(context.Background(), partial))
}
assert.Equal(t, 1, countPagesTitled(t, server, "Page x"))
require.NoError(t, Run(context.Background(), pathsOf(full, dir, "b.md", "a.md")))
assert.True(t, server.Page(bID).Trashed)
}
// TestPartialRunStillWarnsOfAKeptOrphan: a page --on-orphan was asked to remove
// and left alone, here for holding a child, is still a warning in the github
// format under --partial.
func TestPartialRunStillWarnsOfAKeptOrphan(t *testing.T) {
server, full, dir := partialFixture(t)
bID := pageIDTitled(t, server, "Page b")
server.AddPage("DOCS", "Child of b", "page", bID)
require.NoError(t, os.Remove(filepath.Join(dir, "b.md")))
var out strings.Builder
partial := pathsOf(full, dir, "a.md", "b.md")
partial.Report.OutputFormat = report.FormatGitHub
partial.Output = &out
require.NoError(t, Run(context.Background(), partial))
assert.False(t, server.Page(bID).Trashed)
assert.Contains(t, out.String(), "::warning")
assert.Contains(t, out.String(), "left alone")
}
// TestPartialRunLeavesEntriesUnderTheirPattern: a run narrowed to one file
// records that file's page. Recorded under the narrow pattern, the entry would
// drop out of the owning run's scope, and that run would never notice the file
// being deleted.
func TestPartialRunLeavesEntriesUnderTheirPattern(t *testing.T) {
server, full, dir := partialFixture(t)
a := filepath.Join(dir, "a.md")
before, ok := tracked(t, server, a)
require.True(t, ok)
writeFile(t, dir, "a.md", markdownWithTitle("Page a")+"\nChanged.\n")
require.NoError(t, Run(context.Background(), partialOf(full, dir, "a.md")))
after, ok := tracked(t, server, a)
require.True(t, ok)
assert.Equal(t, before.Glob, after.Glob, "the entry stays under the owning run's pattern")
assert.NotEqual(t, before.Hash, after.Hash, "the entry still records what was published")
require.NoError(t, os.Remove(a))
owner := full
owner.Tracking.OnOrphan = report.OnOrphanDelete
require.NoError(t, Run(context.Background(), owner))
_, ok = tracked(t, server, a)
assert.False(t, ok, "the owning run found the deleted file and dealt with its page")
}
// TestPartialRunRecordsANewFileUnderItsOwnPattern: a file no run has tracked
// has no pattern to keep, so it takes the partial run's until the owning run
// publishes it.
func TestPartialRunRecordsANewFileUnderItsOwnPattern(t *testing.T) {
server, full, dir := partialFixture(t)
d := writeFile(t, dir, "d.md", markdownWithTitle("Page d"))
require.NoError(t, Run(context.Background(), partialOf(full, dir, "d.md")))
entry, ok := tracked(t, server, d)
require.True(t, ok)
assert.Equal(t, manifest.Key(d), entry.Glob)
require.NoError(t, Run(context.Background(), full))
entry, ok = tracked(t, server, d)
require.True(t, ok)
assert.Equal(t, manifest.Key(full.Files), entry.Glob)
}
// TestPartialRunFollowsAMove: a file moved with its title unchanged, given to a
// partial run under both names, hands its entry to the new path. Without
// --partial the old entry belongs to another pattern, so the run warns that two
// files claim the page, keeps both, and the new path starts under the partial
// pattern.
func TestPartialRunFollowsAMove(t *testing.T) {
server, full, dir := partialFixture(t)
b := filepath.Join(dir, "b.md")
before, ok := tracked(t, server, b)
require.True(t, ok)
moved := filepath.Join(dir, "moved.md")
require.NoError(t, os.Rename(b, moved))
logged := captureLog(t, func() {
require.NoError(t, Run(context.Background(), partialOf(full, dir, "{b,moved}.md")))
})
assert.NotContains(t, logged, "both publish to page")
_, ok = tracked(t, server, b)
assert.False(t, ok, "the old path handed its entry over")
after, ok := tracked(t, server, moved)
require.True(t, ok)
assert.Equal(t, before.PageID, after.PageID)
assert.Equal(t, before.Glob, after.Glob, "the new path takes the old one's pattern")
}
// TestPartialRunMovesAFileIntoAnotherJobsPattern: a file moved out of one
// job's pattern into another's does not keep the first job's pattern, or that
// job's next run would read it as deleted and trash the page it still
// publishes to.
func TestPartialRunMovesAFileIntoAnotherJobsPattern(t *testing.T) {
server, _ := docsSpace(t)
dir := t.TempDir()
writeAt(t, dir, "docs/keep.md", markdownWithTitle("Keep"))
writeAt(t, dir, "docs/x.md", markdownWithTitle("Page x"))
writeAt(t, dir, "guides/y.md", markdownWithTitle("Page y"))
docs := trackingConfig(server, filepath.Join(dir, "docs", "*.md"))
guides := trackingConfig(server, filepath.Join(dir, "guides", "*.md"))
require.NoError(t, Run(context.Background(), docs))
require.NoError(t, Run(context.Background(), guides))
id := pageIDTitled(t, server, "Page x")
moved := filepath.Join(dir, "guides", "x.md")
require.NoError(t, os.Rename(filepath.Join(dir, "docs", "x.md"), moved))
require.NoError(t, Run(context.Background(), partialOf(docs, dir, "{docs,guides}/x.md")))
entry, ok := tracked(t, server, moved)
require.True(t, ok)
assert.Equal(t, id, entry.PageID, "the move was followed")
assert.NotEqual(t, manifest.Key(docs.Files), entry.Glob)
docs.Tracking.OnOrphan = report.OnOrphanDelete
require.NoError(t, Run(context.Background(), docs))
assert.False(t, server.Page(id).Trashed, "guides/x.md still publishes to it")
}
// TestPartialRunNamesTheMissingPathOfAMove: a partial run given only the new
// path of a moved file cannot tell a move from two files claiming one page,
// and its warning says which path to name.
func TestPartialRunNamesTheMissingPathOfAMove(t *testing.T) {
_, full, dir := partialFixture(t)
require.NoError(t, os.Rename(filepath.Join(dir, "b.md"), filepath.Join(dir, "moved.md")))
logged := captureLog(t, func() {
require.NoError(t, Run(context.Background(), partialOf(full, dir, "moved.md")))
})
assert.Contains(t, logged, "both publish to page")
assert.Contains(t, logged, "name both paths in --files or --files-from to follow the move")
}
// TestPartialRunFollowsARename: a file renamed along with its title is found
// by its content, as in a full run, and an edit made in Confluence survives
// it under --no-overwrite.
func TestPartialRunFollowsARename(t *testing.T) {
server, _ := docsSpace(t)
dir := t.TempDir()
writeFile(t, dir, "old-name.md", markdownTitledFromFilename())
writeFile(t, dir, "other.md", markdownTitledFromFilename()+"\nOther.\n")
full := filenameTitleConfig(server, filepath.Join(dir, "*.md"))
full.Tracking.NoOverwrite = true
require.NoError(t, Run(context.Background(), full))
id := pageIDTitled(t, server, "Old Name")
server.EditPage(id, "<p>Written by a person.</p>")
require.NoError(t, os.Rename(
filepath.Join(dir, "old-name.md"), filepath.Join(dir, "new-name.md")))
renamed := runReported(t, partialOf(full, dir, "{old-name,new-name}.md"))
assert.Equal(t, report.StatusSkipped, renamed.Status)
assert.Contains(t, renamed.Reason, "edited in Confluence")
assert.Equal(t, "<p>Written by a person.</p>", server.Page(id).Body)
assert.Zero(t, countPagesTitled(t, server, "New Name"), "no second page")
entry, ok := tracked(t, server, filepath.Join(dir, "new-name.md"))
require.True(t, ok)
assert.Equal(t, id, entry.PageID)
assert.Equal(t, manifest.Key(full.Files), entry.Glob)
}
func TestPartialRequiresTrackPages(t *testing.T) {
server, _ := docsSpace(t)
dir := t.TempDir()
writeFile(t, dir, "a.md", markdownWithTitle("Page a"))
config := trackingConfig(server, filepath.Join(dir, "*.md"))
config.Tracking = TrackingConfig{Partial: true}
err := Run(context.Background(), config)
require.Error(t, err)
assert.Contains(t, err.Error(), "--partial requires --track-pages")
assert.Zero(t, countPagesTitled(t, server, "Page a"), "refused before publishing")
}
// TestPartialRunGivenPaths: paths given as a list are taken as written, glob
// characters and all, and a deleted one among them is looked for like a file
// a pattern names.
func TestPartialRunGivenPaths(t *testing.T) {
server, full, dir := partialFixture(t)
// Windows has no file name with a '*' in it.
weirdName := "we[a]{b,c}*.md"
if runtime.GOOS == "windows" {
weirdName = "we[a]{b,c}.md"
}
weird := writeFile(t, dir, weirdName, markdownWithTitle("Page weird"))
require.NoError(t, Run(context.Background(), full))
bID := pageIDTitled(t, server, "Page b")
cID := pageIDTitled(t, server, "Page c")
require.NoError(t, os.Remove(filepath.Join(dir, "b.md")))
require.NoError(t, os.Remove(filepath.Join(dir, "c.md")))
writeFile(t, dir, weirdName, markdownWithTitle("Page weird renamed"))
require.NoError(t, Run(context.Background(), pathsOf(full, dir, filepath.Base(weird), "b.md")))
assert.Equal(t, 1, countPagesTitled(t, server, "Page weird renamed"), "the path was published as written")
assert.Equal(t, 1, countPagesTitled(t, server, "Page a"))
assert.True(t, server.Page(bID).Trashed, "b.md was named and is gone")
assert.False(t, server.Page(cID).Trashed, "c.md was not named")
entry, ok := tracked(t, server, weird)
require.True(t, ok)
assert.Equal(t, manifest.Key(full.Files), entry.Glob, "the entry keeps the owning run's pattern")
}
// TestPathsAreNotPatterns: a path holding glob characters names that one file,
// not the files it would match as a pattern.
func TestPathsAreNotPatterns(t *testing.T) {
server, _ := docsSpace(t)
dir := t.TempDir()
literal := writeFile(t, dir, "[ab].md", markdownWithTitle("Literal"))
writeFile(t, dir, "a.md", markdownWithTitle("Page a"))
config := trackingConfig(server, "")
config.Paths = []string{literal}
require.NoError(t, Run(context.Background(), config))
assert.Equal(t, 1, countPagesTitled(t, server, "Literal"))
assert.Zero(t, countPagesTitled(t, server, "Page a"))
}
func TestPathsWithParentsFromPathNeedARoot(t *testing.T) {
server, _ := docsSpace(t)
dir := t.TempDir()
config := trackingConfig(server, "")
config.Paths = []string{writeFile(t, dir, "a.md", markdownWithTitle("Page a"))}
config.ParentsFromPath = true
err := Run(context.Background(), config)
require.ErrorContains(t, err, "needs --parents-from-path-root")
assert.Zero(t, countPagesTitled(t, server, "Page a"))
}
// TestPartialRunGivenTheOwningPatternFollowsNoRenameFromIt: on a checkout
// holding only some of the owning pattern's files, a file not checked out is
// not the old name of a new file with the same content, whose run would
// otherwise take its page over and retitle it.
func TestPartialRunGivenTheOwningPatternFollowsNoRenameFromIt(t *testing.T) {
server, _ := docsSpace(t)
dir := t.TempDir()
old := writeFile(t, dir, "old-name.md", markdownTitledFromFilename())
writeFile(t, dir, "other.md", markdownTitledFromFilename()+"\nOther.\n")
full := filenameTitleConfig(server, filepath.Join(dir, "*.md"))
require.NoError(t, Run(context.Background(), full))
id := pageIDTitled(t, server, "Old Name")
require.NoError(t, os.Remove(old))
writeFile(t, dir, "copy.md", markdownTitledFromFilename())
sparse := full
sparse.Tracking.Partial = true
require.NoError(t, Run(context.Background(), sparse))
assert.Equal(t, "Old Name", server.Page(id).Title, "the page of the file not checked out keeps its title")
assert.Equal(t, 1, countPagesTitled(t, server, "Copy"))
entry, ok := tracked(t, server, old)
require.True(t, ok, "old-name.md stays tracked for the owning run")
assert.Equal(t, id, entry.PageID)
}
// TestPartialRunForgetsAReportedFileOnlyItTracked: a file only partial runs
// ever published is recorded under its own path, which no run publishing a
// whole pattern covers. Reported once it is deleted, its entry goes, as in a
// full run, instead of being reported by every partial run naming it.
func TestPartialRunForgetsAReportedFileOnlyItTracked(t *testing.T) {
server, full, dir := partialFixture(t)
d := writeFile(t, dir, "d.md", markdownWithTitle("Page d"))
require.NoError(t, Run(context.Background(), partialOf(full, dir, "{a,d}.md")))
entry, ok := tracked(t, server, d)
require.True(t, ok)
assert.Equal(t, manifest.Key(d), entry.Glob, "recorded under its own path")
require.NoError(t, os.Remove(d))
require.NoError(t, Run(context.Background(), partialOf(full, dir, "{b,d}.md")))
_, ok = tracked(t, server, d)
assert.False(t, ok, "reported and forgotten")
}
// TestPartialRunGivenTheOwningPatternRecordsANewFileUnderIt: on a sparse
// checkout given the owning pattern, a new file is recorded under that
// pattern, so the next such run, whose checkout lacks it, leaves it to the
// owning run instead of reporting it deleted and forgetting it.
func TestPartialRunGivenTheOwningPatternRecordsANewFileUnderIt(t *testing.T) {
server, full, dir := partialFixture(t)
for _, name := range []string{"a.md", "b.md", "c.md"} {
require.NoError(t, os.Remove(filepath.Join(dir, name)))
}
d := writeFile(t, dir, "d.md", markdownWithTitle("Page d"))
require.NoError(t, Run(context.Background(), partialOf(full, dir, "*.md")))
entry, ok := tracked(t, server, d)
require.True(t, ok)
assert.Equal(t, manifest.Key(full.Files), entry.Glob)
require.NoError(t, os.Remove(d))
writeFile(t, dir, "e.md", markdownWithTitle("Page e"))
var out strings.Builder
sparse := partialOf(full, dir, "*.md")
sparse.Report.OutputFormat = report.FormatGitHub
sparse.Output = &out
require.NoError(t, Run(context.Background(), sparse))
assert.NotContains(t, out.String(), "::warning", "d.md is not checked out, not deleted")
_, ok = tracked(t, server, d)
assert.True(t, ok, "d.md stays tracked for the owning run")
}
// TestFullRunCoversAFileOnlyAPartialRunTracked: a file a partial run added,
// recorded under its own path, and deleted before the full run published it is
// the full run's to deal with once its pattern matches it; otherwise no run
// would, and its page would stay in Confluence untracked.
func TestFullRunCoversAFileOnlyAPartialRunTracked(t *testing.T) {
server, full, dir := partialFixture(t)
d := writeFile(t, dir, "d.md", markdownWithTitle("Page d"))
require.NoError(t, Run(context.Background(), partialOf(full, dir, "{a,d}.md")))
entry, ok := tracked(t, server, d)
require.True(t, ok)
require.Equal(t, manifest.Key(d), entry.Glob)
dID := pageIDTitled(t, server, "Page d")
require.NoError(t, os.Remove(d))
owner := full
owner.Tracking.OnOrphan = report.OnOrphanDelete
require.NoError(t, Run(context.Background(), owner))
assert.True(t, server.Page(dID).Trashed, "the full run found d.md deleted")
_, ok = tracked(t, server, d)
assert.False(t, ok)
}