all: use strs.CutPrefix and strs.CutSuffix more

Updates places where we use HasPrefix + TrimPrefix to use the combined
function.

Updates #5309

Signed-off-by: Mihai Parparita <mihai@tailscale.com>
This commit is contained in:
Mihai Parparita
2022-11-18 10:13:14 -08:00
committed by Mihai Parparita
parent 41e1d336cc
commit 33520920c3
14 changed files with 46 additions and 34 deletions

View File

@@ -8,11 +8,11 @@ import (
"fmt"
"net/netip"
"reflect"
"strings"
"testing"
"go4.org/mem"
"tailscale.com/types/key"
"tailscale.com/util/strs"
)
func TestMarshalAndParse(t *testing.T) {
@@ -72,10 +72,10 @@ func TestMarshalAndParse(t *testing.T) {
t.Run(tt.name, func(t *testing.T) {
foo := []byte("foo")
got := string(tt.m.AppendMarshal(foo))
if !strings.HasPrefix(got, "foo") {
got, ok := strs.CutPrefix(got, "foo")
if !ok {
t.Fatalf("didn't start with foo: got %q", got)
}
got = strings.TrimPrefix(got, "foo")
gotHex := fmt.Sprintf("% x", got)
if gotHex != tt.want {