Skip to content
This repository has been archived by the owner on Mar 11, 2021. It is now read-only.

WIP: Addressing findings from linters/checkers/ci #2300

Open
wants to merge 77 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
77 commits
Select commit Hold shift + click to select a range
9835e47
golint: context.Context should be the first parameter of a function
kwk Sep 26, 2018
89c261b
structcheck: dbPq is unused
kwk Sep 26, 2018
caf7616
structcheck: authzConfig is unused
kwk Sep 26, 2018
2ebb838
varcheck: updateWorkItemLinkPayload is unused
kwk Sep 26, 2018
4a77852
varcheck: createWorkItemLinkTypePayload is unused
kwk Sep 26, 2018
72f0391
varcheck: eventSingle is unused
kwk Sep 26, 2018
a9a2ff9
varcheck: testCtrl is unused
kwk Sep 26, 2018
85ff229
varcheck: workItemBoardColumnData is unused
kwk Sep 26, 2018
ff90c83
varcheck: relationWorkItemType is unused
kwk Sep 26, 2018
4528e0f
varcheck: filterSingle is unused
kwk Sep 26, 2018
b12f314
varcheck: updateWorkItemLinkCategoryPayload is unused
kwk Sep 26, 2018
ab03635
remove unused newUpdateWorkItemLinkPayload and newUpdateWorkItemLinkP…
kwk Sep 26, 2018
8287541
varcheck: updateWorkItemLinkTypePayload is unused
kwk Sep 26, 2018
95ff06a
deadcode: generateSearchQuery is unused
kwk Sep 26, 2018
fa98041
deadcode: strPtrIsNilOrContentIsEqual is unused
kwk Sep 26, 2018
c31cbe8
deadcode: generateEnvKey is unused
kwk Sep 26, 2018
7e6ff5b
deadcode: checkGetKeycloakEndpointSetByEnvVaribaleOK is unused
kwk Sep 26, 2018
5d1d207
deadcode: diff is unused
kwk Sep 26, 2018
8847ed3
deadcode: diff is unused
kwk Sep 26, 2018
27a1303
remove unused CreateWorkItemLinkCategoryPayload and UpdateWorkItemLin…
kwk Sep 26, 2018
6780e2d
fixup
kwk Sep 26, 2018
ab99cd7
fix comment to IncludeBacklogTotalCount
kwk Sep 26, 2018
1cde513
errcheck: Error return value of result.Scan is not checked
kwk Sep 26, 2018
b843890
errcheck: Error return value of tx.Rollback/tx.Commit is not checked
kwk Sep 26, 2018
2002f59
errcheck: Error return value of r.Stop is not checked
kwk Sep 26, 2018
10e08e3
errcheck: Error return value of recordCodebases.Stop is not checked
kwk Sep 26, 2018
ee09935
errcheck: Error return value of db.ScanRows is not checked
kwk Sep 26, 2018
13f1616
errcheck: Error return value of rows2.Scan is not checked
kwk Sep 26, 2018
3fe312b
errcheck: Error return value of db.ScanRows is not checked
kwk Sep 26, 2018
b5c92c0
errcheck: Error return value of db.ScanRows is not checked
kwk Sep 26, 2018
9623714
errcheck: Error return value of rows2.Scan is not checked
kwk Sep 26, 2018
dd194e4
errcheck: Error return value of s.repo.Create is not checked
kwk Sep 26, 2018
e1835c6
errcheck: Error return value of s.repo.Create is not checked
kwk Sep 26, 2018
7d942fc
errcheck: Error return value of s.repo.Create is not checked
kwk Sep 26, 2018
292713d
errcheck: Error return value of s.repo.Create is not checked
kwk Sep 26, 2018
e248562
errcheck:
kwk Sep 26, 2018
f89798e
errcheck:
kwk Sep 26, 2018
141ce7a
errcheck: Error return value of set.Parse is not checked
kwk Sep 26, 2018
1d3a8a9
errcheck: Error return value of api.IterateResources is not checked
kwk Sep 26, 2018
4bd2cda
errcheck: Error return value of res.IterateActions is not checked
kwk Sep 26, 2018
f5f1007
errcheck: Error return value of ctxWr.WriteHeader is not checked
kwk Sep 26, 2018
2c181d8
errcheck: Error return value of rg is not checked
kwk Sep 26, 2018
5cb9c5c
errcheck: Error return value of set.Parse is not checked
kwk Sep 26, 2018
da2892b
errcheck: Error return value of ctxWr.WriteHeader is not checked
kwk Sep 26, 2018
c30e173
errcheck: Error return value of set.Parse is not checked
kwk Sep 26, 2018
9703b37
errcheck: Error return value of ctxWr.WriteHeader is not checked
kwk Sep 26, 2018
3c7fd05
errcheck: Error return value of repo.Create is not checked
kwk Sep 26, 2018
1ea28b7
errcheck: Error return value of repo.Create is not checked
kwk Sep 26, 2018
2dd1e2d
errcheck: Error return value of io.ReadFull is not checked
kwk Sep 26, 2018
7ea4f4a
errcheck: Error return value of hash.Write is not checked
kwk Sep 26, 2018
6e592eb
errcheck: Error return value of reqMetric.Write is not checked
kwk Sep 26, 2018
e1f842f
errcheck: Error return value of buf.ReadFrom is not checked
kwk Sep 26, 2018
b1aa156
errcheck: Error return value of ioutil.ReadAll is not checked
kwk Sep 26, 2018
6314978
errcheck: Error return value of rows2.Scan is not checked
kwk Sep 26, 2018
efd06ec
errcheck: Error return value of json.Unmarshal is not checked
kwk Sep 26, 2018
f7bfe06
errcheck: Error return value of h.Write is not checked
kwk Sep 26, 2018
4e457be
errcheck: Error return value of r.deleteLink is not checked
kwk Sep 26, 2018
9dc9435
errcheck: Error return value of r.deleteLink is not checked
kwk Sep 26, 2018
dde21f7
errcheck: Error return value of s.repo.Save is not checked
kwk Sep 26, 2018
68b4917
errcheck: Error return value of json.Unmarshal is not checked
kwk Sep 26, 2018
241aff9
errcheck: Error return value of json.Unmarshal is not checked
kwk Sep 26, 2018
0b57704
errcheck: Error return value of result.Scan is not checked
kwk Sep 26, 2018
2239ca7
fixup
kwk Sep 26, 2018
4f0b0a7
ineffassign: ineffectual assignment to err
kwk Sep 26, 2018
4354587
ineffassign: ineffectual assignment to err
kwk Sep 26, 2018
c1c5f72
ineffassign: ineffectual assignment to err
kwk Sep 26, 2018
d465c96
ineffassign: ineffectual assignment to mustHaveIDs
kwk Sep 26, 2018
a381903
ineffassign: ineffectual assignment to mustHaveIDs
kwk Sep 26, 2018
cd3a09a
ineffassign: ineffectual assignment to status
kwk Sep 26, 2018
91731e3
ineffassign: ineffectual assignment to statusKey
kwk Sep 26, 2018
ee69987
ineffassign: ineffectual assignment to tracker4
kwk Sep 26, 2018
ca79b5b
golint: codebase/che/client.go:451:2: const IdeUrlRel should be IdeUR…
kwk Sep 26, 2018
d9f6ec5
lint: IGNORE jsonapi/error_handler.go:61:12: should not use basic typ…
kwk Sep 26, 2018
47c6a6d
fixup
kwk Sep 26, 2018
2ad3d2d
fixup: make TestForwardRequest work without errors
kwk Sep 27, 2018
47faa4a
fixup and use non-simply-typed value for context.WithValue()
kwk Sep 27, 2018
f1f4481
fixup
kwk Sep 27, 2018
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
7 changes: 5 additions & 2 deletions application/application_db_calls_bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"testing"

