-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add failing test case with flate.Reader * fix local byteReader implementation -- fixes #6 * ReadByte() : if a byte is read, store the error, and returned the byte with no error * if an error is stored, return it (from ReadByte() or Read()) * ignore error in ReadByte if reader returns 1 byte following discussion on PR #7 * fix typo Co-authored-by: Agniva De Sarker <agnivade@yahoo.co.in>
- Loading branch information
Showing
2 changed files
with
57 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package validator | ||
|
||
import ( | ||
"bytes" | ||
"compress/flate" | ||
"io" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
// flateIt takes and input string, compresses it using flate, and returns a flate.Reader() of the compressed content | ||
func flateIt(t *testing.T, input string) io.Reader { | ||
t.Helper() | ||
|
||
var zipped bytes.Buffer | ||
w, err := flate.NewWriter(&zipped, flate.DefaultCompression) | ||
require.NoError(t, err) | ||
|
||
_, err = w.Write([]byte(input)) | ||
require.NoError(t, err) | ||
|
||
err = w.Close() | ||
require.NoError(t, err) | ||
|
||
return flate.NewReader(&zipped) | ||
} | ||
|
||
func TestValidateZippedReader(t *testing.T) { | ||
// wrap an innocuous "<foo></foo>" XML payload in a flate.Reader : | ||
zipped := flateIt(t, `<foo></foo>`) | ||
|
||
// Validate should not trigger an error on that Reader : | ||
err := Validate(zipped) | ||
assert.NoError(t, err, "Should not error on a valid XML document") | ||
|
||
// an invalid document should still error : | ||
zipped = flateIt(t, `<x::Root/>`) | ||
|
||
err = Validate(zipped) | ||
assert.Error(t, err, "Should error on an invalid XML document") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters