Skip to content

Commit

Permalink
[go-vet] Few more static analysis fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
manugarg committed Dec 14, 2021
1 parent cfe1248 commit 2ecebf1
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 16 deletions.
2 changes: 1 addition & 1 deletion metrics/eventmetrics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ func BenchmarkEventMetricsStringer(b *testing.B) {
})
// run the em.String() function b.N times
for n := 0; n < b.N; n++ {
em.String()
_ = em.String()
}
}

Expand Down
9 changes: 7 additions & 2 deletions probes/dns/dns_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ import (
"testing"
"time"

"github.com/golang/protobuf/proto"
"github.com/cloudprober/cloudprober/logger"
"github.com/cloudprober/cloudprober/probes/common/statskeeper"
configpb "github.com/cloudprober/cloudprober/probes/dns/proto"
"github.com/cloudprober/cloudprober/probes/options"
"github.com/cloudprober/cloudprober/targets"
"github.com/cloudprober/cloudprober/validators"
validatorpb "github.com/cloudprober/cloudprober/validators/proto"
"github.com/golang/protobuf/proto"
"github.com/miekg/dns"
)

Expand Down Expand Up @@ -203,7 +203,12 @@ func TestValidator(t *testing.T) {
{"match", answerMatchPattern, 1},
{"nomatch", answerNoMatchPattern, 0},
} {
valPb := []*validatorpb.Validator{{Name: proto.String(tst.name), Type: &validatorpb.Validator_Regex{tst.pattern}}}
valPb := []*validatorpb.Validator{
{
Name: proto.String(tst.name),
Type: &validatorpb.Validator_Regex{Regex: tst.pattern},
},
}
validator, err := validators.Init(valPb, nil)
if err != nil {
t.Fatalf("Error initializing validator for pattern %v: %v", tst.pattern, err)
Expand Down
4 changes: 2 additions & 2 deletions probes/grpc/grpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import (
"sync"
"time"

"github.com/golang/protobuf/proto"
"github.com/cloudprober/cloudprober/common/oauth"
"github.com/cloudprober/cloudprober/logger"
"github.com/cloudprober/cloudprober/metrics"
Expand All @@ -38,6 +37,7 @@ import (
"github.com/cloudprober/cloudprober/probes/probeutils"
"github.com/cloudprober/cloudprober/sysvars"
"github.com/cloudprober/cloudprober/targets/endpoint"
"github.com/golang/protobuf/proto"

pb "github.com/cloudprober/cloudprober/servers/grpc/proto"
spb "github.com/cloudprober/cloudprober/servers/grpc/proto"
Expand Down Expand Up @@ -98,7 +98,7 @@ func (p *Probe) setupDialOpts() error {
if err != nil {
return err
}
p.dialOpts = append(p.dialOpts, grpc.WithPerRPCCredentials(grpcoauth.TokenSource{oauthTS}))
p.dialOpts = append(p.dialOpts, grpc.WithPerRPCCredentials(grpcoauth.TokenSource{TokenSource: oauthTS}))
}
altsCfg := p.c.GetAltsConfig()
if altsCfg != nil {
Expand Down
6 changes: 3 additions & 3 deletions probes/options/options_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,9 @@ func TestGetSourceIPFromConfig(t *testing.T) {
}

if r.sourceIP != "" {
p.SourceIpConfig = &configpb.ProbeDef_SourceIp{r.sourceIP}
p.SourceIpConfig = &configpb.ProbeDef_SourceIp{SourceIp: r.sourceIP}
} else if r.sourceIntf != "" {
p.SourceIpConfig = &configpb.ProbeDef_SourceInterface{r.sourceIntf}
p.SourceIpConfig = &configpb.ProbeDef_SourceInterface{SourceInterface: r.sourceIntf}
mockInterfaceByName(r.intf, r.intfAddrs)
}

Expand Down Expand Up @@ -175,7 +175,7 @@ func TestIPVersionFromSourceIP(t *testing.T) {
}

if r.sourceIP != "" {
p.SourceIpConfig = &configpb.ProbeDef_SourceIp{r.sourceIP}
p.SourceIpConfig = &configpb.ProbeDef_SourceIp{SourceIp: r.sourceIP}
}

opts, err := BuildProbeOptions(p, nil, nil, nil)
Expand Down
2 changes: 1 addition & 1 deletion rds/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ func (client *Client) initListResourcesFunc() error {
if err != nil {
return fmt.Errorf("rds/client: error getting token source from OAuth config (%+v): %v", client.serverOpts.GetOauthConfig(), err)
}
client.dialOpts = append(client.dialOpts, grpc.WithPerRPCCredentials(grpcoauth.TokenSource{oauthTS}))
client.dialOpts = append(client.dialOpts, grpc.WithPerRPCCredentials(grpcoauth.TokenSource{TokenSource: oauthTS}))
}

conn, err := client.connect(client.serverOpts.GetServerAddress())
Expand Down
4 changes: 2 additions & 2 deletions surfacers/surfacers.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,10 @@ var StatusTmpl = template.Must(template.New("statusTmpl").Parse(`

// Default surfacers. These surfacers are enabled if no surfacer is defined.
var defaultSurfacers = []*surfacerpb.SurfacerDef{
&surfacerpb.SurfacerDef{
{
Type: surfacerpb.Type_PROMETHEUS.Enum(),
},
&surfacerpb.SurfacerDef{
{
Type: surfacerpb.Type_FILE.Enum(),
},
}
Expand Down
9 changes: 4 additions & 5 deletions surfacers/surfacers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ import (
"testing"
"time"

"github.com/golang/protobuf/proto"
"github.com/cloudprober/cloudprober/metrics"
fileconfigpb "github.com/cloudprober/cloudprober/surfacers/file/proto"
surfacerpb "github.com/cloudprober/cloudprober/surfacers/proto"
"google.golang.org/protobuf/proto"
)

func TestDefaultConfig(t *testing.T) {
Expand All @@ -39,7 +39,7 @@ func TestDefaultConfig(t *testing.T) {
}

func TestEmptyConfig(t *testing.T) {
s, err := Init(context.Background(), []*surfacerpb.SurfacerDef{&surfacerpb.SurfacerDef{}})
s, err := Init(context.Background(), []*surfacerpb.SurfacerDef{{}})
if err != nil {
t.Fatal(err)
}
Expand All @@ -59,7 +59,7 @@ func TestInferType(t *testing.T) {
s, err := Init(context.Background(), []*surfacerpb.SurfacerDef{
{
Surfacer: &surfacerpb.SurfacerDef_FileSurfacer{
&fileconfigpb.SurfacerConf{
FileSurfacer: &fileconfigpb.SurfacerConf{
FilePath: proto.String(tmpfile.Name()),
},
},
Expand Down Expand Up @@ -190,8 +190,7 @@ func TestFailureMetric(t *testing.T) {

wantEventMetrics := [][]*metrics.EventMetrics{
testEventMetrics, // s1

[]*metrics.EventMetrics{
{
testEventMetrics[0].Clone().
AddMetric("failure", metrics.NewInt(2)),
testEventMetrics[1], // unchanged
Expand Down

0 comments on commit 2ecebf1

Please sign in to comment.