Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
G
go-systemd
Manage
Activity
Members
Plan
Wiki
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Terraform modules
Analyze
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
CodeLinaro
le
go-systemd
Commits
e68eaeb1
Unverified
Commit
e68eaeb1
authored
8 years ago
by
Luca Bruno
Browse files
Options
Downloads
Patches
Plain Diff
sdjournal: add test for incorrect Read() length
parent
a5232356
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
sdjournal/journal_test.go
+55
-0
55 additions, 0 deletions
sdjournal/journal_test.go
with
55 additions
and
0 deletions
sdjournal/journal_test.go
+
55
−
0
View file @
e68eaeb1
...
...
@@ -16,11 +16,13 @@
package
sdjournal
import
(
"bytes"
"errors"
"fmt"
"io"
"io/ioutil"
"os"
"strings"
"testing"
"time"
...
...
@@ -228,3 +230,56 @@ func TestJournalGetEntry(t *testing.T) {
t
.
Fatalf
(
"Bad result for entry.Fields[
\"
MESSAGE
\"
]: got %s, want %s"
,
got
,
want
)
}
}
// Check for incorrect read into small buffers,
// see https://github.com/coreos/go-systemd/issues/172
func
TestJournalReaderSmallReadBuffer
(
t
*
testing
.
T
)
{
// Write a long entry ...
delim
:=
"%%%%%%"
longEntry
:=
strings
.
Repeat
(
"a"
,
256
)
matchField
:=
"TESTJOURNALREADERSMALLBUF"
matchValue
:=
fmt
.
Sprintf
(
"%d"
,
time
.
Now
()
.
UnixNano
())
r
,
err
:=
NewJournalReader
(
JournalReaderConfig
{
Since
:
time
.
Duration
(
-
15
)
*
time
.
Second
,
Matches
:
[]
Match
{
{
Field
:
matchField
,
Value
:
matchValue
,
},
},
})
if
err
!=
nil
{
t
.
Fatalf
(
"Error opening journal: %s"
,
err
)
}
if
r
==
nil
{
t
.
Fatal
(
"Got a nil reader"
)
}
defer
r
.
Close
()
want
:=
fmt
.
Sprintf
(
"%slongentry %s%s"
,
delim
,
longEntry
,
delim
)
err
=
journal
.
Send
(
want
,
journal
.
PriInfo
,
map
[
string
]
string
{
matchField
:
matchValue
})
if
err
!=
nil
{
t
.
Fatal
(
"Error writing to journal"
,
err
)
}
time
.
Sleep
(
time
.
Second
)
// ... and try to read it back piece by piece via a small buffer
finalBuff
:=
new
(
bytes
.
Buffer
)
var
e
error
for
c
:=
-
1
;
c
!=
0
&&
e
==
nil
;
{
smallBuf
:=
make
([]
byte
,
5
)
c
,
e
=
r
.
Read
(
smallBuf
)
if
c
>
len
(
smallBuf
)
{
t
.
Fatalf
(
"Got unexpected read length: %d vs %d"
,
c
,
len
(
smallBuf
))
}
_
,
_
=
finalBuff
.
Write
(
smallBuf
)
}
b
:=
finalBuff
.
String
()
got
:=
strings
.
Split
(
b
,
delim
)
if
len
(
got
)
!=
3
{
t
.
Fatalf
(
"Got unexpected entry %s"
,
b
)
}
if
got
[
1
]
!=
strings
.
Trim
(
want
,
delim
)
{
t
.
Fatalf
(
"Got unexpected message %s"
,
got
[
1
])
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment