mirror of
https://github.com/retailcrm/mg-transport-core.git
synced 2025-01-31 05:41:41 +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 {
|
||||
return t.loadYAMLBox(fileName)
|
||||
} else if t.TranslationsPath != "" {
|
||||
return t.loadYAMLFile(fileName)
|
||||
return t.loadYAMLFile(filepath.Join(t.TranslationsPath, fileName))
|
||||
} else {
|
||||
return map[string]interface{}{}, errors.New("nor box nor translations directory was provided")
|
||||
}
|
||||
|
@ -4,6 +4,8 @@ import (
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"reflect"
|
||||
"sort"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
@ -16,6 +18,20 @@ type TranslationsExtractorTest struct {
|
||||
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() {
|
||||
translation := map[string]string{
|
||||
"test": "first",
|
||||
@ -27,6 +43,7 @@ func (t *TranslationsExtractorTest) SetupSuite() {
|
||||
|
||||
t.extractor = NewTranslationsExtractor("translate.{}.yml")
|
||||
t.extractor.TranslationsPath = "/tmp"
|
||||
t.extractor.TranslationsBox = nil
|
||||
}
|
||||
|
||||
func (t *TranslationsExtractorTest) Test_LoadLocale() {
|
||||
@ -48,7 +65,7 @@ func (t *TranslationsExtractorTest) Test_GetMapKeys() {
|
||||
}
|
||||
|
||||
func (t *TranslationsExtractorTest) Test_unmarshalToMap() {
|
||||
translation := map[string]string{
|
||||
translation := map[string]interface{}{
|
||||
"test": "first",
|
||||
"another": "second",
|
||||
}
|
||||
@ -56,5 +73,9 @@ func (t *TranslationsExtractorTest) Test_unmarshalToMap() {
|
||||
mapData, err := t.extractor.unmarshalToMap(data)
|
||||
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