Skip to content

Commit

Permalink
Added tests for Make replacer method
Browse files Browse the repository at this point in the history
  • Loading branch information
evg4b committed Oct 14, 2022
1 parent c96105b commit bb59aad
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions internal/urlreplacer/factory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"testing"

"github.com/evg4b/uncors/internal/urlreplacer"
"github.com/evg4b/uncors/pkg/urlx"
"github.com/evg4b/uncors/testing/testutils"
"github.com/stretchr/testify/assert"
)

Expand Down Expand Up @@ -49,3 +51,48 @@ func TestNewUrlReplacerFactory(t *testing.T) {
assert.NoError(t, err)
})
}

func TestFactoryMake(t *testing.T) {
factory, err := urlreplacer.NewURLReplacerFactory(map[string]string{
"http://server1.com": "https://mappedserver1.com",
"https://server2.com": "https://mappedserver2.com",
})
testutils.CheckNoError(t, err)

tests := []struct {
name string
url string
err string
}{
{
name: "mapped http server",
url: "http://server1.com",
},
{
name: "mapped https server",
url: "https://server2.com",
},
{
name: "unknown server",
url: "https://server3.com",
err: "mapping not found",
},
}
for _, testCase := range tests {
t.Run(testCase.name, func(t *testing.T) {
parseURL, err := urlx.Parse(testCase.url)
testutils.CheckNoError(t, err)

got, got1, err := factory.Make(parseURL)
if len(testCase.err) > 0 {
assert.Nil(t, got1)
assert.Nil(t, got)
assert.EqualError(t, err, testCase.err)
} else {
assert.NotNil(t, got1)
assert.NotNil(t, got)
assert.NoError(t, err)
}
})
}
}

0 comments on commit bb59aad

Please sign in to comment.