Skip to content

Commit

Permalink
Cleanup code: WIP 2
Browse files Browse the repository at this point in the history
  • Loading branch information
evg4b committed Jun 3, 2023
1 parent f2c462d commit 1e8d2af
Show file tree
Hide file tree
Showing 10 changed files with 23 additions and 21 deletions.
2 changes: 1 addition & 1 deletion internal/config/config_test.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package config_test

import (
"github.com/evg4b/uncors/testing/testconstants"
"testing"

"github.com/evg4b/uncors/internal/config"
"github.com/evg4b/uncors/testing/testconstants"
"github.com/evg4b/uncors/testing/testutils"
"github.com/evg4b/uncors/testing/testutils/params"
"github.com/spf13/viper"
Expand Down
10 changes: 5 additions & 5 deletions internal/config/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ package config_test

import (
"testing"
"github.com/evg4b/uncors/testing/testconstants"

"github.com/evg4b/uncors/internal/config"
"github.com/evg4b/uncors/testing/testconstants"
"github.com/stretchr/testify/assert"
)

Expand Down Expand Up @@ -42,7 +42,7 @@ func TestNormaliseMappings(t *testing.T) {
{
name: "correctly set https port",
mappings: []config.Mapping{
{From: "https://localhost", To: "https://github.com"},
{From: testconstants.HTTPSLocalhost, To: "https://github.com"},
},
expected: []config.Mapping{
{From: "https://localhost:3001", To: "https://github.com"},
Expand Down Expand Up @@ -98,7 +98,7 @@ func TestNormaliseMappings(t *testing.T) {
},
expected: []config.Mapping{
{From: testconstants.HTTPLocalhost, To: "github.com"},
{From: "https://localhost", To: "github.com"},
{From: testconstants.HTTPSLocalhost, To: "github.com"},
},
useHTTPS: true,
},
Expand All @@ -115,10 +115,10 @@ func TestNormaliseMappings(t *testing.T) {
{
name: "correctly set https port",
mappings: []config.Mapping{
{From: "https://localhost", To: "https://github.com"},
{From: testconstants.HTTPSLocalhost, To: "https://github.com"},
},
expected: []config.Mapping{
{From: "https://localhost", To: "https://github.com"},
{From: testconstants.HTTPSLocalhost, To: "https://github.com"},
},
useHTTPS: true,
},
Expand Down
2 changes: 1 addition & 1 deletion internal/config/mapping_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ package config_test

import (
"testing"
"github.com/evg4b/uncors/testing/testconstants"

"github.com/evg4b/uncors/internal/config"
"github.com/evg4b/uncors/testing/testconstants"
"github.com/evg4b/uncors/testing/testutils"
"github.com/spf13/viper"
"github.com/stretchr/testify/assert"
Expand Down
3 changes: 1 addition & 2 deletions internal/config/mappings.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ type Mappings []Mapping
func (mappings Mappings) String() string {
var builder strings.Builder

groups := lo.GroupBy(mappings, extractHost)
for _, group := range groups {
for _, group := range lo.GroupBy(mappings, extractHost) {
for _, mapping := range group {
builder.WriteString(sfmt.Sprintf("%s => %s\n", mapping.From, mapping.To))
}
Expand Down
4 changes: 2 additions & 2 deletions internal/config/mappings_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func TestMappings(t *testing.T) {
name: "http and https mappings",
mappings: config.Mappings{
{From: testconstants.HTTPLocalhost, To: "https://github.com"},
{From: "https://localhost", To: "https://github.com"},
{From: testconstants.HTTPSLocalhost, To: "https://github.com"},
},
expected: []string{
"https://localhost => https://github.com",
Expand Down Expand Up @@ -77,7 +77,7 @@ func TestMappings(t *testing.T) {
},
},
},
{From: "https://localhost", To: "https://github.com"},
{From: testconstants.HTTPSLocalhost, To: "https://github.com"},
},
expected: []string{
"https://localhost => https://github.com",
Expand Down
4 changes: 1 addition & 3 deletions internal/handler/uncors_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ var (
mock3Body = `{"mock": "mock number 3"}`
mock4Body = `{"mock": "mock number 4"}`

localhostSecure = "https://localhost"

backgroundPng = "background.png"
iconsSvg = "icons.svg"
indexJS = "index.js"
Expand Down Expand Up @@ -57,7 +55,7 @@ func TestUncorsRequestHandler(t *testing.T) {
mappings := []config.Mapping{
{
From: testconstants.HTTPLocalhost,
To: localhostSecure,
To: testconstants.HTTPSLocalhost,
Statics: []config.StaticDirectory{
{Dir: "/assets", Path: "/cc/", Index: indexHTML},
{Dir: "/assets", Path: "/pnp/", Index: "index.php"},
Expand Down
2 changes: 1 addition & 1 deletion internal/helpers/closer_test.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package helpers_test

import (
"github.com/evg4b/uncors/testing/testconstants"
"testing"

"github.com/evg4b/uncors/internal/helpers"
"github.com/evg4b/uncors/testing/mocks"
"github.com/evg4b/uncors/testing/testconstants"
"github.com/stretchr/testify/assert"
)

Expand Down
4 changes: 2 additions & 2 deletions internal/urlreplacer/replacer_test.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package urlreplacer_test

import (
"github.com/evg4b/uncors/testing/testconstants"
"testing"

"github.com/evg4b/uncors/internal/urlreplacer"
"github.com/evg4b/uncors/testing/testconstants"
"github.com/evg4b/uncors/testing/testutils"
"github.com/stretchr/testify/assert"
)
Expand Down Expand Up @@ -232,7 +232,7 @@ var isSecureTestCases = []struct {
},
{
name: "url with https scheme",
url: "https://localhost",
url: testconstants.HTTPSLocalhost,
expected: true,
},
}
Expand Down
7 changes: 3 additions & 4 deletions testing/testconstants/constants.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
package testconstants

var (
SourceHost1 = "host1"
SourceHost2 = "host2"
SourceHost3 = "host3"
HTTPLocalhost = "http://localhost"
SourceHost1 = "host1"
SourceHost2 = "host2"
SourceHost3 = "host3"
)

var (
Expand Down
6 changes: 6 additions & 0 deletions testing/testconstants/hosts.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package testconstants

var (
HTTPLocalhost = "http://localhost"
HTTPSLocalhost = "https://localhost"
)

0 comments on commit 1e8d2af

Please sign in to comment.