Skip to content

Commit

Permalink
close files in fingerprint test: https://github.com/observIQ/opentele…
Browse files Browse the repository at this point in the history
  • Loading branch information
jsirianni committed May 26, 2021
1 parent 5bb4d7e commit ce38677
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions operator/builtin/input/file/fingerprint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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))
Expand Down

0 comments on commit ce38677

Please sign in to comment.