net/flowtrack: fix, test String method
I meant to do this in the earlier change and had a git fail. To atone, add a test too while I'm here. Updates #12486 Updates #12507 Change-Id: I4943b454a2530cb5047636f37136aa2898d2ffc7 Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
This commit is contained in:
parent
9e0a5cc551
commit
162d593514
|
@ -56,7 +56,9 @@ func (t Tuple) SrcPort() uint16 { return t.srcPort }
|
||||||
func (t Tuple) DstPort() uint16 { return t.dstPort }
|
func (t Tuple) DstPort() uint16 { return t.dstPort }
|
||||||
|
|
||||||
func (t Tuple) String() string {
|
func (t Tuple) String() string {
|
||||||
return fmt.Sprintf("(%v %v => %v)", t.proto, t.src, t.dst)
|
return fmt.Sprintf("(%v %v => %v)", t.proto,
|
||||||
|
netip.AddrPortFrom(t.SrcAddr(), t.srcPort),
|
||||||
|
netip.AddrPortFrom(t.DstAddr(), t.dstPort))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t Tuple) MarshalJSON() ([]byte, error) {
|
func (t Tuple) MarshalJSON() ([]byte, error) {
|
||||||
|
|
|
@ -100,10 +100,15 @@ func BenchmarkMapKeys(b *testing.B) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestJSON(t *testing.T) {
|
func TestStringJSON(t *testing.T) {
|
||||||
v := MakeTuple(123,
|
v := MakeTuple(123,
|
||||||
netip.MustParseAddrPort("1.2.3.4:5"),
|
netip.MustParseAddrPort("1.2.3.4:5"),
|
||||||
netip.MustParseAddrPort("6.7.8.9:10"))
|
netip.MustParseAddrPort("6.7.8.9:10"))
|
||||||
|
|
||||||
|
if got, want := v.String(), "(IPProto-123 1.2.3.4:5 => 6.7.8.9:10)"; got != want {
|
||||||
|
t.Errorf("String = %q; want %q", got, want)
|
||||||
|
}
|
||||||
|
|
||||||
got, err := json.Marshal(v)
|
got, err := json.Marshal(v)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
|
|
Loading…
Reference in New Issue