From adb27556f47c027eed970f4e14f3ad6d3f896c15 Mon Sep 17 00:00:00 2001 From: k2tzumi Date: Wed, 3 Jan 2024 21:23:11 +0900 Subject: [PATCH] Append config test --- config/config_test.go | 35 +++++++++++++++++++++++++ config/testdata/locale_empty.yml | 1 + config/testdata/locale_fr.yml | 1 + config/testdata/locale_ja.yml | 1 + config/testdata/locale_ja_uppercase.yml | 1 + config/testdata/locale_nothing.yml | 0 config/testdata/locale_unknown.yml | 1 + 7 files changed, 40 insertions(+) create mode 100644 config/testdata/locale_empty.yml create mode 100644 config/testdata/locale_fr.yml create mode 100644 config/testdata/locale_ja.yml create mode 100644 config/testdata/locale_ja_uppercase.yml create mode 100644 config/testdata/locale_nothing.yml create mode 100644 config/testdata/locale_unknown.yml diff --git a/config/config_test.go b/config/config_test.go index e0beca78..d9478fce 100644 --- a/config/config_test.go +++ b/config/config_test.go @@ -9,6 +9,7 @@ import ( "time" "github.com/google/go-cmp/cmp" + "golang.org/x/text/language" ) func TestMain(m *testing.M) { @@ -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 diff --git a/config/testdata/locale_empty.yml b/config/testdata/locale_empty.yml new file mode 100644 index 00000000..71514559 --- /dev/null +++ b/config/testdata/locale_empty.yml @@ -0,0 +1 @@ +locale: \ No newline at end of file diff --git a/config/testdata/locale_fr.yml b/config/testdata/locale_fr.yml new file mode 100644 index 00000000..06e6d0f8 --- /dev/null +++ b/config/testdata/locale_fr.yml @@ -0,0 +1 @@ +locale: "fr" \ No newline at end of file diff --git a/config/testdata/locale_ja.yml b/config/testdata/locale_ja.yml new file mode 100644 index 00000000..9bd62315 --- /dev/null +++ b/config/testdata/locale_ja.yml @@ -0,0 +1 @@ +locale: "ja" \ No newline at end of file diff --git a/config/testdata/locale_ja_uppercase.yml b/config/testdata/locale_ja_uppercase.yml new file mode 100644 index 00000000..e975dc65 --- /dev/null +++ b/config/testdata/locale_ja_uppercase.yml @@ -0,0 +1 @@ +locale: "JA" \ No newline at end of file diff --git a/config/testdata/locale_nothing.yml b/config/testdata/locale_nothing.yml new file mode 100644 index 00000000..e69de29b diff --git a/config/testdata/locale_unknown.yml b/config/testdata/locale_unknown.yml new file mode 100644 index 00000000..fc7cb7f5 --- /dev/null +++ b/config/testdata/locale_unknown.yml @@ -0,0 +1 @@ +locale: "unknown" \ No newline at end of file