From afe3be23cb9797c362a0b0456e75807b51e487f5 Mon Sep 17 00:00:00 2001 From: Mark Sagi-Kazar Date: Wed, 5 Jun 2024 10:29:25 +0200 Subject: [PATCH] test: add failing test for reading config without a config type Signed-off-by: Mark Sagi-Kazar --- viper_test.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/viper_test.go b/viper_test.go index 3352c1a..0b9d9c6 100644 --- a/viper_test.go +++ b/viper_test.go @@ -1658,6 +1658,12 @@ func TestReadConfig(t *testing.T) { assert.Equal(t, map[string]any{"jacket": "leather", "trousers": "denim", "pants": map[string]any{"size": "large"}}, v.Get("clothing")) assert.Equal(t, 35, v.Get("age")) }) + + t.Run("missing config type", func(t *testing.T) { + v := New() + err := v.ReadConfig(bytes.NewBuffer(yamlExample)) + require.Error(t, err) + }) } func TestIsSet(t *testing.T) { @@ -2130,6 +2136,7 @@ func TestSafeWriteAsConfig(t *testing.T) { v := New() fs := afero.NewMemMapFs() v.SetFs(fs) + v.SetConfigType("yaml") err := v.ReadConfig(bytes.NewBuffer(yamlExample)) require.NoError(t, err) require.NoError(t, v.SafeWriteConfigAs("/test/c.yaml"))