Skip to content

Commit

Permalink
Fix issues with update code
Browse files Browse the repository at this point in the history
  • Loading branch information
joeycumines committed Jul 30, 2023
1 parent 5b0f748 commit b2257bc
Show file tree
Hide file tree
Showing 13 changed files with 70 additions and 3 deletions.
20 changes: 20 additions & 0 deletions hack/insert-line-files.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/bin/sh

# Check if sufficient arguments have been provided
if [ "$#" -lt 2 ]; then
echo "Usage: $0 line files"
exit 1
fi

insert_line=$1
shift

# For each file
for file in "$@"; do
# Extract filename and line number
filename=$(echo $file | cut -d ':' -f1)
line_number=$(echo $file | cut -d ':' -f2)

# Use awk to insert line
awk -v n="$line_number" -v s="$insert_line" '(NR==n) {print s} {print}' $filename >tmpfile && mv tmpfile $filename
done
13 changes: 13 additions & 0 deletions hack/staticcheck-ignore-for-reason.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/sh

if ! { [ "$#" -eq 2 ] && ! [ -z "$1" ] && ! [ -z "$2" ]; }; then
echo "Usage: $0 <code> <reason>"
exit 1
fi

code="$1" &&
shift &&
reason="$1" &&
shift &&
lines="$(hack/staticcheck-lines-for-code.sh "$code")" &&
hack/insert-line-files.sh "//lint:ignore $code $reason" ${lines}
8 changes: 8 additions & 0 deletions hack/staticcheck-lines-for-code.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/sh

if ! { [ "$#" -eq 1 ] && ! [ -z "$1" ]; }; then
echo "Usage: $0 <check>"
exit 1
fi

staticcheck -checks "$1" ./... | tee /dev/stderr | grep -F -- "$1" | cut -d : -f 1-2 | uniq | tac
10 changes: 9 additions & 1 deletion internal/flowcontrol/flowcontrol_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,15 @@ func (x *streamCounterMap) String() string {
kv = append(kv, k)
keys[k] = fmt.Sprint(k)
}
slices.SortFunc(kv, func(a, b mockKey) bool { return keys[a] < keys[b] })
slices.SortFunc(kv, func(a, b mockKey) int {
if keys[a] < keys[b] {
return -1
} else if keys[a] > keys[b] {
return 1
} else {
return 0
}
})
for _, k := range kv {
if b.Len() != 0 {
b.WriteByte('\n')
Expand Down
1 change: 1 addition & 0 deletions internal/nettest/conntest.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"bytes"
"encoding/binary"
"io"
//lint:ignore SA1019 v1 isnt completely released yet
"io/ioutil"
"math/rand"
"net"
Expand Down
1 change: 1 addition & 0 deletions internal/nettest/nettest.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ package nettest
import (
"errors"
"fmt"
//lint:ignore SA1019 v1 isnt completely released yet
"io/ioutil"
"net"
"os"
Expand Down
1 change: 1 addition & 0 deletions internal/testing/testing.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ type (
Run(name string, f func(t T)) bool
}

//lint:ignore U1000 it is actually used
tI = T

// TG is all of T except the recursive method.
Expand Down
6 changes: 5 additions & 1 deletion internal/testutil/grpc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,19 @@ func ExampleNewBufconnClient() {
panic(err)
}

//lint:ignore SA1019 v1 isnt completely released yet
if err := stream.Send(&refl.ServerReflectionRequest{MessageRequest: &refl.ServerReflectionRequest_ListServices{}}); err != nil {
panic(err)
}

if msg, err := stream.Recv(); err != nil {
panic(err)
} else {
//lint:ignore SA1019 v1 isnt completely released yet
services := make([]string, 0, len(msg.GetListServicesResponse().GetService()))
//lint:ignore SA1019 v1 isnt completely released yet
for _, v := range msg.GetListServicesResponse().GetService() {
//lint:ignore SA1019 v1 isnt completely released yet
services = append(services, v.GetName())
}
fmt.Printf("there are %d available services: %q\n", len(services), services)
Expand All @@ -53,7 +57,7 @@ func ExampleNewBufconnClient() {
}

// output:
// there are 1 available services: ["grpc.reflection.v1alpha.ServerReflection"]
// there are 2 available services: ["grpc.reflection.v1.ServerReflection" "grpc.reflection.v1alpha.ServerReflection"]
}

func TestGrpchanClientConnFactory(t *testing.T) {
Expand Down
2 changes: 2 additions & 0 deletions rc/netconn/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ type (
// Server implements rc.RemoteControlServer's NetConn method.
Server struct {
Dialer DialerFactory
//lint:ignore U1000 it is actually used
unimplementedRemoteControlServer
}

Expand All @@ -35,6 +36,7 @@ type (
DialContext(ctx context.Context, network, address string) (net.Conn, error)
}

//lint:ignore U1000 it is actually used
unimplementedRemoteControlServer = rc.UnimplementedRemoteControlServer
)

Expand Down
2 changes: 1 addition & 1 deletion tun/grpc/option_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ func Test_tunnelConfig_validate(t *testing.T) {
t.Error(hm)
} else if c.handlers.get().val != hm[0] {
t.Error()
} else if len(c.handlers.get().val.m) != 2 {
} else if len(c.handlers.get().val.m) != 3 {
t.Error(c.handlers.get().val.m)
}

Expand Down
1 change: 1 addition & 0 deletions tun/grpc/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ type TunnelServer struct {
mu sync.RWMutex
reverseByKey map[interface{}]*reverseChannels

//lint:ignore U1000 it is actually used
unimplementedTunnelServiceServer
}

Expand Down
4 changes: 4 additions & 0 deletions tun/grpc/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ func ExampleTunnelServer_reflection() {
panic(err)
}

//lint:ignore SA1019 v1 isnt completely released yet
if err := stream.Send(&refl.ServerReflectionRequest{MessageRequest: &refl.ServerReflectionRequest_ListServices{}}); err != nil {
panic(err)
}
Expand All @@ -146,7 +147,9 @@ func ExampleTunnelServer_reflection() {
}

var names []string
//lint:ignore SA1019 v1 isnt completely released yet
for _, svc := range res.GetListServicesResponse().GetService() {
//lint:ignore SA1019 v1 isnt completely released yet
names = append(names, svc.GetName())
}
sort.Strings(names)
Expand All @@ -155,6 +158,7 @@ func ExampleTunnelServer_reflection() {
}

// output:
// grpc.reflection.v1.ServerReflection
// grpc.reflection.v1alpha.ServerReflection
// grpchantesting.TestService
}
4 changes: 4 additions & 0 deletions tun/grpc/tunnel_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ func ExampleServeTunnel_reflection() {
panic(err)
}

//lint:ignore SA1019 v1 isnt completely released yet
if err := stream.Send(&refl.ServerReflectionRequest{MessageRequest: &refl.ServerReflectionRequest_ListServices{}}); err != nil {
panic(err)
}
Expand All @@ -68,7 +69,9 @@ func ExampleServeTunnel_reflection() {
}

var names []string
//lint:ignore SA1019 v1 isnt completely released yet
for _, svc := range res.GetListServicesResponse().GetService() {
//lint:ignore SA1019 v1 isnt completely released yet
names = append(names, svc.GetName())
}
sort.Strings(names)
Expand All @@ -77,6 +80,7 @@ func ExampleServeTunnel_reflection() {
}

// output:
// grpc.reflection.v1.ServerReflection
// grpc.reflection.v1alpha.ServerReflection
// grpchantesting.TestService
}
Expand Down

0 comments on commit b2257bc

Please sign in to comment.