fixed typo which caused file reading error

This commit is contained in:
Pavel 2019-11-20 14:53:07 +03:00
parent 87b694bc08
commit b8be21b7c3
2 changed files with 24 additions and 3 deletions

View File

@ -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")
}

View File

@ -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))
}