Skip to content

Commit

Permalink
increase test coverage for file_loader
Browse files Browse the repository at this point in the history
  • Loading branch information
kkumar-gcc committed Nov 17, 2023
1 parent e271f12 commit 3c9b34b
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
14 changes: 12 additions & 2 deletions translation/file_loader_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package translation

import (
"os"
"testing"

"github.com/goravel/framework/support/file"
Expand All @@ -16,6 +17,9 @@ func TestFileLoaderTestSuite(t *testing.T) {
assert.Nil(t, file.Create("lang/en.json", `{"foo": "bar"}`))
assert.Nil(t, file.Create("lang/another/en.json", `{"foo": "backagebar", "baz": "backagesplash"}`))
assert.Nil(t, file.Create("lang/invalid/en.json", `{"foo": "bar",}`))
restrictedFilePath := "lang/restricted/en.json"
assert.Nil(t, file.Create(restrictedFilePath, `{"foo": "restricted"}`))
assert.Nil(t, os.Chmod(restrictedFilePath, 0000))
suite.Run(t, &FileLoaderTestSuite{})
assert.Nil(t, file.Remove("lang"))
}
Expand Down Expand Up @@ -44,6 +48,12 @@ func (f *FileLoaderTestSuite) TestLoad() {
f.NoError(err)
f.NotNil(translations)
f.Equal("backagebar", translations["en"]["foo"])

paths = []string{"./lang/restricted"}
loader = NewFileLoader(paths)
translations, err = loader.Load("*", "en")
f.Error(err)
f.Nil(translations)
}

func (f *FileLoaderTestSuite) TestLoadNonExistentFile() {
Expand All @@ -65,15 +75,15 @@ func (f *FileLoaderTestSuite) TestLoadInvalidJSON() {
f.Nil(translations)
}

func (f *FileLoaderTestSuite) TestMergeMaps() {
func TestMergeMaps(t *testing.T) {
dst := map[string]string{
"foo": "bar",
}
src := map[string]string{
"baz": "backage",
}
mergeMaps(dst, src)
f.Equal(map[string]string{
assert.Equal(t, map[string]string{
"foo": "bar",
"baz": "backage",
}, dst)
Expand Down
1 change: 1 addition & 0 deletions translation/message_selector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ func (m *MessageSelectorTestSuite) TestExtractFromString() {
{"[4,*]first", 5, stringPtr("first")},
{"[1,3]second", 0, nil},
{"[*,4]second", 3, stringPtr("second")},
{"[*,*]second", 0, stringPtr("second")},
}

for _, test := range tests {
Expand Down
3 changes: 2 additions & 1 deletion translation/translator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ import (
"context"
"testing"

"github.com/stretchr/testify/suite"

translationcontract "github.com/goravel/framework/contracts/translation"
mockloader "github.com/goravel/framework/mocks/translation"
"github.com/stretchr/testify/suite"
)

type TranslatorTestSuite struct {
Expand Down

0 comments on commit 3c9b34b

Please sign in to comment.