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:
parent
7d4d856c95
commit
5b0d1bfa60
2 changed files with 13 additions and 1 deletions
|
|
@ -1,6 +1,8 @@
|
||||||
package dhcpapi
|
package dhcpapi
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -171,3 +173,13 @@ func TestCanonical_SortsHostsByMAC(t *testing.T) {
|
||||||
t.Errorf("hosts = %v, want sorted by mac", got.Hosts)
|
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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -54,5 +54,5 @@ type Response struct {
|
||||||
State *State `json:"state,omitempty"`
|
State *State `json:"state,omitempty"`
|
||||||
Digest string `json:"digest,omitempty"`
|
Digest string `json:"digest,omitempty"`
|
||||||
Lease *Lease `json:"lease,omitempty"`
|
Lease *Lease `json:"lease,omitempty"`
|
||||||
Served bool `json:"served,omitempty"`
|
Served bool `json:"served"`
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue