diff options
author | Zeling Feng <zeling@google.com> | 2021-03-09 17:58:02 -0800 |
---|---|---|
committer | gVisor bot <gvisor-bot@google.com> | 2021-03-09 18:00:03 -0800 |
commit | 2a888a106da39f1d5e280417e48a05341a41f4dd (patch) | |
tree | f1e5980bcea761aa323540af82311a13352b043f /pkg/tcpip/header/tcp_test.go | |
parent | 6ef5bdab21e1e700a362a38435b57c9a1010aaf4 (diff) |
Give TCP flags a dedicated type
- Implement Stringer for it so that we can improve error messages.
- Use TCPFlags through the code base. There used to be a mixed usage of byte,
uint8 and int as TCP flags.
PiperOrigin-RevId: 361940150
Diffstat (limited to 'pkg/tcpip/header/tcp_test.go')
-rw-r--r-- | pkg/tcpip/header/tcp_test.go | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/pkg/tcpip/header/tcp_test.go b/pkg/tcpip/header/tcp_test.go index 72563837b..96db8460f 100644 --- a/pkg/tcpip/header/tcp_test.go +++ b/pkg/tcpip/header/tcp_test.go @@ -146,3 +146,23 @@ func TestTCPParseOptions(t *testing.T) { } } } + +func TestTCPFlags(t *testing.T) { + for _, tt := range []struct { + flags header.TCPFlags + want string + }{ + {header.TCPFlagFin, "F "}, + {header.TCPFlagSyn, " S "}, + {header.TCPFlagRst, " R "}, + {header.TCPFlagPsh, " P "}, + {header.TCPFlagAck, " A "}, + {header.TCPFlagUrg, " U"}, + {header.TCPFlagSyn | header.TCPFlagAck, " S A "}, + {header.TCPFlagFin | header.TCPFlagAck, "F A "}, + } { + if got := tt.flags.String(); got != tt.want { + t.Errorf("got TCPFlags(%#b).String() = %s, want = %s", tt.flags, got, tt.want) + } + } +} |