Skip to content

Commit

Permalink
Add tests for sentryutil
Browse files Browse the repository at this point in the history
  • Loading branch information
heppu committed Nov 5, 2024
1 parent 80d6bca commit 39636b0
Showing 1 changed file with 63 additions and 0 deletions.
63 changes: 63 additions & 0 deletions v2/sentryutil/sentry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@ import (
"bytes"
"context"
"fmt"
"net/http/httptest"
"os"
"strings"
"testing"

"github.com/getsentry/sentry-go"
"github.com/gin-gonic/gin"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

Expand Down Expand Up @@ -57,3 +60,63 @@ func TestRecoverWithContext(t *testing.T) {
})
}
}

func TestGinWrapper(t *testing.T) {
tests := []struct {
name string
fn func(*gin.RouterGroup, string, ...gin.HandlerFunc) gin.IRoutes
}{
{
name: "GET",
fn: GET,
},
{
name: "POST",
fn: POST,
},
{
name: "PUT",
fn: PUT,
},
{
name: "DELETE",
fn: DELETE,
},
{
name: "PATCH",
fn: PATCH,
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
r := gin.New()
gr := r.Group("/")
tt.fn(gr, tt.name, func(c *gin.Context) {
span := sentry.SpanFromContext(c.Request.Context())
assert.NotNil(t, span)
})

req := httptest.NewRequest(tt.name, "/", nil)
rr := httptest.NewRecorder()
r.ServeHTTP(rr, req)
})
}
}

func TestMakeSpan(t *testing.T) {
span := MakeSpan(context.Background(), 0)
assert.NotNil(t, span)
}

func TestMakeTransaction(t *testing.T) {
ctx, span, hub := MakeTransaction(context.Background(), "test")
assert.NotNil(t, ctx)
assert.NotNil(t, span)
assert.NotNil(t, hub)
}

func TestErrorDoesntPanic(t *testing.T) {
err := fmt.Errorf("test error")
Error(context.Background(), err)
}

0 comments on commit 39636b0

Please sign in to comment.