Skip to content

Commit

Permalink
Added tests fro normalise helper
Browse files Browse the repository at this point in the history
  • Loading branch information
evg4b committed May 8, 2023
1 parent 5d255c2 commit 501e0fa
Showing 1 changed file with 53 additions and 0 deletions.
53 changes: 53 additions & 0 deletions internal/helpers/http_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package helpers_test

import (
"crypto/tls"

Check failure on line 4 in internal/helpers/http_test.go

View workflow job for this annotation

GitHub Actions / build

File is not `goimports`-ed (goimports)
"github.com/evg4b/uncors/internal/helpers"
"github.com/evg4b/uncors/pkg/urlx"
"github.com/evg4b/uncors/testing/testutils"
"github.com/stretchr/testify/assert"
"net/http"
"testing"
)

func TestNormaliseRequest(t *testing.T) {
var url, err = urlx.Parse("http://localhost")
testutils.CheckNoError(t, err)

t.Run("set correct scheme", func(t *testing.T) {
t.Run("http", func(t *testing.T) {
var request = &http.Request{
URL: url,
Host: "localhost",
}

helpers.NormaliseRequest(request)

assert.Equal(t, request.URL.Scheme, "http")
})

t.Run("https", func(t *testing.T) {
var request = &http.Request{
URL: url,
TLS: &tls.ConnectionState{},
Host: "localhost",
}

helpers.NormaliseRequest(request)

assert.Equal(t, request.URL.Scheme, "https")
})
})

t.Run("fill url.host", func(t *testing.T) {
var request = &http.Request{
URL: url,
TLS: &tls.ConnectionState{},
Host: "localhost",
}

helpers.NormaliseRequest(request)

assert.Equal(t, request.URL.Host, "localhost")
})
}

0 comments on commit 501e0fa

Please sign in to comment.