Skip to content

Commit

Permalink
Append config test
Browse files Browse the repository at this point in the history
  • Loading branch information
k2tzumi committed Jan 3, 2024
1 parent eb13a92 commit adb2755
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 0 deletions.
35 changes: 35 additions & 0 deletions config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"time"

"github.com/google/go-cmp/cmp"
"golang.org/x/text/language"
)

func TestMain(m *testing.M) {
Expand Down Expand Up @@ -92,6 +93,40 @@ func TestLoadCentralPush(t *testing.T) {
}
}

func TestLoadLocale(t *testing.T) {
tests := []struct {
path string
want *language.Tag
wantError bool
}{
{"locale_nothing.yml", nil, false},
{"locale_empty.yml", nil, false},
{"locale_ja.yml", &language.Japanese, false},
{"locale_ja_uppercase.yml", &language.Japanese, false},
{"locale_fr.yml", &language.French, false},
{"locale_unkown.yml", nil, true},
}
for _, tt := range tests {
c := New()
t.Run(fmt.Sprintf("%v", tt.path), func(t *testing.T) {
p := filepath.Join(testdataDir(t), tt.path)
if err := c.Load(p); err != nil {
if tt.wantError {
return
}
t.Fatal(err)
}
got := c.Locale
if tt.want == nil && got == nil {
return
}
if diff := cmp.Diff(got.String(), tt.want.String(), nil); diff != "" {
t.Error(diff)
}
})
}
}

func TestCoveragePaths(t *testing.T) {
tests := []struct {
paths []string
Expand Down
1 change: 1 addition & 0 deletions config/testdata/locale_empty.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
locale:
1 change: 1 addition & 0 deletions config/testdata/locale_fr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
locale: "fr"
1 change: 1 addition & 0 deletions config/testdata/locale_ja.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
locale: "ja"
1 change: 1 addition & 0 deletions config/testdata/locale_ja_uppercase.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
locale: "JA"
Empty file.
1 change: 1 addition & 0 deletions config/testdata/locale_unknown.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
locale: "unknown"

0 comments on commit adb2755

Please sign in to comment.