f-46: dhcpapi: always send served on the wire #46

Served portait json:",omitempty" : sur un probe dont la MAC n'est pas réservée,
false — qui est toute la réponse — disparaissait du fil, et un opérateur lisait
un champ absent plutôt qu'une réponse négative.

Trouvé en rejouant contre un vrai serveur les exemples de diagnostic écrits pour
la documentation.

Signed-off-by: GnomeZworc <nicolas.boufidjeline@g3e.fr>
This commit is contained in:
GnomeZworc 2026-09-09 22:38:14 +02:00
commit 5b0d1bfa60
Signed by: nicolas.boufideline
GPG key ID: 4406BBBF8845D632
2 changed files with 13 additions and 1 deletions

View file

@ -1,6 +1,8 @@
package dhcpapi
import (
"encoding/json"
"strings"
"testing"
)
@ -171,3 +173,13 @@ func TestCanonical_SortsHostsByMAC(t *testing.T) {
t.Errorf("hosts = %v, want sorted by mac", got.Hosts)
}
}
func TestResponse_ServedIsAlwaysOnTheWire(t *testing.T) {
raw, err := json.Marshal(Response{OK: true, Served: false})
if err != nil {
t.Fatalf("Marshal: %v", err)
}
if !strings.Contains(string(raw), `"served":false`) {
t.Errorf("response = %s, want an explicit served:false — omitting it makes \"not served\" indistinguishable from a missing field when probing by hand", raw)
}
}

View file

@ -54,5 +54,5 @@ type Response struct {
State *State `json:"state,omitempty"`
Digest string `json:"digest,omitempty"`
Lease *Lease `json:"lease,omitempty"`
Served bool `json:"served,omitempty"`
Served bool `json:"served"`
}