Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add codecov requirements #428

Merged
merged 3 commits into from
Nov 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
}
Loading