From 896fc959b302c611e7e73ca77917c38e877ac1c6 Mon Sep 17 00:00:00 2001 From: gopherclass Date: Mon, 9 Mar 2020 19:30:20 +0900 Subject: [PATCH] Add test for writing invalid ini --- viper_test.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/viper_test.go b/viper_test.go index b8ceccb..3f98404 100644 --- a/viper_test.go +++ b/viper_test.go @@ -1558,6 +1558,22 @@ func TestWriteConfigDotEnv(t *testing.T) { } } +func TestWriteConfigInvalidIni(t *testing.T) { + v := New() + fs := afero.NewMemMapFs() + v.SetFs(fs) + v.SetConfigName("c") + v.SetConfigType("ini") + v.Set("x", "y") + err := v.WriteConfigAs("c.ini") + require.NotNil(t, err, "invalid ini is expected to return an error") + _, ok := err.(ConfigMarshalError) + if !ok { + t.Fatalf("ConfigMarshalError type is expected, but got %T type", + err) + } +} + func TestSafeWriteConfig(t *testing.T) { v := New() fs := afero.NewMemMapFs()