mirror of
https://github.com/mariocandela/beelzebub.git
synced 2025-07-01 18:47:26 -04:00
72 lines
1.6 KiB
Go
72 lines
1.6 KiB
Go
package plugins
|
|
|
|
import (
|
|
"github.com/go-resty/resty/v2"
|
|
"github.com/jarcoal/httpmock"
|
|
"github.com/mariocandela/beelzebub/v3/tracer"
|
|
"github.com/stretchr/testify/assert"
|
|
"net/http"
|
|
"testing"
|
|
)
|
|
|
|
func TestBuildSendEventFailValidation(t *testing.T) {
|
|
beelzebubCloud := InitBeelzebubCloud("", "")
|
|
|
|
_, err := beelzebubCloud.SendEvent(tracer.Event{})
|
|
|
|
assert.Equal(t, "authToken is empty", err.Error())
|
|
}
|
|
|
|
func TestBuildSendEventWithResults(t *testing.T) {
|
|
client := resty.New()
|
|
httpmock.ActivateNonDefault(client.GetClient())
|
|
defer httpmock.DeactivateAndReset()
|
|
|
|
uri := "localhost:8081/events"
|
|
|
|
// Given
|
|
httpmock.RegisterResponder("POST", uri,
|
|
func(req *http.Request) (*http.Response, error) {
|
|
resp, err := httpmock.NewJsonResponse(200, &tracer.Event{})
|
|
if err != nil {
|
|
return httpmock.NewStringResponse(500, ""), nil
|
|
}
|
|
return resp, nil
|
|
},
|
|
)
|
|
|
|
beelzebubCloud := InitBeelzebubCloud(uri, "sdjdnklfjndslkjanfk")
|
|
beelzebubCloud.client = client
|
|
|
|
//When
|
|
result, err := beelzebubCloud.SendEvent(tracer.Event{})
|
|
|
|
//Then
|
|
assert.Equal(t, true, result)
|
|
assert.Nil(t, err)
|
|
}
|
|
|
|
func TestBuildSendEventErro(t *testing.T) {
|
|
client := resty.New()
|
|
httpmock.ActivateNonDefault(client.GetClient())
|
|
defer httpmock.DeactivateAndReset()
|
|
|
|
uri := "localhost:8081/events"
|
|
|
|
// Given
|
|
httpmock.RegisterResponder("POST", uri,
|
|
func(req *http.Request) (*http.Response, error) {
|
|
return httpmock.NewStringResponse(500, ""), nil
|
|
},
|
|
)
|
|
|
|
beelzebubCloud := InitBeelzebubCloud(uri, "sdjdnklfjndslkjanfk")
|
|
beelzebubCloud.client = client
|
|
|
|
//When
|
|
result, _ := beelzebubCloud.SendEvent(tracer.Event{})
|
|
|
|
//Then
|
|
assert.Equal(t, false, result)
|
|
}
|