github.com/lingyao2333/mo-zero@v1.4.1/core/stat/remotewriter_test.go (about)

     1  package stat
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/stretchr/testify/assert"
     7  	"gopkg.in/h2non/gock.v1"
     8  )
     9  
    10  func TestRemoteWriter(t *testing.T) {
    11  	defer gock.Off()
    12  
    13  	gock.New("http://foo.com").Reply(200).BodyString("foo")
    14  	writer := NewRemoteWriter("http://foo.com")
    15  	err := writer.Write(&StatReport{
    16  		Name: "bar",
    17  	})
    18  	assert.Nil(t, err)
    19  }
    20  
    21  func TestRemoteWriterFail(t *testing.T) {
    22  	defer gock.Off()
    23  
    24  	gock.New("http://foo.com").Reply(503).BodyString("foo")
    25  	writer := NewRemoteWriter("http://foo.com")
    26  	err := writer.Write(&StatReport{
    27  		Name: "bar",
    28  	})
    29  	assert.NotNil(t, err)
    30  }