✨ Load config from file with defaults
This commit is contained in:
parent
2da9fcac37
commit
40f9518611
8 changed files with 127 additions and 2 deletions
29
config/load_test.go
Normal file
29
config/load_test.go
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
package config
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
//fp "path/filepath"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestLoad(t *testing.T) {
|
||||
f, _ := os.CreateTemp("", "test")
|
||||
ConfigPath = f.Name()
|
||||
fmt.Fprint(f, `[input]
|
||||
ext = "log"`)
|
||||
c, err := Load()
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, "log", c.Input.Ext)
|
||||
}
|
||||
|
||||
func TestLoadIgnoreMissingFile(t *testing.T) {
|
||||
def, _ := DefaultConfig()
|
||||
ConfigPath = "/not/a/real/file"
|
||||
c, err := Load()
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, def, c)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue