-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathechorelic_test.go
60 lines (52 loc) · 1.42 KB
/
echorelic_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package echorelic
import (
"net/http"
"net/http/httptest"
"testing"
"github.com/labstack/echo"
newrelic "github.com/newrelic/go-agent"
"github.com/stretchr/testify/suite"
)
type TestSuite struct {
suite.Suite
echoRelic *EchoRelic
e *echo.Echo
}
func (suite *TestSuite) SetupTest() {
echoRelic, err := New("test", "1234567890123456789012345678901234567890")
if err != nil {
suite.Fail("Failed to create new EchoRelic")
}
suite.echoRelic = echoRelic
e := echo.New()
e.GET("/", func(c echo.Context) error {
return c.String(http.StatusOK, "Hello, World!")
})
suite.e = e
}
func (suite *TestSuite) TestUseMiddleware() {
var t newrelic.Transaction
suite.e.Use(suite.echoRelic.Transaction)
req := httptest.NewRequest(echo.GET, "/", nil)
res := httptest.NewRecorder()
c := suite.e.NewContext(req, res)
txn := c.Get("newRelicTransaction")
suite.IsType(t, txn)
}
func (suite *TestSuite) TestBadConfig() {
_, err := New("test", "1234567890")
suite.Error(err, "Should error when a key is passed with an invalid length")
}
func (suite *TestSuite) TestShouldReturnNil() {
handlerFunc := suite.echoRelic.Transaction(func(c echo.Context) error {
return c.String(http.StatusOK, "Hello, World!")
})
req := httptest.NewRequest(echo.GET, "/", nil)
res := httptest.NewRecorder()
c := suite.e.NewContext(req, res)
err := handlerFunc(c)
suite.NoError(err)
}
func TestMethodSuite(t *testing.T) {
suite.Run(t, new(TestSuite))
}