feat: add TOML codec and envc format support
New toml package (pelletier/go-toml/v2) matching yaml/json options and merge flow. envc convert/get/merge accept --from/--to toml; fixture and CLI tests; docs refresh. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
package toml
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"github.com/eslider/go-config/internal/testfixtures"
|
||||
)
|
||||
|
||||
func TestCodec_IdentityTOMLFixture(t *testing.T) {
|
||||
c := New(WithBytes(testfixtures.Load(t, "identity", "service.toml")))
|
||||
m, err := c.Map(context.Background())
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if m["service"].(map[string]any)["name"] != "my-service" {
|
||||
t.Fatalf("%#v", m)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCodec_MarshalRoundTripMap(t *testing.T) {
|
||||
in := map[string]any{
|
||||
"app": map[string]any{
|
||||
"name": "demo",
|
||||
"port": int64(8080),
|
||||
},
|
||||
}
|
||||
c := New()
|
||||
b, err := c.Marshal(in)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
c2 := New(WithBytes(b))
|
||||
m, err := c2.Map(context.Background())
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if m["app"].(map[string]any)["name"] != "demo" {
|
||||
t.Fatalf("%#v", m)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user