Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 59 additions & 0 deletions journal/journal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
package journal

import (
"fmt"
"io/ioutil"
"strconv"
"strings"
"testing"
)

Expand All @@ -40,3 +44,58 @@ func TestValidaVarName(t *testing.T) {
}
}
}

func TestJournalSend(t *testing.T) {
// an always-too-big value (hopefully)
hugeValue := 1234567890

// a value slightly larger than default limit,
// see `SO_SNDBUF` in socket(7)
largeValue := hugeValue
if wmem, err := ioutil.ReadFile("/proc/sys/net/core/wmem_default"); err == nil {
wmemStr := strings.TrimSpace(string(wmem))
if v, err := strconv.Atoi(wmemStr); err == nil {
largeValue = v + 1
}
}
// See https://github.com/coreos/go-systemd/pull/221#issuecomment-276727718
_ = largeValue

// small messages should go over normal data,
// larger ones over temporary file with fd in ancillary data
testValues := []struct {
label string
len int
}{
{
"empty message",
0,
},
{
"small message",
5,
},
/* See https://github.com/coreos/go-systemd/pull/221#issuecomment-276727718
{
"large message",
largeValue,
},
{
"huge message",
hugeValue,
},
*/
}

for i, tt := range testValues {
t.Logf("journal send test #%v - %s (len=%d)", i, tt.label, tt.len)
largeVars := map[string]string{
"KEY": string(make([]byte, tt.len)),
}

err := Send(fmt.Sprintf("go-systemd test #%v - %s", i, tt.label), PriCrit, largeVars)
if err != nil {
t.Fatalf("#%v: failed sending %s: %s", i, tt.label, err)
}
}
}