Files
go-config/internal/merge/merge_test.go
eSliderandCursor c575341178 feat(go-config): multi-format codecs, envc CLI, fixtures, ASRs
- Module github.com/eslider/go-config with env/yaml/json/ini packages
- internal: source, keymap, merge, structconv, bytesutil
- cmd/envc: convert, get, merge
- docs/asr ASR-0001..0008, README/CHANGELOG/AGENTS refresh
- golangci-lint v2 config; tests + fixtures

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-05-02 14:04:01 +01:00

53 lines
1.2 KiB
Go

package merge
import (
"reflect"
"testing"
)
func TestDeepMerge_MapRecursion(t *testing.T) {
dst := map[string]any{
"a": map[string]any{"x": "1"},
}
src := map[string]any{
"a": map[string]any{"y": "2"},
}
DeepMerge(dst, src)
want := map[string]any{
"a": map[string]any{"x": "1", "y": "2"},
}
if !reflect.DeepEqual(dst, want) {
t.Fatalf("got %#v want %#v", dst, want)
}
}
func TestDeepMerge_ScalarLastWins(t *testing.T) {
dst := map[string]any{"k": "first"}
src := map[string]any{"k": "second"}
DeepMerge(dst, src)
if dst["k"] != "second" {
t.Fatalf("got %v", dst["k"])
}
}
func TestDeepMerge_SliceReplace(t *testing.T) {
dst := map[string]any{"s": []any{"a", "b"}}
src := map[string]any{"s": []any{"c"}}
DeepMerge(dst, src, WithSliceStrategy(Replace))
got := dst["s"].([]any)
if len(got) != 1 || got[0] != "c" {
t.Fatalf("got %#v", got)
}
}
func TestDeepMerge_SliceConcat(t *testing.T) {
dst := map[string]any{"s": []any{"a", "b"}}
src := map[string]any{"s": []any{"c"}}
DeepMerge(dst, src, WithSliceStrategy(Concat))
got := dst["s"].([]any)
want := []any{"a", "b", "c"}
if !reflect.DeepEqual(got, want) {
t.Fatalf("got %#v want %#v", got, want)
}
}