Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

all: fix errors reported by 'go vet' #144

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jobs:

- name: Test
run: |
make test
make fmtchk vet test

- name: build
run: |
Expand Down
7 changes: 5 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,11 @@ generate:

.PHONY: fmtcheck
fmtchk:
$Qexit $(shell gofmt -l . | grep -v '^vendor' | wc -l)
@OUTPUT=$$(gofmt -l . | grep -v vendor/); \
if [ -n "$$OUTPUT" ]; then \
echo "Some files were not gofmtted:\\n$$OUTPUT"; \
exit 1; \
fi

.PHONY: fmtfix
fmtfix:
Expand All @@ -75,4 +79,3 @@ test:
.PHONY: bench
bench:
$Qgo test $(GOTESTFLAGS) -bench .

2 changes: 1 addition & 1 deletion pkg/cmd/ctlstore/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -632,7 +632,7 @@ func newReflector(cliCfg reflectorCliConfig, isSupervisor bool, i int) (*reflect
events.Log("DEPRECATION NOTICE: use --disable-ecs-behavior instead of --disable to control this ledger monitor behavior")
}
id := fmt.Sprintf("%s-%d", path.Base(cliCfg.LDBPath), i)
l := events.NewLogger(events.DefaultHandler).With(events.Args{{"id", id}})
l := events.NewLogger(events.DefaultHandler).With(events.Args{{Name: "id", Value: id}})
l.EnableDebug = cliCfg.Debug
return reflectorpkg.ReflectorFromConfig(reflectorpkg.ReflectorConfig{
LDBPath: cliCfg.LDBPath,
Expand Down
8 changes: 6 additions & 2 deletions pkg/event/changelog_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,16 +161,16 @@ func TestChangelog(t *testing.T) {
rotateAfter: test.rotateAfter,
rotateAfterBytes: test.rotateAfterBytes,
}
var writeErr error
var wg sync.WaitGroup
wg.Add(1)
go func() {
defer wg.Done()
err := flw.writeN(ctx, test.numEvents)
if err != nil {
t.Fatal(err)
writeErr = err
}
}()
defer wg.Wait()
for i := 0; i < test.numEvents; i++ {
event, err := cl.next(ctx)
if err != nil {
Expand All @@ -182,6 +182,10 @@ func TestChangelog(t *testing.T) {
if test.mustRotateN > 0 {
require.EqualValues(t, test.mustRotateN, atomic.LoadInt64(&flw.rotations))
}
wg.Wait()
if writeErr != nil {
t.Fatal(writeErr)
}
})
}
}
Expand Down
3 changes: 2 additions & 1 deletion pkg/event/entry.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ package event

// entry represents a single row in the changelog
// e.g.
// {"seq":1,"family":"fam","table":"foo","key":[{"name":"id","type":"int","value":1}]}
//
// {"seq":1,"family":"fam","table":"foo","key":[{"name":"id","type":"int","value":1}]}
type entry struct {
Seq int64 `json:"seq"`
Family string `json:"family"`
Expand Down
2 changes: 1 addition & 1 deletion pkg/executive/db_executive.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ func (e *dbExecutive) CreateTable(familyName string, tableName string, fieldName

err = tbl.Validate()
if err != nil {
return &errs.BadRequestError{err.Error()}
return &errs.BadRequestError{Err: err.Error()}
}

ddl, err := tbl.AsCreateTableDDL()
Expand Down
7 changes: 4 additions & 3 deletions pkg/executive/dml_ledger_writer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ func TestDMLLogWriterAdd(t *testing.T) {

for i, testCase := range suite {
testName := fmt.Sprintf("[%d] %s", i, testCase.desc)
statements := testCase.statements
t.Run(testName, func(t *testing.T) {
t.Parallel()
ctx := context.Background()
Expand All @@ -42,7 +43,7 @@ func TestDMLLogWriterAdd(t *testing.T) {
defer w.Close()

seqs := []schema.DMLSequence{}
for _, stString := range testCase.statements {
for _, stString := range statements {
seq, err := w.Add(ctx, stString)
if err != nil {
t.Fatalf("Unexpected error: %v", err)
Expand Down Expand Up @@ -81,7 +82,7 @@ func TestDMLLogWriterAdd(t *testing.T) {

i := 0
for rows.Next() {
if i+1 > len(testCase.statements) {
if i+1 > len(statements) {
t.Errorf("Scanned more statements than expected")
break
}
Expand All @@ -98,7 +99,7 @@ func TestDMLLogWriterAdd(t *testing.T) {
t.Errorf("Expected %v, got %v", want, got)
}

if want, got := testCase.statements[i], rowStmt; want != got {
if want, got := statements[i], rowStmt; want != got {
t.Errorf("Expected %v, got %v", want, got)
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/executive/executive.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func newMutationRequest(famName schema.FamilyName, req ExecutiveMutationRequest)
}

// Returns the request Values as a slice in the order specified by the
//fieldOrder param. An error will be returned if a field is missing.
// fieldOrder param. An error will be returned if a field is missing.
func (r *mutationRequest) valuesByOrder(fieldOrder []schema.FieldName) ([]interface{}, error) {
values := []interface{}{}
for _, fn := range fieldOrder {
Expand Down
2 changes: 0 additions & 2 deletions pkg/ldbwriter/ldb_writer_with_changelog.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ type LDBWriterWithChangelog struct {
Seq int64
}

//
// NOTE: How does the changelog work?
//
// This is sort of the crux of how the changelog comes together. The Reflector
Expand All @@ -33,7 +32,6 @@ type LDBWriterWithChangelog struct {
// This is pretty complex, but after enumerating about 8 different options, it
// ended up actually being the most simple. Other options involved not-so-great
// options like parsing SQL or maintaining triggers on every table.
//
func (w *LDBWriterWithChangelog) ApplyDMLStatement(ctx context.Context, statement schema.DMLStatement) error {
err := w.LdbWriter.ApplyDMLStatement(ctx, statement)
if err != nil {
Expand Down
9 changes: 6 additions & 3 deletions pkg/reflector/reflector_ctl.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,14 +137,17 @@ func (r *ReflectorCtl) lifecycle(appCtx context.Context) {
for {
select {
case <-appCtx.Done():
// the application is quitting
// the application is quitting - cancel the reflector
events.Log("reflectorCtl stopping due to context err=%v", appCtx.Err())
if cancel != nil {
cancel()
}
return
case msg := <-r.messages:
// another goroutine has asked for the reflector to either
// be started or stopped.
switch msg.desired {
case true:
case true: // start the reflector
if !running {
ctx, cancel = context.WithCancel(appCtx)
wg.Add(1)
Expand All @@ -155,7 +158,7 @@ func (r *ReflectorCtl) lifecycle(appCtx context.Context) {
running = true
}
msg.sendErr(appCtx, nil)
case false:
case false: // stop the reflector
if running {
cancel()
done := make(chan struct{})
Expand Down
5 changes: 3 additions & 2 deletions pkg/reflector/reflector_ctl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,12 @@ func TestReflectorCtl(t *testing.T) {
// context root.
func TestReflectorCtlContext(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
ctx2, _ := context.WithCancel(ctx)
ctx2, cancel2 := context.WithCancel(ctx)
defer cancel2()
cancel()
select {
case <-ctx2.Done():
default:
t.Fatal("context should have been canceled")
t.Fatal("child context should have been canceled")
}
}
5 changes: 5 additions & 0 deletions pkg/reflector/shovel.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ func (s *shovel) Start(ctx context.Context) error {
safeCancel()
var sctx context.Context
sctx, cancel = context.WithTimeout(ctx, s.pollTimeout)
safeCancel = func() {
if cancel != nil {
cancel()
}
}

stats.Incr("shovel.loop_enter")
s.logger().Debug("shovel polling...")
Expand Down
42 changes: 21 additions & 21 deletions pkg/sqlgen/sqlgen_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ func TestMetaTableAsCreateTableDDL(t *testing.T) {
FamilyName: famName,
TableName: tblName,
Fields: []schema.NamedFieldType{
{schema.FieldName{Name: "field1"}, schema.FTString},
{schema.FieldName{Name: "field2"}, schema.FTInteger},
{schema.FieldName{Name: "field3"}, schema.FTDecimal},
{Name: schema.FieldName{Name: "field1"}, FieldType: schema.FTString},
{Name: schema.FieldName{Name: "field2"}, FieldType: schema.FTInteger},
{Name: schema.FieldName{Name: "field3"}, FieldType: schema.FTDecimal},
},
KeyFields: schema.PrimaryKey{Fields: []schema.FieldName{{Name: "field1"}}},
}
Expand Down Expand Up @@ -176,10 +176,10 @@ func TestMetaTableUpsertDML(t *testing.T) {
FamilyName: famName,
TableName: tblName,
Fields: []schema.NamedFieldType{
{schema.FieldName{Name: "field1"}, schema.FTString},
{schema.FieldName{Name: "field2"}, schema.FTString},
{schema.FieldName{Name: "field3"}, schema.FTInteger},
{schema.FieldName{Name: "field4"}, schema.FTByteString},
{Name: schema.FieldName{Name: "field1"}, FieldType: schema.FTString},
{Name: schema.FieldName{Name: "field2"}, FieldType: schema.FTString},
{Name: schema.FieldName{Name: "field3"}, FieldType: schema.FTInteger},
{Name: schema.FieldName{Name: "field4"}, FieldType: schema.FTByteString},
},
KeyFields: schema.PrimaryKey{Fields: []schema.FieldName{{Name: "field1"}, {Name: "field2"}}},
}
Expand All @@ -200,9 +200,9 @@ func TestMetaTableUpsertDML(t *testing.T) {
FamilyName: famName,
TableName: tblName,
Fields: []schema.NamedFieldType{
{schema.FieldName{Name: "field1"}, schema.FTString},
{schema.FieldName{Name: "field2"}, schema.FTString},
{schema.FieldName{Name: "field3"}, schema.FTInteger},
{Name: schema.FieldName{Name: "field1"}, FieldType: schema.FTString},
{Name: schema.FieldName{Name: "field2"}, FieldType: schema.FTString},
{Name: schema.FieldName{Name: "field3"}, FieldType: schema.FTInteger},
},
KeyFields: schema.PrimaryKey{Fields: []schema.FieldName{{Name: "field1"}, {Name: "field2"}}},
}
Expand All @@ -222,9 +222,9 @@ func TestMetaTableUpsertDML(t *testing.T) {
FamilyName: famName,
TableName: tblName,
Fields: []schema.NamedFieldType{
{schema.FieldName{Name: "field1"}, schema.FTString},
{schema.FieldName{Name: "field2"}, schema.FTString},
{schema.FieldName{Name: "field3"}, schema.FTInteger},
{Name: schema.FieldName{Name: "field1"}, FieldType: schema.FTString},
{Name: schema.FieldName{Name: "field2"}, FieldType: schema.FTString},
{Name: schema.FieldName{Name: "field3"}, FieldType: schema.FTInteger},
},
KeyFields: schema.PrimaryKey{Fields: []schema.FieldName{{Name: "field1"}, {Name: "field2"}}},
}
Expand Down Expand Up @@ -261,9 +261,9 @@ func TestMetaTableDeleteDML(t *testing.T) {
FamilyName: famName,
TableName: tblName,
Fields: []schema.NamedFieldType{
{schema.FieldName{Name: "field1"}, schema.FTString},
{schema.FieldName{Name: "field2"}, schema.FTByteString},
{schema.FieldName{Name: "field3"}, schema.FTInteger},
{Name: schema.FieldName{Name: "field1"}, FieldType: schema.FTString},
{Name: schema.FieldName{Name: "field2"}, FieldType: schema.FTByteString},
{Name: schema.FieldName{Name: "field3"}, FieldType: schema.FTInteger},
},
KeyFields: schema.PrimaryKey{Fields: []schema.FieldName{{Name: "field1"}, {Name: "field2"}}},
}
Expand All @@ -285,8 +285,8 @@ func TestMetaTableDeleteDML(t *testing.T) {
FamilyName: famName,
TableName: tblName,
Fields: []schema.NamedFieldType{
{schema.FieldName{Name: "field1"}, schema.FTString},
{schema.FieldName{Name: "field2"}, schema.FTString},
{Name: schema.FieldName{Name: "field1"}, FieldType: schema.FTString},
{Name: schema.FieldName{Name: "field2"}, FieldType: schema.FTString},
},
KeyFields: schema.PrimaryKey{Fields: []schema.FieldName{{Name: "field1"}}},
}
Expand All @@ -313,8 +313,8 @@ func TestMetaTableClearTableDDL(t *testing.T) {
FamilyName: famName,
TableName: tblName,
Fields: []schema.NamedFieldType{
{schema.FieldName{Name: "field1"}, schema.FTString},
{schema.FieldName{Name: "field2"}, schema.FTByteString},
{Name: schema.FieldName{Name: "field1"}, FieldType: schema.FTString},
{Name: schema.FieldName{Name: "field2"}, FieldType: schema.FTByteString},
},
KeyFields: schema.PrimaryKey{Fields: []schema.FieldName{{Name: "field1"}}},
}
Expand All @@ -334,7 +334,7 @@ func TestMetaTableDropTableDDL(t *testing.T) {
FamilyName: famName,
TableName: tblName,
Fields: []schema.NamedFieldType{
{schema.FieldName{Name: "field1"}, schema.FTString},
{Name: schema.FieldName{Name: "field1"}, FieldType: schema.FTString},
},
KeyFields: schema.PrimaryKey{Fields: []schema.FieldName{{Name: "field1"}}},
}
Expand Down
1 change: 1 addition & 0 deletions pkg/unsafe/unsafe_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build !race
// +build !race

package unsafe
Expand Down
9 changes: 4 additions & 5 deletions pkg/utils/interface_slice.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,13 @@ import "reflect"
//
// - Returns empty slice if no args are passed
//
// - For a single argument which is of a slice type, the slice
// is converted and returned.
// - For a single argument which is of a slice type, the slice
// is converted and returned.
//
// - For a single argument which is not a slice type, the value is
// returned within a single-element slice.
// - For a single argument which is not a slice type, the value is
// returned within a single-element slice.
//
// - For multiple arguments, returns a slice with all the args
//
func InterfaceSlice(any ...interface{}) []interface{} {
if len(any) == 0 {
return []interface{}{}
Expand Down
1 change: 1 addition & 0 deletions pkg/version/version_go1_12.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build go1.12
// +build go1.12

package version
Expand Down
1 change: 1 addition & 0 deletions tools.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build tools
// +build tools

package ctlstore
Expand Down
Loading