GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Test Setup Failed
Push — master ( 27c8ce...a5aa25 )
by Amir
01:18
created

main.TestIndexHandler   B

Complexity

Conditions 7

Size

Total Lines 67
Code Lines 51

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 7
eloc 51
nop 1
dl 0
loc 67
rs 7.2036
c 0
b 0
f 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
package main
2
3
import (
4
	"context"
5
	"github.com/arazmj/gerdu/lrucache"
6
	"github.com/arazmj/gerdu/proto"
7
	"google.golang.org/grpc"
8
	"google.golang.org/grpc/test/bufconn"
9
	"log"
10
	"net"
11
	"testing"
12
)
13
14
const bufSize = 1024 * 1024
15
16
var lis *bufconn.Listener
17
18
func init() {
19
	lis = bufconn.Listen(bufSize)
20
	s := grpc.NewServer()
21
	proto.RegisterGerduServer(s, &server{})
22
	go func() {
23
		if err := s.Serve(lis); err != nil {
24
			log.Fatalf("Server exited with error: %v", err)
25
		}
26
	}()
27
}
28
29
func bufDialer(context.Context, string) (net.Conn, error) {
30
	return lis.Dial()
31
}
32
33
func TestServerGrpc(t *testing.T) {
34
	gerdu = lrucache.NewCache(1000)
35
	ctx := context.Background()
36
	conn, err := grpc.DialContext(ctx, "bufnet", grpc.WithContextDialer(bufDialer), grpc.WithInsecure())
37
	if err != nil {
38
		t.Fatalf("Failed to dial bufnet: %v", err)
39
	}
40
	defer conn.Close()
41
	client := proto.NewGerduClient(conn)
42
	resp, err := client.Put(ctx, &proto.PutRequest{
43
		Key:   "Key1",
44
		Value: []byte("Value1"),
45
	})
46
	if err != nil {
47
		t.Fatalf("gRPC Put failed: %v", err)
48
	}
49
50
	if resp.Created != true {
51
		t.Fatalf("gRPC Put could not create the key")
52
	}
53
54
	response, err := client.Get(ctx, &proto.GetRequest{
55
		Key: "Key1",
56
	})
57
58
	if err != nil {
59
		t.Fatalf("gRPC Get failed: %v", err)
60
	}
61
62
	value := string(response.Value)
63
	if value != "Value1" {
64
		t.Fatalf("gRPC Get the value does not match expecting Value1, but got %v", value)
65
	}
66
}
67