Skip to content

Commit

Permalink
Start refactoring for now linter rules
Browse files Browse the repository at this point in the history
  • Loading branch information
kopi-solarpunk committed May 13, 2024
1 parent 7960a49 commit e45a8b6
Show file tree
Hide file tree
Showing 45 changed files with 146 additions and 170 deletions.
1 change: 0 additions & 1 deletion pkg/api/accounting_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ func TestAccountingInfo(t *testing.T) {
if !reflect.DeepEqual(got, expected) {
t.Errorf("got accounting: %v, expected: %v", got, expected)
}

}

func TestAccountingInfoError(t *testing.T) {
Expand Down
8 changes: 3 additions & 5 deletions pkg/api/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ func newTestServer(t *testing.T, o testServerOptions) (*http.Client, *websocket.
erc20 := erc20mock.New(o.Erc20Opts...)
backend := backendmock.New(o.BackendOpts...)

var extraOpts = api.ExtraOptions{
extraOpts := api.ExtraOptions{
TopologyDriver: topologyDriver,
Accounting: acc,
Pseudosettle: recipient,
Expand Down Expand Up @@ -344,7 +344,7 @@ func TestParseName(t *testing.T) {
const bzzHash = "89c17d0d8018a19057314aa035e61c9d23c47581a61dd3a79a7839692c617e4d"
log := log.Noop

var errInvalidNameOrAddress = errors.New("invalid name or bzz address")
errInvalidNameOrAddress := errors.New("invalid name or bzz address")

testCases := []struct {
desc string
Expand Down Expand Up @@ -531,9 +531,7 @@ func TestPostageHeaderError(t *testing.T) {
func TestOptions(t *testing.T) {
t.Parallel()

var (
client, _, _, _ = newTestServer(t, testServerOptions{})
)
client, _, _, _ := newTestServer(t, testServerOptions{})
for _, tc := range []struct {
endpoint string
expectedMethods string // expectedMethods contains HTTP methods like GET, POST, HEAD, PATCH, DELETE, OPTIONS. These are in alphabetical sorted order
Expand Down
1 change: 0 additions & 1 deletion pkg/api/balances_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,6 @@ func TestConsumedBalances(t *testing.T) {
if !equalBalances(got, expected) {
t.Errorf("got balances: %v, expected: %v", got, expected)
}

}

func TestConsumedError(t *testing.T) {
Expand Down
1 change: 0 additions & 1 deletion pkg/api/bytes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,6 @@ func TestBytesInvalidStamp(t *testing.T) {
jsonhttptest.WithRequestBody(bytes.NewReader(content)),
)
})

}

func TestBytesUploadHandlerInvalidInputs(t *testing.T) {
Expand Down
9 changes: 4 additions & 5 deletions pkg/api/bzz.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,6 @@ import (
"strings"
"time"

"github.com/opentracing/opentracing-go"
"github.com/opentracing/opentracing-go/ext"
olog "github.com/opentracing/opentracing-go/log"

"github.com/ethereum/go-ethereum/common"
"github.com/ethersphere/bee/v2/pkg/feeds"
"github.com/ethersphere/bee/v2/pkg/file/joiner"
Expand All @@ -37,6 +33,9 @@ import (
"github.com/ethersphere/bee/v2/pkg/tracing"
"github.com/ethersphere/langos"
"github.com/gorilla/mux"
"github.com/opentracing/opentracing-go"
"github.com/opentracing/opentracing-go/ext"
olog "github.com/opentracing/opentracing-go/log"
)

// The size of buffer used for prefetching content with Langos when not using erasure coding
Expand Down Expand Up @@ -394,7 +393,7 @@ FETCH:
// go on normally.
if !feedDereferenced {
if l, err := s.manifestFeed(ctx, m); err == nil {
//we have a feed manifest here
// we have a feed manifest here
ch, cur, _, err := l.At(ctx, time.Now().Unix(), 0)
if err != nil {
logger.Debug("bzz download: feed lookup failed", "error", err)
Expand Down
3 changes: 0 additions & 3 deletions pkg/api/bzz_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -934,7 +934,6 @@ func TestInvalidBzzParams(t *testing.T) {
jsonhttptest.WithRequestBody(tr),
jsonhttptest.WithRequestHeader(api.ContentTypeHeader, api.ContentTypeTar),
)

})

t.Run("batch exists", func(t *testing.T) {
Expand Down Expand Up @@ -962,7 +961,6 @@ func TestInvalidBzzParams(t *testing.T) {
jsonhttptest.WithRequestBody(tr),
jsonhttptest.WithRequestHeader(api.ContentTypeHeader, api.ContentTypeTar),
)

})

t.Run("batch not found", func(t *testing.T) {
Expand Down Expand Up @@ -1057,7 +1055,6 @@ func TestInvalidBzzParams(t *testing.T) {
address := "f30c0aa7e9e2a0ef4c9b1b750ebfeaeb7c7c24da700bb089da19a46e3677824b"
jsonhttptest.Request(t, client, http.MethodGet, fmt.Sprintf("/bzz/%s/", address), http.StatusNotFound)
})

}

// TestDirectUploadBzz tests that the direct upload endpoint give correct error message in dev mode
Expand Down
1 change: 0 additions & 1 deletion pkg/api/chequebook.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (
"github.com/ethersphere/bee/v2/pkg/postage/postagecontract"
"github.com/ethersphere/bee/v2/pkg/settlement/swap"
"github.com/ethersphere/bee/v2/pkg/settlement/swap/chequebook"

"github.com/ethersphere/bee/v2/pkg/swarm"
"github.com/gorilla/mux"
)
Expand Down
6 changes: 0 additions & 6 deletions pkg/api/chequebook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
"github.com/ethersphere/bee/v2/pkg/settlement/swap/chequebook"
"github.com/ethersphere/bee/v2/pkg/settlement/swap/chequebook/mock"
swapmock "github.com/ethersphere/bee/v2/pkg/settlement/swap/mock"

"github.com/ethersphere/bee/v2/pkg/swarm"
)

Expand Down Expand Up @@ -427,7 +426,6 @@ func TestChequebookLastCheques(t *testing.T) {
if !LastChequesEqual(got, expected) {
t.Fatalf("Got: \n %+v \n\n Expected: \n %+v \n\n", got, expected)
}

}

func TestChequebookLastChequesPeer(t *testing.T) {
Expand All @@ -442,7 +440,6 @@ func TestChequebookLastChequesPeer(t *testing.T) {
sig := make([]byte, 65)

lastSentChequeFunc := func(swarm.Address) (*chequebook.SignedCheque, error) {

sig := make([]byte, 65)

lastSentCheque := &chequebook.SignedCheque{
Expand All @@ -458,7 +455,6 @@ func TestChequebookLastChequesPeer(t *testing.T) {
}

lastReceivedChequeFunc := func(swarm.Address) (*chequebook.SignedCheque, error) {

lastReceivedCheque := &chequebook.SignedCheque{
Cheque: chequebook.Cheque{
Beneficiary: beneficiary0,
Expand Down Expand Up @@ -498,7 +494,6 @@ func TestChequebookLastChequesPeer(t *testing.T) {
if !reflect.DeepEqual(got, expected) {
t.Fatalf("Got: \n %+v \n\n Expected: \n %+v \n\n", got, expected)
}

}

func TestChequebookCashout(t *testing.T) {
Expand Down Expand Up @@ -780,7 +775,6 @@ func Test_chequebookLastPeerHandler_invalidInputs(t *testing.T) {
}

func LastChequesEqual(a, b *api.ChequebookLastChequesResponse) bool {

var state bool

for akeys := range a.LastCheques {
Expand Down
3 changes: 1 addition & 2 deletions pkg/api/chunk.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,9 @@ import (
"strconv"

"github.com/ethersphere/bee/v2/pkg/cac"
"github.com/ethersphere/bee/v2/pkg/soc"

"github.com/ethersphere/bee/v2/pkg/jsonhttp"
"github.com/ethersphere/bee/v2/pkg/postage"
"github.com/ethersphere/bee/v2/pkg/soc"
"github.com/ethersphere/bee/v2/pkg/storage"
"github.com/ethersphere/bee/v2/pkg/swarm"
"github.com/gorilla/mux"
Expand Down
9 changes: 4 additions & 5 deletions pkg/api/chunk_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,15 @@ import (
"testing"
"time"

"github.com/ethersphere/bee/v2/pkg/api"
"github.com/ethersphere/bee/v2/pkg/jsonhttp"
"github.com/ethersphere/bee/v2/pkg/jsonhttp/jsonhttptest"
"github.com/ethersphere/bee/v2/pkg/log"
mockbatchstore "github.com/ethersphere/bee/v2/pkg/postage/batchstore/mock"
mockpost "github.com/ethersphere/bee/v2/pkg/postage/mock"
"github.com/ethersphere/bee/v2/pkg/spinlock"
mockstorer "github.com/ethersphere/bee/v2/pkg/storer/mock"

"github.com/ethersphere/bee/v2/pkg/api"
"github.com/ethersphere/bee/v2/pkg/jsonhttp"
"github.com/ethersphere/bee/v2/pkg/jsonhttp/jsonhttptest"
testingc "github.com/ethersphere/bee/v2/pkg/storage/testing"
mockstorer "github.com/ethersphere/bee/v2/pkg/storer/mock"
"github.com/ethersphere/bee/v2/pkg/swarm"
)

Expand Down
4 changes: 2 additions & 2 deletions pkg/api/cors_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,6 @@ func TestCORSHeaders(t *testing.T) {
}
})
}

}

// TestCors tests whether CORs work correctly with OPTIONS method
Expand All @@ -135,7 +134,8 @@ func TestCors(t *testing.T) {
{
endpoint: "bzz",
expectedMethods: "POST",
}, {
},
{
endpoint: "bzz/0101011",
expectedMethods: "GET, HEAD",
},
Expand Down
1 change: 0 additions & 1 deletion pkg/api/debugstorage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,4 @@ func TestDebugStorage(t *testing.T) {
jsonhttptest.WithExpectedJSONResponse(want),
)
})

}
1 change: 0 additions & 1 deletion pkg/api/dirs.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,6 @@ func storeDir(
errorFilename string,
rLevel redundancy.Level,
) (swarm.Address, error) {

logger := tracing.NewLoggerWithTraceID(ctx, log)
loggerV1 := logger.V(1).Build()

Expand Down
7 changes: 2 additions & 5 deletions pkg/api/dirs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,6 @@ func TestDirs(t *testing.T) {
// check error document
validateAltPath(t, "_non_existent_file_path_", errorDocumentPath)
}

}
t.Run(tc.name, func(t *testing.T) {
t.Run("tar_upload", func(t *testing.T) {
Expand Down Expand Up @@ -542,7 +541,7 @@ func tarFiles(t *testing.T, files []f) *bytes.Buffer {
// create tar header and write it
hdr := &tar.Header{
Name: filePath,
Mode: 0600,
Mode: 0o600,
Size: int64(len(file.data)),
}
if err := tw.WriteHeader(hdr); err != nil {
Expand Down Expand Up @@ -571,7 +570,7 @@ func tarEmptyDir(t *testing.T) *bytes.Buffer {

hdr := &tar.Header{
Name: "empty/",
Mode: 0600,
Mode: 0o600,
}

if err := tw.WriteHeader(hdr); err != nil {
Expand Down Expand Up @@ -604,11 +603,9 @@ func multipartFiles(t *testing.T, files []f) (*bytes.Buffer, string) {
contentType := file.header.Get(api.ContentTypeHeader)
if contentType != "" {
hdr.Set(api.ContentTypeHeader, contentType)

}
if len(file.data) > 0 {
hdr.Set(api.ContentLengthHeader, strconv.Itoa(len(file.data)))

}
part, err := mw.CreatePart(hdr)
if err != nil {
Expand Down
8 changes: 4 additions & 4 deletions pkg/api/dynamicaccess.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"encoding/hex"
"encoding/json"
"errors"
"fmt"
"io"
"net/http"
"time"
Expand Down Expand Up @@ -114,7 +115,6 @@ func (s *Service) actDecryptionHandler() func(h http.Handler) http.Handler {
h.ServeHTTP(w, r.WithContext(setAddressInContext(ctx, reference)))
})
}

}

// actEncryptionHandler is a middleware that encrypts the given address using the publisher's public key
Expand All @@ -133,7 +133,7 @@ func (s *Service) actEncryptionHandler(
if err != nil {
logger.Debug("act failed to encrypt reference", "error", err)
logger.Error(nil, "act failed to encrypt reference")
return swarm.ZeroAddress, err
return swarm.ZeroAddress, fmt.Errorf("act failed to encrypt reference: %w", err)
}
// only need to upload history and kvs if a new history is created,
// meaning that the publsher uploaded to the history for the first time
Expand All @@ -142,13 +142,13 @@ func (s *Service) actEncryptionHandler(
if err != nil {
logger.Debug("done split keyvaluestore failed", "error", err)
logger.Error(nil, "done split keyvaluestore failed")
return swarm.ZeroAddress, err
return swarm.ZeroAddress, fmt.Errorf("done split keyvaluestore failed: %w", err)
}
err = putter.Done(historyReference)
if err != nil {
logger.Debug("done split history failed", "error", err)
logger.Error(nil, "done split history failed")
return swarm.ZeroAddress, err
return swarm.ZeroAddress, fmt.Errorf("done split history failed: %w", err)
}
}

Expand Down
Loading

0 comments on commit e45a8b6

Please sign in to comment.