Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
dms3
go-dms3-chunker
Commits
65d7a6e9
Commit
65d7a6e9
authored
Jan 21, 2020
by
Peter Rabbitson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Test all the things
parent
397f536c
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
57 additions
and
13 deletions
+57
-13
parse_test.go
parse_test.go
+57
-13
No files found.
parse_test.go
View file @
65d7a6e9
...
@@ -2,35 +2,79 @@ package chunk
...
@@ -2,35 +2,79 @@ package chunk
import
(
import
(
"bytes"
"bytes"
"fmt"
"testing"
"testing"
)
)
const
(
testTwoThirdsOfBlockPayloadLimit
=
2
*
(
float32
(
BlockPayloadLimit
)
/
float32
(
3
))
)
func
TestParseRabin
(
t
*
testing
.
T
)
{
func
TestParseRabin
(
t
*
testing
.
T
)
{
max
:=
1000
r
:=
bytes
.
NewReader
(
randBuf
(
t
,
1000
))
r
:=
bytes
.
NewReader
(
randBuf
(
t
,
max
))
chk1
:=
"rabin-18-25-32"
_
,
err
:=
FromString
(
r
,
"rabin-18-25-32"
)
chk2
:=
"rabin-15-23-31"
_
,
err
:=
parseRabinString
(
r
,
chk1
)
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Errorf
(
err
.
Error
())
t
.
Errorf
(
err
.
Error
())
}
}
_
,
err
=
parseRabinString
(
r
,
chk2
)
_
,
err
=
FromString
(
r
,
"rabin-15-23-31"
)
if
err
!=
ErrRabinMin
{
if
err
!=
ErrRabinMin
{
t
.
Fatalf
(
"Expected an 'ErrRabinMin' error, got: %#v"
,
err
)
t
.
Fatalf
(
"Expected an 'ErrRabinMin' error, got: %#v"
,
err
)
}
}
_
,
err
=
FromString
(
r
,
"rabin-20-20-21"
)
if
err
==
nil
||
err
.
Error
()
!=
"incorrect format: rabin-min must be smaller than rabin-avg"
{
t
.
Fatalf
(
"Expected an arg-out-of-order error, got: %#v"
,
err
)
}
_
,
err
=
FromString
(
r
,
"rabin-19-21-21"
)
if
err
==
nil
||
err
.
Error
()
!=
"incorrect format: rabin-avg must be smaller than rabin-max"
{
t
.
Fatalf
(
"Expected an arg-out-of-order error, got: %#v"
,
err
)
}
_
,
err
=
FromString
(
r
,
fmt
.
Sprintf
(
"rabin-19-21-%d"
,
BlockPayloadLimit
))
if
err
!=
nil
{
t
.
Fatalf
(
"Expected success, got: %#v"
,
err
)
}
_
,
err
=
FromString
(
r
,
fmt
.
Sprintf
(
"rabin-19-21-%d"
,
1
+
BlockPayloadLimit
))
if
err
!=
ErrSizeMax
{
t
.
Fatalf
(
"Expected 'ErrSizeMax', got: %#v"
,
err
)
}
_
,
err
=
FromString
(
r
,
fmt
.
Sprintf
(
"rabin-%.0f"
,
testTwoThirdsOfBlockPayloadLimit
))
if
err
!=
nil
{
t
.
Fatalf
(
"Expected success, got: %#v"
,
err
)
}
_
,
err
=
FromString
(
r
,
fmt
.
Sprintf
(
"rabin-%.0f"
,
1
+
testTwoThirdsOfBlockPayloadLimit
))
if
err
!=
ErrSizeMax
{
t
.
Fatalf
(
"Expected 'ErrSizeMax', got: %#v"
,
err
)
}
}
}
func
TestParseSize
(
t
*
testing
.
T
)
{
func
TestParseSize
(
t
*
testing
.
T
)
{
max
:=
1000
r
:=
bytes
.
NewReader
(
randBuf
(
t
,
1000
))
r
:=
bytes
.
NewReader
(
randBuf
(
t
,
max
))
size1
:=
"size-0"
_
,
err
:=
FromString
(
r
,
"size-0"
)
size2
:=
"size-32"
_
,
err
:=
FromString
(
r
,
size1
)
if
err
!=
ErrSize
{
if
err
!=
ErrSize
{
t
.
Fatalf
(
"Expected an 'ErrSize' error, got: %#v"
,
err
)
t
.
Fatalf
(
"Expected an 'ErrSize' error, got: %#v"
,
err
)
}
}
_
,
err
=
FromString
(
r
,
size2
)
_
,
err
=
FromString
(
r
,
"size-32"
)
if
err
!=
nil
{
t
.
Fatalf
(
"Expected success, got: %#v"
,
err
)
}
_
,
err
=
FromString
(
r
,
fmt
.
Sprintf
(
"size-%d"
,
BlockPayloadLimit
))
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Fatal
(
err
)
t
.
Fatalf
(
"Expected success, got: %#v"
,
err
)
}
_
,
err
=
FromString
(
r
,
fmt
.
Sprintf
(
"size-%d"
,
1
+
BlockPayloadLimit
))
if
err
!=
ErrSizeMax
{
t
.
Fatalf
(
"Expected 'ErrSizeMax', got: %#v"
,
err
)
}
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment