Skip to content

Commit

Permalink
enable golangci
Browse files Browse the repository at this point in the history
Signed-off-by: Angelo De Caro <[email protected]>
  • Loading branch information
adecaro committed Dec 18, 2024
1 parent 1083089 commit c694b83
Show file tree
Hide file tree
Showing 20 changed files with 100 additions and 230 deletions.
58 changes: 58 additions & 0 deletions .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
name: golangci-lint

on:
push:
branches:
- master
- main
pull_request:
# The branches below must be a subset of the branches above
branches: [ main ]

permissions:
contents: read
# Optional: allow read access to pull request. Use with `only-new-issues` option.
# pull-requests: read

jobs:
golangci:
name: lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version-file: "go.mod"
cache: false
- name: golangci-lint
uses: golangci/golangci-lint-action@v6
with:
# Require: The version of golangci-lint to use.
# When `install-mode` is `binary` (default) the value can be v1.2 or v1.2.3 or `latest` to use the latest version.
# When `install-mode` is `goinstall` the value can be v1.2.3, `latest`, or the hash of a commit.
version: v1.60.1

# Optional: working directory, useful for monorepos
# working-directory: somedir

# Optional: golangci-lint command line arguments.
#
# Note: By default, the `.golangci.yml` file should be at the root of the repository.
# The location of the configuration file can be changed by using `--config=`
args: --timeout=30m

# Optional: show only new issues if it's a pull request. The default value is `false`.
# only-new-issues: true

# Optional: if set to true, then all caching functionality will be completely disabled,
# takes precedence over all other caching options.
# skip-cache: true

# Optional: if set to true, then the action won't cache or restore ~/go/pkg.
# skip-pkg-cache: true

# Optional: if set to true, then the action won't cache or restore ~/.cache/go-build.
# skip-build-cache: true

