diff --git a/operator/builtin/input/file/fingerprint_test.go b/operator/builtin/input/file/fingerprint_test.go index ebc39634e..9eadc357e 100644 --- a/operator/builtin/input/file/fingerprint_test.go +++ b/operator/builtin/input/file/fingerprint_test.go @@ -233,6 +233,8 @@ func TestFingerprintStartsWith_FromFile(t *testing.T) { fullFile, err := ioutil.TempFile(tempDir, "") require.NoError(t, err) + defer fullFile.Close() + _, err = fullFile.Write(content) require.NoError(t, err) @@ -241,14 +243,20 @@ func TestFingerprintStartsWith_FromFile(t *testing.T) { partialFile, err := ioutil.TempFile(tempDir, "") require.NoError(t, err) + defer partialFile.Close() + + // Write the first byte before comparing, since empty files will never match + _, err = partialFile.Write(content[:1]) + require.NoError(t, err) + content = content[1:] - // Write one byte at a time and validate that updated - // full fingerprint still starts with partial + // Write one byte at a time and validate that + // full fingerprint still starts with updated partial for i := range content { _, err = partialFile.Write(content[i:i]) require.NoError(t, err) - pff, err := operator.NewFingerprint(fullFile) + pff, err := operator.NewFingerprint(partialFile) require.NoError(t, err) require.True(t, fff.StartsWith(pff))