package main import ( "testing" "github.com/stretchr/testify/assert" ) func Test_mergeData(t *testing.T) { tests := []struct { name string d1 wkData d2 wkData expected wkData }{ {"empty", map[string]interface{}{}, map[string]interface{}{"a": 1}, map[string]interface{}{"a": 1}}, {"append", map[string]interface{}{"a": 1}, map[string]interface{}{"b": 2}, map[string]interface{}{"a": 1, "b": 2}}, {"existing", map[string]interface{}{"a": "a", "b": "b"}, map[string]interface{}{"a": "aa"}, map[string]interface{}{"a": "aa", "b": "b"}}, {"nested", map[string]interface{}{"a": map[string]interface{}{"nest": "value"}}, map[string]interface{}{"b": 2}, map[string]interface{}{"a": map[string]interface{}{"nest": "value"}, "b": 2}}, {"nestedExist", map[string]interface{}{"a": map[string]interface{}{"nest": "value"}}, map[string]interface{}{"a": 2}, map[string]interface{}{"a": 2}}, {"nestedExistMerge", map[string]interface{}{"a": map[string]interface{}{"nest": "value"}}, map[string]interface{}{"a": map[string]interface{}{"nest2": "value2"}}, map[string]interface{}{"a": map[string]interface{}{"nest": "value", "nest2": "value2"}}}, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { result := mergeData(tt.d1, tt.d2) assert.Equal(t, tt.expected, result) }) } } func Test_wkRegistry_encode(t *testing.T) { tests := []struct { name string reg wkRegistry want map[string]string }{ // JSON test cases { name: "simple_json", reg: wkRegistry{ "a": map[string]interface{}{"b": 1}, }, want: map[string]string{ "a.json": "{\n \"b\": 1\n}", "a": "{\n \"b\": 1\n}", // Stored without .json extension for compatibility }, }, { name: "double_json", reg: wkRegistry{ "a": map[string]interface{}{"b": 1}, "b": map[string]interface{}{"c": 2}, }, want: map[string]string{ "a.json": "{\n \"b\": 1\n}", "a": "{\n \"b\": 1\n}", "b.json": "{\n \"c\": 2\n}", "b": "{\n \"c\": 2\n}", }, }, // Plain text test cases { name: "simple_text", reg: wkRegistry{ "a": []string{"line1", "line2"}, }, want: map[string]string{ "a.txt": "line1\nline2", }, }, { name: "double_text", reg: wkRegistry{ "a": []string{"line1", "line2"}, "b": "single line", }, want: map[string]string{ "a.txt": "line1\nline2", "b.txt": "single line", }, }, // Mixed content test cases { name: "mixed_content", reg: wkRegistry{ "a": map[string]interface{}{"b": 1}, "c": "plain text", }, want: map[string]string{ "a.json": "{\n \"b\": 1\n}", "a": "{\n \"b\": 1\n}", "c.txt": "plain text", }, }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { got := tt.reg.encode() assert.Equal(t, tt.want, got) }) } }