# Optional: The mode to install golangci-lint. It can be 'binary' or 'goinstall'.
# install-mode: "goinstall"
6 changes: 3 additions & 3 deletions integration/nwo/fsc/fsc.go
Original file line number Diff line number Diff line change
Expand Up @@ -558,7 +558,7 @@ func (p *Platform) fscNodeCommand(node *node2.Replica, command common.Command, t
if p.Context.IgnoreSigHUP() {
cmd.Env = append(cmd.Env, "FSCNODE_SIGHUP_IGNORE=true")
}
//cmd.SysProcAttr = &syscall.SysProcAttr{Setpgid: true}
// cmd.SysProcAttr = &syscall.SysProcAttr{Setpgid: true}

if p.Topology.GRPCLogging {
cmd.Env = append(cmd.Env, "GRPC_GO_LOG_VERBOSITY_LEVEL=2")
Expand Down Expand Up @@ -812,7 +812,7 @@ func (p *Platform) GetAdminSigningIdentity(peer *node2.Peer) (view.SigningIdenti

func (p *Platform) listTLSCACertificates() []string {
fileName2Path := make(map[string]string)
filepath.Walk(filepath.Join(p.Context.RootDir(), "fsc", "crypto"), func(path string, info os.FileInfo, err error) error {
Expect(filepath.Walk(filepath.Join(p.Context.RootDir(), "fsc", "crypto"), func(path string, info os.FileInfo, err error) error {
if err != nil {
return err
}
Expand All @@ -822,7 +822,7 @@ func (p *Platform) listTLSCACertificates() []string {
fileName2Path[info.Name()] = path
}
return nil
})
})).ToNot(HaveOccurred())

var tlsCACertificates []string
for _, path := range fileName2Path {
Expand Down
6 changes: 3 additions & 3 deletions integration/nwo/fsc/fsc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ var _ = Describe("EndToEnd", func() {

ExpectedMainOne, err := os.ReadFile("./testdata/main/main.go.output")
Expect(err).ToNot(HaveOccurred())
Expect(string(buf.Bytes())).To(BeEquivalentTo(string(ExpectedMainOne)))
Expect(buf.String()).To(BeEquivalentTo(string(ExpectedMainOne)))
// Expect(os.WriteFile("./testdata/main/main.go.output", buf.Bytes(), 0777)).ToNot(HaveOccurred())
})

Expand Down Expand Up @@ -89,8 +89,8 @@ var _ = Describe("EndToEnd", func() {

ExpectedMainOne, err := os.ReadFile("./testdata/main/main.go.output")
Expect(err).ToNot(HaveOccurred())
Expect(string(buf.Bytes())).To(BeEquivalentTo(string(ExpectedMainOne)))
//Expect(os.WriteFile("./testdata/main/main.go.output", buf.Bytes(), 0777)).ToNot(HaveOccurred())
Expect(buf.String()).To(BeEquivalentTo(string(ExpectedMainOne)))
// Expect(os.WriteFile("./testdata/main/main.go.output", buf.Bytes(), 0777)).ToNot(HaveOccurred())
})

})
Expand Down
12 changes: 6 additions & 6 deletions platform/common/core/generic/vault/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -377,8 +377,8 @@ func TTestShardLikeCommit(t *testing.T, ddb VersionedPersistence, vp artifactsPr
}
rwsb.ReadSet.Add(ns, k1, versionBlockTxNumToBytes(35, 1))
rwsb.ReadSet.Add(ns, k2, versionBlockTxNumToBytes(37, 2))
rwsb.WriteSet.Add(ns, k1, []byte("k1FromTxidInvalid"))
rwsb.WriteSet.Add(ns, k2, []byte("k2FromTxidInvalid"))
assert.NoError(t, rwsb.WriteSet.Add(ns, k1, []byte("k1FromTxidInvalid")))
assert.NoError(t, rwsb.WriteSet.Add(ns, k2, []byte("k2FromTxidInvalid")))
marshaller := vp.NewMarshaller()
rwsBytes, err := marshaller.Marshal("pineapple", rwsb)
assert.NoError(t, err)
Expand Down Expand Up @@ -423,8 +423,8 @@ func TTestShardLikeCommit(t *testing.T, ddb VersionedPersistence, vp artifactsPr
}
rwsb.ReadSet.Add(ns, k1, versionBlockTxNumToBytes(35, 1))
rwsb.ReadSet.Add(ns, k2, versionBlockTxNumToBytes(37, 3))
rwsb.WriteSet.Add(ns, k1, []byte("k1FromTxidValid"))
rwsb.WriteSet.Add(ns, k2, []byte("k2FromTxidValid"))
assert.NoError(t, rwsb.WriteSet.Add(ns, k1, []byte("k1FromTxidValid")))
assert.NoError(t, rwsb.WriteSet.Add(ns, k2, []byte("k2FromTxidValid")))
rwsBytes, err = marshaller.Marshal("pineapple", rwsb)
assert.NoError(t, err)

Expand Down Expand Up @@ -561,7 +561,7 @@ func TTestMerge(t *testing.T, ddb VersionedPersistence, vp artifactsProvider) {
rwsb.ReadSet.Add(ns, k1, versionBlockTxNumToBytes(35, 1))
rwsb.ReadSet.Add(ns, ne2Key, nil)
rwsb.WriteSet.Add(ns, k1, []byte("newv1"))
rwsb.MetaWriteSet.Add(ns, k1, map[string][]byte{"k1": []byte("v1")})
assert.NoError(t, rwsb.MetaWriteSet.Add(ns, k1, map[string][]byte{"k1": []byte("v1")}))
m := vp.NewMarshaller()
rwsBytes, err := m.Marshal("pineapple", rwsb)
assert.NoError(t, err)
Expand Down Expand Up @@ -631,7 +631,7 @@ func TTestMerge(t *testing.T, ddb VersionedPersistence, vp artifactsProvider) {
MetaWrites: map[string]KeyedMetaWrites{},
},
}
rwsb.MetaWriteSet.Add(ns, k3, map[string][]byte{"k": []byte("v")})
assert.NoError(t, rwsb.MetaWriteSet.Add(ns, k3, map[string][]byte{"k": []byte("v")}))
rwsBytes, err = m.Marshal("pineapple", rwsb)
assert.NoError(t, err)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ func testTXIDStore(t *testing.T, store *SimpleTXIDStore[vc]) {
}
assert.Equal(t, []string{"txid1", "txid2", "txid10", "txid12", "txid21", "txid100", "txid200", "txid1025"}, txids)

it, err = store.Iterator(&driver.SeekPos{Txid: "boh"})
_, err = store.Iterator(&driver.SeekPos{Txid: "boh"})
assert.EqualError(t, err, "txid boh was not found")

it, err = store.Iterator(&driver.SeekPos{Txid: "txid12"})
Expand Down
4 changes: 2 additions & 2 deletions platform/fabric/core/generic/msp/idemix/provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -260,9 +260,9 @@ func TestProvider_DeserializeSigner(t *testing.T) {
assert.NoError(t, verifier.Verify(msg, sigma))

// Try to deserialize id2 with provider for id, must fail
signer, err = p.DeserializeSigner(id2)
_, err = p.DeserializeSigner(id2)
assert.Error(t, err)
verifier, err = p.DeserializeVerifier(id2)
_, err = p.DeserializeVerifier(id2)
assert.NoError(t, err)

// this must work
Expand Down
2 changes: 1 addition & 1 deletion platform/view/services/client/view/cmd/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
)

func TestConfig(t *testing.T) {
rand.Seed(time.Now().UnixNano())
rand.New(rand.NewSource(time.Now().UnixNano()))
configFilePath := filepath.Join(os.TempDir(), fmt.Sprintf("config-%d.yaml", rand.Int()))
fmt.Println(configFilePath)
t.Run("save and load a config", func(t *testing.T) {
Expand Down
4 changes: 2 additions & 2 deletions platform/view/services/comm/test_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ func SessionsTestRound(t *testing.T, bootstrapNode *HostNode, node *HostNode) {
assert.NoError(t, err)
assert.NotNil(t, session)

session.Send([]byte("ciaoback"))
assert.NoError(t, session.Send([]byte("ciaoback")))

sessionMsgs := session.Receive()
msg = <-sessionMsgs
Expand Down Expand Up @@ -156,7 +156,7 @@ func SessionsForMPCTestRound(t *testing.T, bootstrapNode *HostNode, node *HostNo
msg := <-sessionMsgs
assert.Equal(t, []byte("ciao"), msg.Payload)

session.Send([]byte("ciaoback"))
assert.NoError(t, session.Send([]byte("ciaoback")))

session.Close()

Expand Down
6 changes: 3 additions & 3 deletions platform/view/services/db/dbtest/bench.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ var (
)

func ReadExisting(b *testing.B, db driver.TransactionalVersionedPersistence) {
db.BeginUpdate()
db.SetState(namespace, key, driver.VersionedValue{Raw: payload})
db.Commit()
assert.NoError(b, db.BeginUpdate())
assert.NoError(b, db.SetState(namespace, key, driver.VersionedValue{Raw: payload}))
assert.NoError(b, db.Commit())

var v []byte
b.ResetTimer()
Expand Down
27 changes: 0 additions & 27 deletions platform/view/services/db/driver/badger/badger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,33 +142,6 @@ const (
compositeKeyNamespace = "\x00"
)

func validateCompositeKeyAttribute(str string) error {
if !utf8.ValidString(str) {
return errors.Errorf("not a valid utf8 string: [%x]", str)
}
for index, runeValue := range str {
if runeValue == minUnicodeRuneValue || runeValue == maxUnicodeRuneValue {
return errors.Errorf(`input contain unicode %#U starting at position [%d]. %#U and %#U are not allowed in the input attribute of a composite key`,
runeValue, index, minUnicodeRuneValue, maxUnicodeRuneValue)
}
}
return nil
}

func createCompositeKey(objectType string, attributes []string) (string, error) {
if err := validateCompositeKeyAttribute(objectType); err != nil {
return "", err
}
ck := compositeKeyNamespace + objectType + fmt.Sprint(minUnicodeRuneValue)
for _, att := range attributes {
if err := validateCompositeKeyAttribute(att); err != nil {
return "", err
}
ck += att + fmt.Sprint(minUnicodeRuneValue)
}
return ck, nil
}

func TestAutoCleaner(t *testing.T) {
dbpath := filepath.Join(tempDir, "DB-autocleaner")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,6 @@ import (
"github.com/stretchr/testify/assert"
)

//go:generate counterfeiter -o mocks/config.go -fake-name Config . config

type config interface {
db.Config
}

var tempDir string

func TestRangeQueriesBadger(t *testing.T) {
Expand Down
8 changes: 0 additions & 8 deletions platform/view/services/events/simple/eventbus_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,13 +115,9 @@ var _ = Describe("Event system", func() {
event := &fakes.Event{}
event.TopicReturns("topicAAA")
event.MessageReturns("HelloWorld")

var listeners []*fakes.Listener

for i := 0; i < 10000; i++ {
l := &fakes.Listener{}
alice.Subscribe(fmt.Sprintf("topic_%d", i), l)
listeners = append(listeners, l)
Expect(len(notifier.handlers)).To(Equal(i + 1))
}
})
Expand All @@ -130,13 +126,9 @@ var _ = Describe("Event system", func() {
event := &fakes.Event{}
event.TopicReturns("topicAAA")
event.MessageReturns("HelloWorld")

var listeners []*fakes.Listener

for i := 0; i < 10000; i++ {
l := &fakes.Listener{}
alice.Subscribe("topic", l)
listeners = append(listeners, l)
Expect(len(notifier.handlers)).To(Equal(1))
Expect(len(notifier.handlers["topic"])).To(Equal(i + 1))
}
Expand Down
Empty file.
Empty file.
63 changes: 0 additions & 63 deletions platform/view/services/grpc/connection_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,13 @@ SPDX-License-Identifier: Apache-2.0
package grpc

import (
"context"
"crypto/tls"
"fmt"
"net"
"os"
"path/filepath"
"sync/atomic"
"testing"
"time"

"github.com/pkg/errors"
"github.com/stretchr/testify/assert"

"github.com/hyperledger-labs/fabric-smart-client/platform/view/services/grpc/testpb"
)

const (
Expand Down Expand Up @@ -111,59 +104,3 @@ func TestCredentialSupport(t *testing.T) {
assert.Equal(t, "1.2", creds.Info().SecurityVersion,
"Expected Security version to be 1.2")
}

type srv struct {
address string
*GRPCServer
caCert []byte
serviced uint32
}

func (s *srv) assertServiced(t *testing.T) {
assert.Equal(t, uint32(1), atomic.LoadUint32(&s.serviced))
atomic.StoreUint32(&s.serviced, 0)
}

func (s *srv) EmptyCall(context.Context, *testpb.Empty) (*testpb.Empty, error) {
atomic.StoreUint32(&s.serviced, 1)
return &testpb.Empty{}, nil
}

func newServer(org string) *srv {
certs := map[string][]byte{
"ca.crt": nil,
"server.crt": nil,
"server.key": nil,
}
for suffix := range certs {
fName := filepath.Join("testdata", "impersonation", org, suffix)
cert, err := os.ReadFile(fName)
if err != nil {
panic(errors.Errorf("Failed reading %s: %v", fName, err))
}
certs[suffix] = cert
}
l, err := net.Listen("tcp", "127.0.0.1:0")
if err != nil {
panic(errors.Errorf("Failed to create listener: %v", err))
}
gSrv, err := NewGRPCServerFromListener(l, ServerConfig{
ConnectionTimeout: 250 * time.Millisecond,
SecOpts: SecureOptions{
Certificate: certs["server.crt"],
Key: certs["server.key"],
UseTLS: true,
},
})
if err != nil {
panic(errors.Errorf("Failed starting gRPC server: %v", err))
}
s := &srv{
address: l.Addr().String(),
caCert: certs["ca.crt"],
GRPCServer: gSrv,
}
testpb.RegisterTestServiceServer(gSrv.Server(), s)
go s.Start()
return s
}
Loading

0 comments on commit c694b83

Please sign in to comment.