mirror of https://github.com/VinGarcia/ksql.git
Since golint is deprecated we upgraded to staticheck instead
parent
1eca192677
commit
e5d1de061b
|
@ -17,8 +17,8 @@ jobs:
|
||||||
run: go vet ./...
|
run: go vet ./...
|
||||||
- name: Check go version
|
- name: Check go version
|
||||||
run: go version
|
run: go version
|
||||||
- name: Run golint
|
- name: Run linters
|
||||||
run: go get golang.org/x/lint/golint && bash -c "$(go env GOPATH)/bin/golint -set_exit_status -min_confidence 0.9 ./..."
|
run: go install honnef.co/go/tools/cmd/staticcheck@latest && bash -c "$(go env GOPATH)/bin/staticcheck ./..."
|
||||||
- name: Run Tests
|
- name: Run Tests
|
||||||
run: ./scripts/run-all-tests.sh
|
run: ./scripts/run-all-tests.sh
|
||||||
- name: Run Coverage
|
- name: Run Coverage
|
||||||
|
|
10
Makefile
10
Makefile
|
@ -18,22 +18,22 @@ bench:
|
||||||
@echo "Benchmark executed on commit: $$(git rev-parse HEAD)"
|
@echo "Benchmark executed on commit: $$(git rev-parse HEAD)"
|
||||||
|
|
||||||
lint: setup
|
lint: setup
|
||||||
@$(GOBIN)/golint -set_exit_status -min_confidence 0.9 $(path) $(args)
|
@$(GOBIN)/staticcheck $(path) $(args)
|
||||||
@go vet $(path) $(args)
|
@go vet $(path) $(args)
|
||||||
@make --no-print-directory -C benchmarks
|
@make --no-print-directory -C benchmarks
|
||||||
@echo "Golint & Go Vet found no problems on your code!"
|
@echo "StaticCheck & Go Vet found no problems on your code!"
|
||||||
|
|
||||||
gen: mock
|
gen: mock
|
||||||
mock: setup
|
mock: setup
|
||||||
$(GOBIN)/mockgen -package=exampleservice -source=contracts.go -destination=examples/example_service/mocks.go
|
$(GOBIN)/mockgen -package=exampleservice -source=contracts.go -destination=examples/example_service/mocks.go
|
||||||
|
|
||||||
setup: $(GOBIN)/richgo $(GOBIN)/golint $(GOBIN)/mockgen
|
setup: $(GOBIN)/richgo $(GOBIN)/staticcheck $(GOBIN)/mockgen
|
||||||
|
|
||||||
$(GOBIN)/richgo:
|
$(GOBIN)/richgo:
|
||||||
go get github.com/kyoh86/richgo
|
go get github.com/kyoh86/richgo
|
||||||
|
|
||||||
$(GOBIN)/golint:
|
$(GOBIN)/staticcheck:
|
||||||
go get golang.org/x/lint
|
go install honnef.co/go/tools/cmd/staticcheck@latest
|
||||||
|
|
||||||
$(GOBIN)/mockgen:
|
$(GOBIN)/mockgen:
|
||||||
@# (Gomock is used on examples/example_service)
|
@# (Gomock is used on examples/example_service)
|
||||||
|
|
|
@ -2,5 +2,5 @@
|
||||||
GOBIN=$(shell go env GOPATH)/bin
|
GOBIN=$(shell go env GOPATH)/bin
|
||||||
|
|
||||||
lint:
|
lint:
|
||||||
@$(GOBIN)/golint -set_exit_status -min_confidence 0.9 ./...
|
@$(GOBIN)/staticcheck ./...
|
||||||
@go vet ./...
|
@go vet ./...
|
||||||
|
|
2
ksql.go
2
ksql.go
|
@ -495,7 +495,7 @@ func (c DB) insertWithLastInsertID(
|
||||||
|
|
||||||
if !tID.ConvertibleTo(fieldType) {
|
if !tID.ConvertibleTo(fieldType) {
|
||||||
return fmt.Errorf(
|
return fmt.Errorf(
|
||||||
"Can't convert last insert id of type int64 into field `%s` of type %v",
|
"can't convert last insert id of type int64 into field `%s` of type %v",
|
||||||
idName,
|
idName,
|
||||||
fieldType,
|
fieldType,
|
||||||
)
|
)
|
||||||
|
|
|
@ -381,11 +381,6 @@ func TestCallFunctionWithRows(t *testing.T) {
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("should report error if the input function is invalid", func(t *testing.T) {
|
t.Run("should report error if the input function is invalid", func(t *testing.T) {
|
||||||
type User struct {
|
|
||||||
Name string `ksql:"name"`
|
|
||||||
Age int `ksql:"age"`
|
|
||||||
}
|
|
||||||
|
|
||||||
err := CallFunctionWithRows(func() {}, []map[string]interface{}{{
|
err := CallFunctionWithRows(func() {}, []map[string]interface{}{{
|
||||||
"name": "fake-name1",
|
"name": "fake-name1",
|
||||||
"age": 42,
|
"age": 42,
|
||||||
|
|
|
@ -381,11 +381,6 @@ func TestCallFunctionWithRows(t *testing.T) {
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("should report error if the input function is invalid", func(t *testing.T) {
|
t.Run("should report error if the input function is invalid", func(t *testing.T) {
|
||||||
type User struct {
|
|
||||||
Name string `ksql:"name"`
|
|
||||||
Age int `ksql:"age"`
|
|
||||||
}
|
|
||||||
|
|
||||||
err := CallFunctionWithRows(func() {}, []map[string]interface{}{{
|
err := CallFunctionWithRows(func() {}, []map[string]interface{}{{
|
||||||
"name": "fake-name1",
|
"name": "fake-name1",
|
||||||
"age": 42,
|
"age": 42,
|
||||||
|
|
14
main_test.go
14
main_test.go
|
@ -1,14 +0,0 @@
|
||||||
package ksql
|
|
||||||
|
|
||||||
import (
|
|
||||||
"encoding/json"
|
|
||||||
"fmt"
|
|
||||||
)
|
|
||||||
|
|
||||||
func toJSON(i interface{}) []byte {
|
|
||||||
rawJSON, err := json.Marshal(i)
|
|
||||||
if err != nil {
|
|
||||||
panic(fmt.Sprintf("error marshalling %v during test", i))
|
|
||||||
}
|
|
||||||
return rawJSON
|
|
||||||
}
|
|
|
@ -0,0 +1 @@
|
||||||
|
checks = ["all","-S1002","-ST1000","-ST1003"]
|
|
@ -37,8 +37,6 @@ type address struct {
|
||||||
Country string `json:"country"`
|
Country string `json:"country"`
|
||||||
}
|
}
|
||||||
|
|
||||||
var postsTable = NewTable("posts")
|
|
||||||
|
|
||||||
type post struct {
|
type post struct {
|
||||||
ID int `ksql:"id"`
|
ID int `ksql:"id"`
|
||||||
UserID uint `ksql:"user_id"`
|
UserID uint `ksql:"user_id"`
|
||||||
|
@ -1936,7 +1934,6 @@ func QueryChunksTest(
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
func(missingReturnType []user) {
|
func(missingReturnType []user) {
|
||||||
return
|
|
||||||
},
|
},
|
||||||
func(users []user) string {
|
func(users []user) string {
|
||||||
return ""
|
return ""
|
||||||
|
@ -2348,47 +2345,6 @@ func shiftErrSlice(errs *[]error) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func getUsersByID(db DBAdapter, dialect Dialect, resultsPtr *[]user, ids ...uint) error {
|
|
||||||
placeholders := make([]string, len(ids))
|
|
||||||
params := make([]interface{}, len(ids))
|
|
||||||
for i := range ids {
|
|
||||||
params[i] = ids[i]
|
|
||||||
placeholders[i] = dialect.Placeholder(i)
|
|
||||||
}
|
|
||||||
|
|
||||||
results := []user{}
|
|
||||||
rows, err := db.QueryContext(
|
|
||||||
context.TODO(),
|
|
||||||
fmt.Sprintf(
|
|
||||||
"SELECT id, name, age FROM users WHERE id IN (%s)",
|
|
||||||
strings.Join(placeholders, ", "),
|
|
||||||
),
|
|
||||||
params...,
|
|
||||||
)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
defer rows.Close()
|
|
||||||
|
|
||||||
for rows.Next() {
|
|
||||||
var u user
|
|
||||||
err = rows.Scan(&u.ID, &u.Name, &u.Age)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
results = append(results, u)
|
|
||||||
}
|
|
||||||
if rows.Err() != nil {
|
|
||||||
return rows.Err()
|
|
||||||
}
|
|
||||||
if err := rows.Close(); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
*resultsPtr = results
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func getUserByID(db DBAdapter, dialect Dialect, result *user, id uint) error {
|
func getUserByID(db DBAdapter, dialect Dialect, result *user, id uint) error {
|
||||||
rows, err := db.QueryContext(context.TODO(), `SELECT id, name, age, address FROM users WHERE id=`+dialect.Placeholder(0), id)
|
rows, err := db.QueryContext(context.TODO(), `SELECT id, name, age, address FROM users WHERE id=`+dialect.Placeholder(0), id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
Loading…
Reference in New Issue