Update upstream source from tag 'upstream/0.0_git20190516.1c6f5a3'
Update to upstream version '0.0~git20190516.1c6f5a3'
with Debian dir 1e6d0d7146fbf753bef02eaeebece658f465bf03
Sascha Steinbiss
3 years ago
159 | 159 |
}
|
160 | 160 |
return a
|
161 | 161 |
}
|
|
162 |
|
|
163 |
// NewEncoderWithHostname creates a new encoder that writes to the given
|
|
164 |
// io.Writer with an overridden hostname
|
|
165 |
func NewEncoderWithHostname(w io.Writer, host string) *Encoder {
|
|
166 |
a := &Encoder{
|
|
167 |
host: host,
|
|
168 |
Writer: w,
|
|
169 |
}
|
|
170 |
return a
|
|
171 |
}
|
90 | 90 |
}
|
91 | 91 |
}
|
92 | 92 |
|
|
93 |
func TestEncoderEncoderWithHostname(t *testing.T) {
|
|
94 |
var b bytes.Buffer
|
|
95 |
|
|
96 |
ile := NewEncoderWithHostname(&b, "testhost")
|
|
97 |
tags := make(map[string]string)
|
|
98 |
tags["foo"] = "bar"
|
|
99 |
tags["baaz gogo"] = "gu,gu"
|
|
100 |
err := ile.Encode("mytool", testStruct, tags)
|
|
101 |
if err != nil {
|
|
102 |
t.Fatal(err)
|
|
103 |
}
|
|
104 |
|
|
105 |
out := b.String()
|
|
106 |
if len(out) == 0 {
|
|
107 |
t.Fatalf("unexpected result length: %d == 0", len(out))
|
|
108 |
}
|
|
109 |
|
|
110 |
if match, _ := regexp.Match(`^mytool,host=testhost,baaz\\ gogo=gu\\,gu,foo=bar testval=1i,testvalue=2i,testvalue2=-3i,testvalue3=\"foobar\\\"baz\",testvaluebool=false,testvalueflt32=3.1415927,testvalueflt64=1.29e-24,testvaluetime=`, []byte(out)); !match {
|
|
111 |
t.Fatalf("unexpected match content: %s", out)
|
|
112 |
}
|
|
113 |
}
|
|
114 |
|
93 | 115 |
func TestEncoderTypeFail(t *testing.T) {
|
94 | 116 |
var b bytes.Buffer
|
95 | 117 |
|