Compare commits
2
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a10c588152 | ||
|
|
f68cc284ac |
@@ -189,8 +189,8 @@ func reportCheckProgress(progress <-chan mfer.CheckStatus, wg *sync.WaitGroup) {
|
|||||||
log.ProgressDone()
|
log.ProgressDone()
|
||||||
}
|
}
|
||||||
|
|
||||||
// countCheckFailures consumes check results, counting and logging
|
// countCheckFailures consumes check results, counting failures and logging
|
||||||
// failures, then closes done.
|
// each at error level so that --quiet still shows them, then closes done.
|
||||||
func countCheckFailures(
|
func countCheckFailures(
|
||||||
results <-chan mfer.Result, failures *int64, done chan<- struct{},
|
results <-chan mfer.Result, failures *int64, done chan<- struct{},
|
||||||
) {
|
) {
|
||||||
@@ -198,7 +198,7 @@ func countCheckFailures(
|
|||||||
if result.Status != mfer.StatusOK {
|
if result.Status != mfer.StatusOK {
|
||||||
*failures++
|
*failures++
|
||||||
|
|
||||||
log.Infof("%s: %s (%s)", result.Status, result.Path, result.Message)
|
log.Errorf("%s: %s (%s)", result.Status, result.Path, result.Message)
|
||||||
} else {
|
} else {
|
||||||
log.Verbosef("%s: %s", result.Status, result.Path)
|
log.Verbosef("%s: %s", result.Status, result.Path)
|
||||||
}
|
}
|
||||||
@@ -208,8 +208,8 @@ func countCheckFailures(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// findExtraFiles reports files present on disk but absent from the
|
// findExtraFiles reports files present on disk but absent from the
|
||||||
// manifest, and anything the search cannot read: each is a failure under
|
// manifest, and anything the search cannot read: each is a failure, logged
|
||||||
// --no-extra-files, otherwise a warning.
|
// at error level, under --no-extra-files, otherwise a warning.
|
||||||
func findExtraFiles(
|
func findExtraFiles(
|
||||||
ctx context.Context, cmd *cli.Command, chk *mfer.Checker, failures *int64,
|
ctx context.Context, cmd *cli.Command, chk *mfer.Checker, failures *int64,
|
||||||
) error {
|
) error {
|
||||||
@@ -221,7 +221,7 @@ func findExtraFiles(
|
|||||||
if cmd.Bool("no-extra-files") {
|
if cmd.Bool("no-extra-files") {
|
||||||
*failures++
|
*failures++
|
||||||
|
|
||||||
log.Infof("%s: %s (%s)", result.Status, result.Path, result.Message)
|
log.Errorf("%s: %s (%s)", result.Status, result.Path, result.Message)
|
||||||
} else {
|
} else {
|
||||||
log.Warnf("%s: %s (%s)", result.Status, result.Path, result.Message)
|
log.Warnf("%s: %s (%s)", result.Status, result.Path, result.Message)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -694,6 +694,33 @@ func TestCheckCommandWithSizeMismatch(t *testing.T) {
|
|||||||
"check should have failed for size mismatch")
|
"check should have failed for size mismatch")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TestCheckQuietShowsFailedFiles asserts that check -q prints nothing for a
|
||||||
|
// tree that passes and still names each file that fails: --quiet hides
|
||||||
|
// everything except errors, and a failed file is an error.
|
||||||
|
func TestCheckQuietShowsFailedFiles(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
|
fs := afero.NewMemMapFs()
|
||||||
|
require.NoError(t, fs.MkdirAll(testDir, 0o755))
|
||||||
|
writeTestFile(t, fs, testFile1, "hello world")
|
||||||
|
|
||||||
|
opts := testOpts([]string{testApp, cmdGenerate, "-q", "-o", testManifest, testDir}, fs)
|
||||||
|
require.Equal(t, 0, runCLI(opts), "generate failed: %s", testStderr(t, opts))
|
||||||
|
|
||||||
|
args := []string{testApp, cmdCheck, "-q", testFlagBase, testDir, testManifest}
|
||||||
|
|
||||||
|
opts = testOpts(args, fs)
|
||||||
|
require.Equal(t, 0, runCLI(opts), "stderr: %s", testStderr(t, opts))
|
||||||
|
assert.Empty(t, testStdout(t, opts))
|
||||||
|
assert.Empty(t, testStderr(t, opts))
|
||||||
|
|
||||||
|
writeTestFile(t, fs, testFile1, "HELLO WORLD")
|
||||||
|
|
||||||
|
opts = testOpts(args, fs)
|
||||||
|
assert.Equal(t, 1, runCLI(opts))
|
||||||
|
assert.Contains(t, testStderr(t, opts), "HASH_MISMATCH: file1.txt")
|
||||||
|
}
|
||||||
|
|
||||||
func TestBannerOutput(t *testing.T) {
|
func TestBannerOutput(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
@@ -926,8 +953,9 @@ func TestCheckWarnsAboutUnlistedFiles(t *testing.T) {
|
|||||||
assert.Equal(t, 1, exitCode, "stderr: %s", stderr)
|
assert.Equal(t, 1, exitCode, "stderr: %s", stderr)
|
||||||
assert.Contains(t, stderr, unlisted)
|
assert.Contains(t, stderr, unlisted)
|
||||||
|
|
||||||
exitCode, _ = check("-q", testFlagNoExtra)
|
exitCode, stderr = check("-q", testFlagNoExtra)
|
||||||
assert.Equal(t, 1, exitCode)
|
assert.Equal(t, 1, exitCode)
|
||||||
|
assert.Contains(t, stderr, unlisted)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user