mirror of
https://github.com/retailcrm/mg-transport-core.git
synced 2025-02-07 08:49:22 +03:00
fixed typo which caused file reading error
This commit is contained in:
parent
87b694bc08
commit
b8be21b7c3
@ -78,7 +78,7 @@ func (t *TranslationsExtractor) loadYAML(fileName string) (map[string]interface{
|
|||||||
if t.TranslationsBox != nil {
|
if t.TranslationsBox != nil {
|
||||||
return t.loadYAMLBox(fileName)
|
return t.loadYAMLBox(fileName)
|
||||||
} else if t.TranslationsPath != "" {
|
} else if t.TranslationsPath != "" {
|
||||||
return t.loadYAMLFile(fileName)
|
return t.loadYAMLFile(filepath.Join(t.TranslationsPath, fileName))
|
||||||
} else {
|
} else {
|
||||||
return map[string]interface{}{}, errors.New("nor box nor translations directory was provided")
|
return map[string]interface{}{}, errors.New("nor box nor translations directory was provided")
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,8 @@ import (
|
|||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
"reflect"
|
"reflect"
|
||||||
|
"sort"
|
||||||
|
"testing"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
@ -16,6 +18,20 @@ type TranslationsExtractorTest struct {
|
|||||||
extractor *TranslationsExtractor
|
extractor *TranslationsExtractor
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (t *TranslationsExtractorTest) getKeys(data map[string]interface{}) []string {
|
||||||
|
keys := make([]string, len(data))
|
||||||
|
|
||||||
|
i := 0
|
||||||
|
for k := range data {
|
||||||
|
keys[i] = k
|
||||||
|
i++
|
||||||
|
}
|
||||||
|
|
||||||
|
sort.Strings(keys)
|
||||||
|
|
||||||
|
return keys
|
||||||
|
}
|
||||||
|
|
||||||
func (t *TranslationsExtractorTest) SetupSuite() {
|
func (t *TranslationsExtractorTest) SetupSuite() {
|
||||||
translation := map[string]string{
|
translation := map[string]string{
|
||||||
"test": "first",
|
"test": "first",
|
||||||
@ -27,6 +43,7 @@ func (t *TranslationsExtractorTest) SetupSuite() {
|
|||||||
|
|
||||||
t.extractor = NewTranslationsExtractor("translate.{}.yml")
|
t.extractor = NewTranslationsExtractor("translate.{}.yml")
|
||||||
t.extractor.TranslationsPath = "/tmp"
|
t.extractor.TranslationsPath = "/tmp"
|
||||||
|
t.extractor.TranslationsBox = nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *TranslationsExtractorTest) Test_LoadLocale() {
|
func (t *TranslationsExtractorTest) Test_LoadLocale() {
|
||||||
@ -48,7 +65,7 @@ func (t *TranslationsExtractorTest) Test_GetMapKeys() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (t *TranslationsExtractorTest) Test_unmarshalToMap() {
|
func (t *TranslationsExtractorTest) Test_unmarshalToMap() {
|
||||||
translation := map[string]string{
|
translation := map[string]interface{}{
|
||||||
"test": "first",
|
"test": "first",
|
||||||
"another": "second",
|
"another": "second",
|
||||||
}
|
}
|
||||||
@ -56,5 +73,9 @@ func (t *TranslationsExtractorTest) Test_unmarshalToMap() {
|
|||||||
mapData, err := t.extractor.unmarshalToMap(data)
|
mapData, err := t.extractor.unmarshalToMap(data)
|
||||||
require.NoError(t.T(), err)
|
require.NoError(t.T(), err)
|
||||||
|
|
||||||
assert.True(t.T(), reflect.DeepEqual(translation, mapData))
|
assert.True(t.T(), reflect.DeepEqual(t.getKeys(translation), t.getKeys(mapData)))
|
||||||
|
}
|
||||||
|
|
||||||
|
func Test_TranslationExtractor(t *testing.T) {
|
||||||
|
suite.Run(t, new(TranslationsExtractorTest))
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user