Skip to content

Commit

Permalink
Reafactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
evg4b committed Apr 29, 2023
1 parent c8ac00d commit bc0853b
Show file tree
Hide file tree
Showing 9 changed files with 21 additions and 20 deletions.
1 change: 1 addition & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ linters-settings:
- form
- to
- ok
- fs
presets:
- bugs
- comment
Expand Down
2 changes: 1 addition & 1 deletion internal/configuration/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func LoadConfiguration(viperInstance *viper.Viper, args []string) (*UncorsConfig
URLMappingHookFunc(),
))
if err := viperInstance.Unmarshal(configuration, configOption); err != nil {
return nil, fmt.Errorf("filed parsing configuraion: %w", err)
return nil, fmt.Errorf("filed parsing configuration: %w", err)
}

if err := readURLMapping(viperInstance, configuration); err != nil {
Expand Down
4 changes: 2 additions & 2 deletions internal/configuration/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ func TestLoadConfiguration(t *testing.T) {
{
name: "incorrect param type",
args: []string{
params.HttpPort, "xxx",
params.HTTPPort, "xxx",
},
expected: []string{
"filed parsing flags: invalid argument \"xxx\" for \"-p, --http-port\" flag: " +
Expand All @@ -216,7 +216,7 @@ func TestLoadConfiguration(t *testing.T) {
params.Config, "/incorrect-config.yaml",
},
expected: []string{
"filed parsing configuraion: 1 error(s) decoding:\n\n* cannot parse 'http-port' as int:" +
"filed parsing configuration: 1 error(s) decoding:\n\n* cannot parse 'http-port' as int:" +
" strconv.ParseInt: parsing \"xxx\": invalid syntax",
},
},
Expand Down
15 changes: 8 additions & 7 deletions internal/infrastructure/panic_test.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
//go:build release

package infrastructure
package infrastructure_test

import (
"errors"
"github.com/evg4b/uncors/internal/infrastructure"
"testing"

"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -31,20 +32,20 @@ func TestPanicInterceptor(t *testing.T) {
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
for _, testCast := range tests {
t.Run(testCast.name, func(t *testing.T) {
called := false

assert.NotPanics(t, func() {
defer PanicInterceptor(func(data any) {
defer infrastructure.PanicInterceptor(func(data any) {
called = true
assert.Equal(t, tt.panicData, data)
assert.Equal(t, testCast.panicData, data)
})

panic(tt.panicData)
panic(testCast.panicData)
})

assert.Equal(t, tt.shouldBeCalled, called)
assert.Equal(t, testCast.shouldBeCalled, called)
})
}
}
7 changes: 3 additions & 4 deletions internal/version/new_version_check_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"errors"
"github.com/evg4b/uncors/internal/version"
"io"
"io/ioutil"
"net/http"
"strings"
"testing"
Expand Down Expand Up @@ -68,7 +67,7 @@ func TestCheckNewVersion(t *testing.T) {
assert.NotPanics(t, func() {
version.CheckNewVersion(context.Background(), testCase.client, testCase.version)

outputData, err := ioutil.ReadAll(output)
outputData, err := io.ReadAll(output)
testutils.CheckNoError(t, err)

assert.Equal(t, testCase.expected, string(outputData))
Expand All @@ -84,7 +83,7 @@ func TestCheckNewVersion(t *testing.T) {

version.CheckNewVersion(context.Background(), httpClient, "0.0.4")

outputData, err := ioutil.ReadAll(output)
outputData, err := io.ReadAll(output)
testutils.CheckNoError(t, err)
expected := ` DEBUG Checking new version
INFO NEW VERSION IS Available!
Expand All @@ -101,7 +100,7 @@ func TestCheckNewVersion(t *testing.T) {

version.CheckNewVersion(context.Background(), httpClient, "0.0.7")

outputData, err := ioutil.ReadAll(output)
outputData, err := io.ReadAll(output)
testutils.CheckNoError(t, err)
expected := " DEBUG Checking new version\n DEBUG Version is up to date\n"
assert.Equal(t, expected, string(outputData))
Expand Down
2 changes: 1 addition & 1 deletion pkg/urlx/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ for [uncors](https://github.com/evg4b/uncors) project.

## License

`github.com/evg4b/uncors/pkg/urlx` is licensed under the [MIT License](./LICENSE).
`github.com/evg4b/uncors/pkg/urlx` is licensed under the [MIT License](LICENSE).
2 changes: 1 addition & 1 deletion pkg/urlx/urlx.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func defaultScheme(rawURL, scheme string) string {
var (
domainRegexp = regexp.MustCompile(`^([a-zA-Z0-9-_*]{1,63}\.)*([a-zA-Z0-9-*]{1,63})$`)
ipv4Regexp = regexp.MustCompile(`^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$`)
ipv6Regexp = regexp.MustCompile(`^\[[a-fA-F0-9:]+\]$`)
ipv6Regexp = regexp.MustCompile(`^\[[a-fA-F0-9:]+]$`)
)

func checkHost(host string) error {
Expand Down
6 changes: 3 additions & 3 deletions testing/testutils/certs.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,10 @@ func certSetup(t *testing.T) *Certs {
KeyUsage: x509.KeyUsageDigitalSignature,
}

certPrivKey, err := rsa.GenerateKey(rand.Reader, 4096)
certPrivateKey, err := rsa.GenerateKey(rand.Reader, 4096)
CheckNoError(t, err)

certBytes, err := x509.CreateCertificate(rand.Reader, cert, ca, &certPrivKey.PublicKey, caPrivateKey)
certBytes, err := x509.CreateCertificate(rand.Reader, cert, ca, &certPrivateKey.PublicKey, caPrivateKey)
CheckNoError(t, err)

certPEM := pem.EncodeToMemory(&pem.Block{
Expand All @@ -108,7 +108,7 @@ func certSetup(t *testing.T) *Certs {

privateKeyPEM := pem.EncodeToMemory(&pem.Block{
Type: "RSA PRIVATE KEY",
Bytes: x509.MarshalPKCS1PrivateKey(certPrivKey),
Bytes: x509.MarshalPKCS1PrivateKey(certPrivateKey),
})
CheckNoError(t, err)

Expand Down
2 changes: 1 addition & 1 deletion testing/testutils/params/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ package params
const Config = "--config"
const From = "--from"
const To = "--to"
const HttpPort = "--http-port"
const HTTPPort = "--http-port"

0 comments on commit bc0853b

Please sign in to comment.