Skip to content

Commit

Permalink
fix: #59 dump config data to file error
Browse files Browse the repository at this point in the history
  • Loading branch information
inhere committed Oct 13, 2021
1 parent 4bdc506 commit 63ceadf
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 1 deletion.
2 changes: 1 addition & 1 deletion export.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ func (c *Config) DumpTo(out io.Writer, format string) (n int64, err error) {
}

// encode data to string
encoded, err := encoder(&c.data)
encoded, err := encoder(c.data)
if err != nil {
return
}
Expand Down
22 changes: 22 additions & 0 deletions issues_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ import (
"testing"

"github.com/gookit/config/v2"
"github.com/gookit/config/v2/ini"
"github.com/gookit/config/v2/yaml"
"github.com/gookit/config/v2/yamlv3"
"github.com/gookit/goutil/dump"
"github.com/gookit/goutil/fsutil"
"github.com/gookit/goutil/testutil"
"github.com/stretchr/testify/assert"
)
Expand Down Expand Up @@ -112,5 +114,25 @@ func TestIssues_46(t *testing.T) {
dump.Println(h)
is.Equal(19090, h.Port)
})
}

// https://github.com/gookit/config/issues/46
func TestIssues_59(t *testing.T) {
is := assert.New(t)

c := config.NewWithOptions("test", config.ParseEnv)
c.AddDriver(ini.Driver)

err := c.LoadFiles("testdata/ini_base.ini")
is.NoError(err)
dump.Println(c.Data())

dumpfile := "testdata/issues59.ini"
out := fsutil.MustCreateFile(dumpfile, 0666, 0666)
_, err = c.DumpTo(out, config.Ini)
is.NoError(err)

str := string(fsutil.MustReadFile(dumpfile))
is.Contains(str, "name = app")
is.Contains(str, "key1 = val1")
}
1 change: 1 addition & 0 deletions testdata/ini_base.ini
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ baseKey = value
age = 123
envKey = ${SHELL}
envKey1 = ${NotExist|defValue}
multiWords = hello world

[map1]
key = val
Expand Down
12 changes: 12 additions & 0 deletions testdata/issues59.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
age = 123
baseKey = value
debug = false
envKey = ${SHELL}
envKey1 = ${NotExist|defValue}
multiWords = hello world
name = app
[map1]
key = val
key1 = val1
key2 = val2

0 comments on commit 63ceadf

Please sign in to comment.