mirror of
https://github.com/retailcrm/mg-transport-core.git
synced 2025-03-14 08:36:10 +03:00
fix lint
This commit is contained in:
parent
49e73247eb
commit
662521ac60
@ -140,7 +140,7 @@ linters-settings:
|
||||
default-signifies-exhaustive: false
|
||||
funlen:
|
||||
lines: 65
|
||||
statements: 40
|
||||
statements: 50
|
||||
gocognit:
|
||||
min-complexity: 25
|
||||
gocyclo:
|
||||
|
@ -89,7 +89,7 @@ func MustMapValue(data interface{}, path string) interface{} {
|
||||
|
||||
// convertKeyToKind converts a string to the given kind.
|
||||
func convertKeyToKind(part string, kind reflect.Kind) (interface{}, error) {
|
||||
switch kind {
|
||||
switch kind { //nolint:exhaustive
|
||||
case reflect.String:
|
||||
return part, nil
|
||||
case reflect.Bool:
|
||||
@ -97,13 +97,13 @@ func convertKeyToKind(part string, kind reflect.Kind) (interface{}, error) {
|
||||
case reflect.Int:
|
||||
return strconv.Atoi(part)
|
||||
case reflect.Int8:
|
||||
val, err := strconv.Atoi(part)
|
||||
val, err := strconv.ParseInt(part, 10, 8)
|
||||
return int8(val), err
|
||||
case reflect.Int16:
|
||||
val, err := strconv.Atoi(part)
|
||||
val, err := strconv.ParseInt(part, 10, 16)
|
||||
return int16(val), err
|
||||
case reflect.Int32:
|
||||
val, err := strconv.Atoi(part)
|
||||
val, err := strconv.ParseInt(part, 10, 32)
|
||||
return int32(val), err
|
||||
case reflect.Int64:
|
||||
val, err := strconv.ParseInt(part, 10, 64)
|
||||
|
@ -1,8 +1,11 @@
|
||||
package testutil
|
||||
|
||||
import (
|
||||
"github.com/stretchr/testify/assert"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestMapValue_DifferentKeyTypes(t *testing.T) {
|
||||
@ -39,7 +42,7 @@ func TestMapValue_DifferentKeyTypes(t *testing.T) {
|
||||
|
||||
func TestMapValue_ErrorUnsupportedKeyType(t *testing.T) {
|
||||
_, err := MapValue(map[complex64]interface{}{}, "key")
|
||||
assert.Error(t, err)
|
||||
require.Error(t, err)
|
||||
assert.Equal(t, "unsupported reflect.Kind: complex64", err.Error())
|
||||
}
|
||||
|
||||
@ -74,27 +77,27 @@ func TestMapValue_Nested(t *testing.T) {
|
||||
|
||||
func TestMapValue_ErrorNotAMap(t *testing.T) {
|
||||
_, err := MapValue(1, "key")
|
||||
assert.Error(t, err)
|
||||
require.Error(t, err)
|
||||
assert.Equal(t, "value at path '' is not a map", err.Error())
|
||||
|
||||
_, err = MapValue(map[string]int{"key": 1}, "key.key2")
|
||||
assert.Error(t, err)
|
||||
require.Error(t, err)
|
||||
assert.Equal(t, "value at path 'key' is not a map", err.Error())
|
||||
}
|
||||
|
||||
func TestMapValue_ErrorKeyNotFound(t *testing.T) {
|
||||
_, err := MapValue(map[string]int{"key": 1}, "key2")
|
||||
assert.Error(t, err)
|
||||
require.Error(t, err)
|
||||
assert.Equal(t, "key 'key2' not found at path ''", err.Error())
|
||||
|
||||
_, err = MapValue(map[string]map[string]int{"key": {"key2": 1}}, "key.key3")
|
||||
assert.Error(t, err)
|
||||
require.Error(t, err)
|
||||
assert.Equal(t, "key 'key3' not found at path 'key'", err.Error())
|
||||
}
|
||||
|
||||
func TestMapValue_ErrorOutOfBounds(t *testing.T) {
|
||||
_, err := MapValue(map[string][]int{"key": {1}}, "key.1")
|
||||
assert.Error(t, err)
|
||||
require.Error(t, err)
|
||||
assert.Equal(t, "index 1 out of bounds for slice of length 1 at path 'key'", err.Error())
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user