2020-10-08 09:42:20 +08:00
|
|
|
package stat
|
|
|
|
|
|
|
|
import (
|
2024-04-05 00:13:42 +08:00
|
|
|
"errors"
|
2020-10-08 09:42:20 +08:00
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
"gopkg.in/h2non/gock.v1"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestRemoteWriter(t *testing.T) {
|
|
|
|
defer gock.Off()
|
|
|
|
|
|
|
|
gock.New("http://foo.com").Reply(200).BodyString("foo")
|
|
|
|
writer := NewRemoteWriter("http://foo.com")
|
|
|
|
err := writer.Write(&StatReport{
|
|
|
|
Name: "bar",
|
|
|
|
})
|
|
|
|
assert.Nil(t, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestRemoteWriterFail(t *testing.T) {
|
|
|
|
defer gock.Off()
|
|
|
|
|
|
|
|
gock.New("http://foo.com").Reply(503).BodyString("foo")
|
|
|
|
writer := NewRemoteWriter("http://foo.com")
|
|
|
|
err := writer.Write(&StatReport{
|
|
|
|
Name: "bar",
|
|
|
|
})
|
|
|
|
assert.NotNil(t, err)
|
|
|
|
}
|
2024-04-05 00:13:42 +08:00
|
|
|
|
|
|
|
func TestRemoteWriterError(t *testing.T) {
|
|
|
|
defer gock.Off()
|
|
|
|
|
|
|
|
gock.New("http://foo.com").ReplyError(errors.New("foo"))
|
|
|
|
writer := NewRemoteWriter("http://foo.com")
|
|
|
|
err := writer.Write(&StatReport{
|
|
|
|
Name: "bar",
|
|
|
|
})
|
|
|
|
assert.NotNil(t, err)
|
|
|
|
}
|