38005c0618
Go's encoding/json does not bridge snake_case <-> PascalCase field names, so store.Endpoint, store.Task and the anonymous request bodies in accounts.go/auth.go were silently decoding empty/zero values from the frontend's snake_case JSON contract (tls_mode, role_label, src_endpoint_id, dst_endpoint_id, src_login/pass, dst_login/pass). Adds explicit json tags; DB layer is unaffected since pgx binds by positional params, not struct-tag reflection. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01MMHQTtnQtQqL8muAXHr9kd
36 lines
995 B
Go
36 lines
995 B
Go
package store
|
|
|
|
import (
|
|
"encoding/json"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
func TestEndpointJSONRoundTrip(t *testing.T) {
|
|
var e Endpoint
|
|
if err := json.Unmarshal([]byte(`{"role_label":"src","host":"h","port":993,"tls_mode":"ssl"}`), &e); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if e.RoleLabel != "src" || e.Host != "h" || e.Port != 993 || e.TLSMode != "ssl" {
|
|
t.Fatalf("decode failed: %+v", e)
|
|
}
|
|
b, _ := json.Marshal(e)
|
|
if !strings.Contains(string(b), `"tls_mode":"ssl"`) || !strings.Contains(string(b), `"role_label":"src"`) {
|
|
t.Fatalf("marshal not snake_case: %s", b)
|
|
}
|
|
}
|
|
|
|
func TestTaskJSONRoundTrip(t *testing.T) {
|
|
var tk Task
|
|
if err := json.Unmarshal([]byte(`{"name":"n","src_endpoint_id":1,"dst_endpoint_id":2}`), &tk); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if tk.Name != "n" || tk.SrcEndpointID != 1 || tk.DstEndpointID != 2 {
|
|
t.Fatalf("decode failed: %+v", tk)
|
|
}
|
|
b, _ := json.Marshal(tk)
|
|
if !strings.Contains(string(b), `"src_endpoint_id":1`) {
|
|
t.Fatalf("marshal not snake_case: %s", b)
|
|
}
|
|
}
|