Codebase list golang-github-dcso-fluxline / 1a63084
Merge pull request #3 from philippreston/master Override Hostname Sascha Steinbiss authored 4 years ago GitHub committed 4 years ago
2 changed file(s) with 32 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
159159 }
160160 return a
161161 }
162
163 // NewEncoder creates a new encoder that writes to the given io.Writer with
164 // 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 }
9090 }
9191 }
9292
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
93115 func TestEncoderTypeFail(t *testing.T) {
94116 var b bytes.Buffer
95117