package configutil import ( "encoding/json" "testing" "kra/app/system/internal/conf" "google.golang.org/protobuf/encoding/protojson" ) func TestMergeProtoJSONPreservesOmittedFieldsAndNormalizesKeys(t *testing.T) { target := &conf.AdminBackend{ RouterPrefix: "/api", System: &conf.AdminBackend_System{UseRedis: true, IplimitCount: 3}, } patch := json.RawMessage(`{"router_prefix":"/admin","system":{"iplimit_count":9}}`) if err := MergeProtoJSON(target, patch, protojson.UnmarshalOptions{DiscardUnknown: true}); err != nil { t.Fatal(err) } if target.RouterPrefix != "/admin" || target.System.IplimitCount != 9 { t.Fatalf("patch was not applied: %#v", target) } if !target.System.UseRedis { t.Fatal("an omitted nested field was cleared") } }