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>
42 lines
784 B
Go
42 lines
784 B
Go
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)
|
|
}
|
|
}
|