From 32ef9938960b65c1ff528ec21bf865691963139e Mon Sep 17 00:00:00 2001 From: joanestebanr <129153821+joanestebanr@users.noreply.github.com> Date: Wed, 18 Sep 2024 13:03:32 +0200 Subject: [PATCH] feat: add ut --- config/config_test.go | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/config/config_test.go b/config/config_test.go index 98003598..8019ed5f 100644 --- a/config/config_test.go +++ b/config/config_test.go @@ -7,7 +7,7 @@ import ( "github.com/stretchr/testify/require" ) -func TestXxx(t *testing.T) { +func TestLoadDeafaultConfig(t *testing.T) { tmpFile, err := os.CreateTemp("", "ut_config") require.NoError(t, err) defer os.Remove(tmpFile.Name()) @@ -16,3 +16,33 @@ func TestXxx(t *testing.T) { require.NoError(t, err) require.NotNil(t, cfg) } + +const configWithUnexpectedFields = ` +[UnknownField] +Field = "value" +` + +func TestLoadConfigWithUnexpectedFields(t *testing.T) { + tmpFile, err := os.CreateTemp("", "ut_config") + require.NoError(t, err) + defer os.Remove(tmpFile.Name()) + tmpFile.Write([]byte(configWithUnexpectedFields)) + cfg, err := LoadFile(tmpFile.Name()) + require.NoError(t, err) + require.NotNil(t, cfg) +} + +const configWithForbiddenFields = ` +[aggregator.synchronizer.db] +name = "value" +` + +func TestLoadConfigWithForbiddenFields(t *testing.T) { + tmpFile, err := os.CreateTemp("", "ut_config") + require.NoError(t, err) + defer os.Remove(tmpFile.Name()) + tmpFile.Write([]byte(configWithForbiddenFields)) + cfg, err := LoadFile(tmpFile.Name()) + require.NoError(t, err) + require.NotNil(t, cfg) +}