Skip to content

Commit

Permalink
feat: add ut
Browse files Browse the repository at this point in the history
  • Loading branch information
joanestebanr committed Sep 18, 2024
1 parent f573c41 commit 32ef993
Showing 1 changed file with 31 additions and 1 deletion.
32 changes: 31 additions & 1 deletion config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand All @@ -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))

Check failure on line 29 in config/config_test.go

View workflow job for this annotation

GitHub Actions / lint

Error return value of `tmpFile.Write` is not checked (errcheck)
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))

Check failure on line 44 in config/config_test.go

View workflow job for this annotation

GitHub Actions / lint

Error return value of `tmpFile.Write` is not checked (errcheck)
cfg, err := LoadFile(tmpFile.Name())
require.NoError(t, err)
require.NotNil(t, cfg)
}

0 comments on commit 32ef993

Please sign in to comment.