1515package journal
1616
1717import (
18+ "fmt"
19+ "io/ioutil"
20+ "strconv"
21+ "strings"
1822 "testing"
1923)
2024
@@ -40,3 +44,58 @@ func TestValidaVarName(t *testing.T) {
4044 }
4145 }
4246}
47+
48+ func TestJournalSend (t * testing.T ) {
49+ // an always-too-big value (hopefully)
50+ hugeValue := 1234567890
51+
52+ // a value slightly larger than default limit,
53+ // see `SO_SNDBUF` in socket(7)
54+ largeValue := hugeValue
55+ if wmem , err := ioutil .ReadFile ("/proc/sys/net/core/wmem_default" ); err == nil {
56+ wmemStr := strings .TrimSpace (string (wmem ))
57+ if v , err := strconv .Atoi (wmemStr ); err == nil {
58+ largeValue = v + 1
59+ }
60+ }
61+ // See https://github.com/coreos/go-systemd/pull/221#issuecomment-276727718
62+ _ = largeValue
63+
64+ // small messages should go over normal data,
65+ // larger ones over temporary file with fd in ancillary data
66+ testValues := []struct {
67+ label string
68+ len int
69+ }{
70+ {
71+ "empty message" ,
72+ 0 ,
73+ },
74+ {
75+ "small message" ,
76+ 5 ,
77+ },
78+ /* See https://github.com/coreos/go-systemd/pull/221#issuecomment-276727718
79+ {
80+ "large message",
81+ largeValue,
82+ },
83+ {
84+ "huge message",
85+ hugeValue,
86+ },
87+ */
88+ }
89+
90+ for i , tt := range testValues {
91+ t .Logf ("journal send test #%v - %s (len=%d)" , i , tt .label , tt .len )
92+ largeVars := map [string ]string {
93+ "KEY" : string (make ([]byte , tt .len )),
94+ }
95+
96+ err := Send (fmt .Sprintf ("go-systemd test #%v - %s" , i , tt .label ), PriCrit , largeVars )
97+ if err != nil {
98+ t .Fatalf ("#%v: failed sending %s: %s" , i , tt .label , err )
99+ }
100+ }
101+ }
0 commit comments