Files
goclaw/internal/store/pg/agents_update_null_coerce_test.go
T
Duy /zuey/ ba3b535286 fix(agents): handle null JSON config updates (#13)
* fix(agents): handle null JSON config updates

* docs(changelog): note agent provider switch fix

* docs(journal): record agent provider switch fix
2026-05-17 22:34:19 +07:00

33 lines
940 B
Go

package pg
import (
"encoding/json"
"testing"
)
func TestIsEmptyOrNullJSONUpdate(t *testing.T) {
tests := []struct {
name string
in any
want bool
}{
{name: "nil interface", in: nil, want: true},
{name: "nil raw message", in: json.RawMessage(nil), want: true},
{name: "json null raw message", in: json.RawMessage(`null`), want: true},
{name: "json null bytes", in: []byte(` null `), want: true},
{name: "empty string", in: "", want: true},
{name: "json null string", in: " null ", want: true},
{name: "object raw message", in: json.RawMessage(`{"enabled":true}`), want: false},
{name: "empty object", in: []byte(`{}`), want: false},
{name: "map", in: map[string]any{}, want: false},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := isEmptyOrNullJSONUpdate(tt.in); got != tt.want {
t.Fatalf("isEmptyOrNullJSONUpdate(%T) = %v, want %v", tt.in, got, tt.want)
}
})
}
}