Skip to content

Commit

Permalink
Merge pull request #428 from elisasre/feat/codecov
Browse files Browse the repository at this point in the history
Add codecov requirements
  • Loading branch information
heppu authored Nov 5, 2024
2 parents bf8ce69 + 39636b0 commit fca1091
Show file tree
Hide file tree
Showing 4 changed files with 127 additions and 1 deletion.
13 changes: 13 additions & 0 deletions codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
coverage:
precision: 2
round: down

status:
project:
default:
target: 80%
threshold: 1%
patch:
default:
target: 50%
threshold: 2%
2 changes: 1 addition & 1 deletion v2/httputil/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
func IsHTTPS(r *http.Request) bool {
const protoHTTPS = "https"
switch {
case r.URL.Scheme == protoHTTPS:
case r.URL != nil && r.URL.Scheme == protoHTTPS:
return true
case r.TLS != nil:
return true
Expand Down
50 changes: 50 additions & 0 deletions v2/httputil/util_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package httputil

import (
"crypto/tls"
"net/http"
"net/url"
"testing"

"github.com/stretchr/testify/require"
)

func TestIsHTTPS(t *testing.T) {
tests := []struct {
name string
r *http.Request
expected bool
}{
{
name: "HTTPS scheme",
r: &http.Request{URL: &url.URL{Scheme: "https"}},
expected: true,
},
{
name: "is TLS",
r: &http.Request{TLS: &tls.ConnectionState{}},
expected: true,
},
{
name: "HTTPS proto",
r: &http.Request{Proto: "HTTPS/1.1"},
expected: true,
},
{
name: "X-Forwarded-Proto",
r: &http.Request{Header: http.Header{"X-Forwarded-Proto": []string{"https"}}},
expected: true,
},
{
name: "not HTTPS",
r: &http.Request{},
expected: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got := IsHTTPS(tt.r)
require.Equal(t, tt.expected, got)
})
}
}
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 fca1091

Please sign in to comment.