_ "github.com/lib/pq"
"github.com/stretchr/testify/require"

"github.com/fabric8-services/fabric8-wit/application"
"github.com/fabric8-services/fabric8-wit/gormapplication"
Expand Down Expand Up @@ -125,7 +126,8 @@ func (s *BenchDbOperations) BenchmarkGormSelectSpaceNameRaw() {
defer result.Close()
for result.Next() {
var wit string
result.Scan(&wit)
err := result.Scan(&wit)
require.NoError(s.B(), err)
names = append(names, wit)
}
}
Expand Down Expand Up @@ -195,11 +197,12 @@ func (s *BenchDbOperations) BenchmarkGormSelectSpaceRaw() {
defer result.Close()
for result.Next() {
var sp space.Space
result.Scan(
err := result.Scan(
&sp.Version,
&sp.Name,
&sp.Description,
&sp.OwnerID)
require.NoError(s.B(), err)
sps = append(sps, sp)
}
}
Expand Down
19 changes: 16 additions & 3 deletions application/transaction.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package application

import (
"context"
"runtime/debug"
"time"

Expand Down Expand Up @@ -46,15 +47,27 @@ func Transactional(db DB, todo func(f Application) error) error {
case err := <-errorChan:
if err != nil {
log.Debug(nil, map[string]interface{}{"error": err}, "Rolling back the transaction...")
tx.Rollback()
errRollback := tx.Rollback()
if errRollback != nil {
log.Error(context.Background(), map[string]interface{}{
"errRollback": errors.WithStack(errRollback),
"err": errors.WithStack(err),
}, "failed to rollback transaction: %+v", errRollback)
}
log.Error(nil, map[string]interface{}{
"err": err,
}, "database transaction failed!")
return errors.WithStack(err)
}

tx.Commit()
log.Debug(nil, nil, "Commit the transaction!")
log.Debug(nil, nil, "Committing the transaction!")
errCommit := tx.Commit()
if errCommit != nil {
log.Error(context.Background(), map[string]interface{}{
"errCommit": errors.WithStack(errCommit),
}, "failed to commit transaction: %+v", errCommit)
}

return nil
case <-txTimeout:
log.Debug(nil, nil, "Rolling back the transaction...")
Expand Down
2 changes: 0 additions & 2 deletions application/transaction_bench_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package application_test

import (
"database/sql"
"testing"

_ "github.com/lib/pq"
Expand All @@ -17,7 +16,6 @@ type BenchTransactional struct {
gormbench.DBBenchSuite
repo space.Repository
appDB application.DB
dbPq *sql.DB
}

func BenchmarkRunTransactional(b *testing.B) {
Expand Down
45 changes: 36 additions & 9 deletions codebase/analytics-gemini/client_blackbox_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@ func TestRegister(t *testing.T) {
testrecorder.WithJWTMatcher("../../test/jwt/public_key.pem"),
)
require.NoError(t, err)
defer r.Stop()
defer func() {
err := r.Stop()
require.NoError(t, err)
}()

httpClient := &http.Client{
Transport: r.Transport,
Expand All @@ -50,7 +53,10 @@ func TestRegister(t *testing.T) {
"../../test/data/gemini-scan/register-401",
)
require.NoError(t, err)
defer r.Stop()
defer func() {
err := r.Stop()
require.NoError(t, err)
}()

httpClient := &http.Client{
Transport: r.Transport,
Expand Down Expand Up @@ -102,7 +108,10 @@ func TestRegister(t *testing.T) {
testrecorder.WithJWTMatcher("../../test/jwt/public_key.pem"),
)
require.NoError(t, err)
defer r.Stop()
defer func() {
err := r.Stop()
require.NoError(t, err)
}()

httpClient := &http.Client{
Transport: r.Transport,
Expand All @@ -128,7 +137,10 @@ func TestRegister(t *testing.T) {
testrecorder.WithJWTMatcher("../../test/jwt/public_key.pem"),
)
require.NoError(t, err)
defer r.Stop()
defer func() {
err := r.Stop()
require.NoError(t, err)
}()

httpClient := &http.Client{
Transport: r.Transport,
Expand Down Expand Up @@ -165,7 +177,10 @@ func TestDeRegister(t *testing.T) {
"../../test/data/gemini-scan/deregister-200",
)
require.NoError(t, err)
defer r.Stop()
defer func() {
err := r.Stop()
require.NoError(t, err)
}()

httpClient := &http.Client{Transport: r.Transport}
cli := gemini.NewScanRepoClient(geminiURL, httpClient, codebaseURL, httpClient, false)
Expand All @@ -187,15 +202,21 @@ func TestDeRegister(t *testing.T) {
"../../test/data/gemini-scan/deregister-call-gemini-codebases-200",
)
require.NoError(t, err)
defer recordCodebases.Stop()
defer func() {
err := recordCodebases.Stop()
require.NoError(t, err)
}()
codebaseClient := &http.Client{Transport: recordCodebases.Transport}

recordGemini, err := testrecorder.New(
"../../test/data/gemini-scan/deregister-call-gemini-200",
testrecorder.WithJWTMatcher("../../test/jwt/public_key.pem"),
)
require.NoError(t, err)
defer recordGemini.Stop()
defer func() {
err := recordGemini.Stop()
require.NoError(t, err)
}()
geminiClient := &http.Client{Transport: recordGemini.Transport}

cli := gemini.NewScanRepoClient(geminiURL, geminiClient, codebaseURL, codebaseClient, false)
Expand Down Expand Up @@ -242,7 +263,10 @@ func TestDeRegister(t *testing.T) {
"../../test/data/gemini-scan/deregister-400",
)
require.NoError(t, err)
defer r.Stop()
defer func() {
err := r.Stop()
require.NoError(t, err)
}()

httpClient := &http.Client{Transport: r.Transport}
cli := gemini.NewScanRepoClient(geminiURL, httpClient, codebaseURL, httpClient, false)
Expand All @@ -263,7 +287,10 @@ func TestDeRegister(t *testing.T) {
"../../test/data/gemini-scan/deregister-bad-output",
)
require.NoError(t, err)
defer r.Stop()
defer func() {
err := r.Stop()
require.NoError(t, err)
}()

httpClient := &http.Client{Transport: r.Transport}
cli := gemini.NewScanRepoClient(geminiURL, httpClient, codebaseURL, httpClient, false)
Expand Down
2 changes: 1 addition & 1 deletion codebase/che/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@ func (w WorkspaceResponse) GetHrefByRelOfWorkspaceLink(rel string) string {

// Following const define commonly used WorkspaceLink rel
const (
IdeUrlRel = "ide url"
IdeURLRel = "ide url"
SelfLinkRel = "self link"
)

Expand Down
18 changes: 14 additions & 4 deletions codebase/codebase.go
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,10 @@ func (m *GormCodebaseRepository) List(ctx context.Context, spaceID uuid.UUID, st

for rows.Next() {
value := Codebase{}
db.ScanRows(rows, &value)
err := db.ScanRows(rows, &value)
if err != nil {
return nil, 0, errs.Wrapf(err, "failed to scan codebase rows")
}
if first {
first = false
if err = rows.Scan(columnValues...); err != nil {
Expand All @@ -300,10 +303,14 @@ func (m *GormCodebaseRepository) List(ctx context.Context, spaceID uuid.UUID, st
rows2, err := orgDB.Rows()
defer closeable.Close(ctx, rows2)
if err != nil {
return nil, 0, err
return nil, 0, errs.WithStack(err)
}
rows2.Next() // count(*) will always return a row
rows2.Scan(&count)
err = rows2.Scan(&count)
if err != nil {
return nil, 0, errs.WithStack(err)
}

}
return result, count, nil
}
Expand Down Expand Up @@ -384,7 +391,10 @@ func (m *GormCodebaseRepository) SearchByURL(ctx context.Context, url string, st
first := true
for rows.Next() {
value := Codebase{}
db.ScanRows(rows, &value)
err := db.ScanRows(rows, &value)
if err != nil {
return nil, 0, errors.NewInternalError(ctx, err)
}
if first {
first = false
if err = rows.Scan(columnValues...); err != nil {
Expand Down
12 changes: 9 additions & 3 deletions comment/comment_repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,10 @@ func (m *GormCommentRepository) List(ctx context.Context, parentID uuid.UUID, st

for rows.Next() {
value := &Comment{}
db.ScanRows(rows, value)
err := db.ScanRows(rows, value)
if err != nil {
return nil, 0, errors.NewInternalError(ctx, err)
}
if first {
first = false
if err = rows.Scan(columnValues...); err != nil {
Expand All @@ -191,10 +194,13 @@ func (m *GormCommentRepository) List(ctx context.Context, parentID uuid.UUID, st
rows2, err := orgDB.Rows()
defer closeable.Close(ctx, rows2)
if err != nil {
return nil, 0, err
return nil, 0, errs.WithStack(err)
}
rows2.Next() // count(*) will always return a row
rows2.Scan(&count)
err = rows2.Scan(&count)
if err != nil {
return nil, 0, errors.NewInternalError(ctx, err)
}
}
return result, count, nil
}
Expand Down
20 changes: 13 additions & 7 deletions comment/comment_repository_blackbox_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,16 +56,18 @@ func (s *TestCommentRepository) TestCreateCommentWithParentComment() {
// parent comment
fxt := tf.NewTestFixture(s.T(), s.DB, tf.Identities(1))
parentComment := newComment(uuid.NewV4(), "Test A", rendering.SystemMarkupMarkdown)
s.repo.Create(s.Ctx, parentComment, fxt.Identities[0].ID)
err := s.repo.Create(s.Ctx, parentComment, fxt.Identities[0].ID)
require.NoError(s.T(), err)
// child comments
childComment := newComment(uuid.NewV4(), "Test Child A", rendering.SystemMarkupMarkdown)
childComment.ParentCommentID = id.NullUUID{
UUID: parentComment.ID,
Valid: true,
}
// when
s.repo.Create(s.Ctx, childComment, fxt.Identities[0].ID)
err = s.repo.Create(s.Ctx, childComment, fxt.Identities[0].ID)
// then
require.NoError(s.T(), err)
require.NotNil(s.T(), childComment.ID, "Comment was not created, ID nil")
require.NotNil(s.T(), childComment.CreatedAt, "Comment was not created")
require.False(s.T(), childComment.CreatedAt.After(time.Now()), "Comment was not created, CreatedAt after Now()")
Expand All @@ -74,7 +76,7 @@ func (s *TestCommentRepository) TestCreateCommentWithParentComment() {
// now retrieving the stored child comment again and see if the parent reference was stored
var resultComment *comment.Comment
// when
resultComment, err := s.repo.Load(s.Ctx, childComment.ID)
resultComment, err = s.repo.Load(s.Ctx, childComment.ID)
// then
require.NoError(s.T(), err)
require.NotNil(s.T(), resultComment.ParentCommentID, "Parent comment id was not set, ID nil")
Expand All @@ -86,8 +88,9 @@ func (s *TestCommentRepository) TestCreateCommentWithMarkup() {
fxt := tf.NewTestFixture(s.T(), s.DB, tf.Identities(1))
comment := newComment(uuid.NewV4(), "Test A", rendering.SystemMarkupMarkdown)
// when
s.repo.Create(s.Ctx, comment, fxt.Identities[0].ID)
err := s.repo.Create(s.Ctx, comment, fxt.Identities[0].ID)
// then
require.NoError(s.T(), err)
assert.NotNil(s.T(), comment.ID, "Comment was not created, ID nil")
require.NotNil(s.T(), comment.CreatedAt, "Comment was not created?")
assert.False(s.T(), comment.CreatedAt.After(time.Now()), "Comment was not created, CreatedAt after Now()?")
Expand All @@ -98,8 +101,9 @@ func (s *TestCommentRepository) TestCreateCommentWithoutMarkup() {
fxt := tf.NewTestFixture(s.T(), s.DB, tf.Identities(1))
comment := newComment(uuid.NewV4(), "Test A", "")
// when
s.repo.Create(s.Ctx, comment, fxt.Identities[0].ID)
err := s.repo.Create(s.Ctx, comment, fxt.Identities[0].ID)
// then
require.NoError(s.T(), err)
assert.NotNil(s.T(), comment.ID, "Comment was not created, ID nil")
require.NotNil(s.T(), comment.CreatedAt, "Comment was not created?")
assert.False(s.T(), comment.CreatedAt.After(time.Now()), "CreatedAt after Now()?")
Expand All @@ -116,7 +120,8 @@ func (s *TestCommentRepository) TestSaveCommentWithMarkup() {
// when
comment.Body = "Test AB"
comment.Markup = rendering.SystemMarkupMarkdown
s.repo.Save(s.Ctx, comment, comment.Creator)
err := s.repo.Save(s.Ctx, comment, comment.Creator)
require.NoError(s.T(), err)
offset := 0
limit := 1
comments, _, err := s.repo.List(s.Ctx, comment.ParentID, &offset, &limit)
Expand All @@ -137,7 +142,8 @@ func (s *TestCommentRepository) TestSaveCommentWithoutMarkup() {
// when
comment.Body = "Test AB"
comment.Markup = ""
s.repo.Save(s.Ctx, comment, comment.Creator)
err := s.repo.Save(s.Ctx, comment, comment.Creator)
require.NoError(s.T(), err)
offset := 0
limit := 1
comments, _, err := s.repo.List(s.Ctx, comment.ParentID, &offset, &limit)
Expand Down
26 changes: 0 additions & 26 deletions configuration/configuration_blackbox_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"fmt"
"os"
"strconv"
"strings"
"testing"

"net/http"
Expand All @@ -13,7 +12,6 @@ import (

"github.com/fabric8-services/fabric8-wit/configuration"
"github.com/fabric8-services/fabric8-wit/resource"
"github.com/satori/go.uuid"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
Expand Down Expand Up @@ -183,30 +181,6 @@ func TestGetMaxHeaderSizeSetByEnvVaribaleOK(t *testing.T) {
assert.Equal(t, envValue, viperValue)
}

func generateEnvKey(yamlKey string) string {
return "F8_" + strings.ToUpper(strings.Replace(yamlKey, ".", "_", -1))
}

func checkGetKeycloakEndpointSetByEnvVaribaleOK(t *testing.T, envName string, getEndpoint func(req *http.Request) (string, error)) {
envValue := uuid.NewV4().String()
env := os.Getenv(envName)
defer func() {
os.Setenv(envName, env)
resetConfiguration(defaultValuesConfigFilePath)
}()

os.Setenv(envName, envValue)
resetConfiguration(defaultValuesConfigFilePath)

url, err := getEndpoint(reqLong)
require.NoError(t, err)
require.Equal(t, envValue, url)

url, err = getEndpoint(reqShort)
require.NoError(t, err)
require.Equal(t, envValue, url)
}

func TestGetDeploymentsTimeoutDefault(t *testing.T) {
resource.Require(t, resource.UnitTest)
viperValue := config.GetDeploymentsHTTPTimeoutSeconds()
Expand Down
Loading