mirror of
https://github.com/netbirdio/gvisor.git
synced 2026-05-22 17:12:49 -07:00
Implement fmt.Stringer for NDPRoutePreference
PiperOrigin-RevId: 382427879
This commit is contained in:
committed by
gVisor bot
parent
6ef2684096
commit
07ffecef83
@@ -16,9 +16,12 @@ package header
|
||||
|
||||
import (
|
||||
"encoding/binary"
|
||||
"fmt"
|
||||
"time"
|
||||
)
|
||||
|
||||
var _ fmt.Stringer = NDPRoutePreference(0)
|
||||
|
||||
// NDPRoutePreference is the preference values for default routers or
|
||||
// more-specific routes.
|
||||
//
|
||||
@@ -64,6 +67,22 @@ const (
|
||||
ReservedRoutePreference = 0b10
|
||||
)
|
||||
|
||||
// String implements fmt.Stringer.
|
||||
func (p NDPRoutePreference) String() string {
|
||||
switch p {
|
||||
case HighRoutePreference:
|
||||
return "HighRoutePreference"
|
||||
case MediumRoutePreference:
|
||||
return "MediumRoutePreference"
|
||||
case LowRoutePreference:
|
||||
return "LowRoutePreference"
|
||||
case ReservedRoutePreference:
|
||||
return "ReservedRoutePreference"
|
||||
default:
|
||||
return fmt.Sprintf("NDPRoutePreference(%d)", p)
|
||||
}
|
||||
}
|
||||
|
||||
// NDPRouterAdvert is an NDP Router Advertisement message. It will only contain
|
||||
// the body of an ICMPv6 packet.
|
||||
//
|
||||
|
||||
@@ -1717,3 +1717,32 @@ func TestNDPOptionsIter(t *testing.T) {
|
||||
t.Errorf("got Next = (%x, _, _), want = (nil, _, _)", next)
|
||||
}
|
||||
}
|
||||
|
||||
func TestNDPRoutePreferenceStringer(t *testing.T) {
|
||||
p := NDPRoutePreference(0)
|
||||
for {
|
||||
var wantStr string
|
||||
switch p {
|
||||
case 0b01:
|
||||
wantStr = "HighRoutePreference"
|
||||
case 0b00:
|
||||
wantStr = "MediumRoutePreference"
|
||||
case 0b11:
|
||||
wantStr = "LowRoutePreference"
|
||||
case 0b10:
|
||||
wantStr = "ReservedRoutePreference"
|
||||
default:
|
||||
wantStr = fmt.Sprintf("NDPRoutePreference(%d)", p)
|
||||
}
|
||||
|
||||
if gotStr := p.String(); gotStr != wantStr {
|
||||
t.Errorf("got NDPRoutePreference(%d).String() = %s, want = %s", p, gotStr, wantStr)
|
||||
}
|
||||
|
||||
p++
|
||||
if p == 0 {
|
||||
// Overflowed, we hit all values.
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user