Skip to content

Commit

Permalink
*: fix nakedret lint
Browse files Browse the repository at this point in the history
Signed-off-by: Wei Fu <fuweid89@gmail.com>
  • Loading branch information
fuweid committed Sep 17, 2023
1 parent fb8a315 commit 30dd006
Show file tree
Hide file tree
Showing 9 changed files with 31 additions and 31 deletions.
2 changes: 1 addition & 1 deletion client/pkg/transport/keepalive_listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ type tlsKeepaliveListener struct {
func (l *tlsKeepaliveListener) Accept() (c net.Conn, err error) {
c, err = l.Listener.Accept()
if err != nil {
return
return nil, err
}

c = tls.Server(c, l.config)
Expand Down
24 changes: 12 additions & 12 deletions client/pkg/transport/listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ func newKeepAliveListener(cfg *net.ListenConfig, addr string) (ln net.Listener,
ln, err = net.Listen("tcp", addr)
}
if err != nil {
return
return nil, err
}

return NewKeepAliveListener(ln, "tcp", nil)
Expand Down Expand Up @@ -213,7 +213,7 @@ func SelfCert(lg *zap.Logger, dirpath string, hosts []string, selfSignedCertVali
"cannot generate cert",
zap.Error(err),
)
return
return info, err
}
err = fileutil.TouchDirAll(lg, dirpath)
if err != nil {
Expand All @@ -223,16 +223,16 @@ func SelfCert(lg *zap.Logger, dirpath string, hosts []string, selfSignedCertVali
zap.Error(err),
)
}
return
return info, err
}

certPath, err := filepath.Abs(filepath.Join(dirpath, "cert.pem"))
if err != nil {
return
return info, err
}
keyPath, err := filepath.Abs(filepath.Join(dirpath, "key.pem"))
if err != nil {
return
return info, err
}
_, errcert := os.Stat(certPath)
_, errkey := os.Stat(keyPath)
Expand All @@ -242,7 +242,7 @@ func SelfCert(lg *zap.Logger, dirpath string, hosts []string, selfSignedCertVali
info.ClientCertFile = certPath
info.ClientKeyFile = keyPath
info.selfCert = true
return
return info, err
}

serialNumberLimit := new(big.Int).Lsh(big.NewInt(1), 128)
Expand All @@ -254,7 +254,7 @@ func SelfCert(lg *zap.Logger, dirpath string, hosts []string, selfSignedCertVali
zap.Error(err),
)
}
return
return info, err
}

tmpl := x509.Certificate{
Expand Down Expand Up @@ -292,7 +292,7 @@ func SelfCert(lg *zap.Logger, dirpath string, hosts []string, selfSignedCertVali
zap.Error(err),
)
}
return
return info, err
}

derBytes, err := x509.CreateCertificate(rand.Reader, &tmpl, &tmpl, &priv.PublicKey, priv)
Expand All @@ -303,7 +303,7 @@ func SelfCert(lg *zap.Logger, dirpath string, hosts []string, selfSignedCertVali
zap.Error(err),
)
}
return
return info, err
}

certOut, err := os.Create(certPath)
Expand All @@ -313,7 +313,7 @@ func SelfCert(lg *zap.Logger, dirpath string, hosts []string, selfSignedCertVali
zap.String("path", certPath),
zap.Error(err),
)
return
return info, err
}
pem.Encode(certOut, &pem.Block{Type: "CERTIFICATE", Bytes: derBytes})
certOut.Close()
Expand All @@ -323,7 +323,7 @@ func SelfCert(lg *zap.Logger, dirpath string, hosts []string, selfSignedCertVali

b, err := x509.MarshalECPrivateKey(priv)
if err != nil {
return
return info, err
}
keyOut, err := os.OpenFile(keyPath, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0600)
if err != nil {
Expand All @@ -334,7 +334,7 @@ func SelfCert(lg *zap.Logger, dirpath string, hosts []string, selfSignedCertVali
zap.Error(err),
)
}
return
return info, err
}
pem.Encode(keyOut, &pem.Block{Type: "EC PRIVATE KEY", Bytes: b})
keyOut.Close()
Expand Down
2 changes: 1 addition & 1 deletion etcdctl/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func SplitTestArgs(args []string) (testArgs, appArgs []string) {
appArgs = append(appArgs, arg)
}
}
return
return testArgs, appArgs
}

// TestEmpty is an empty test to avoid no-tests warning.
Expand Down
2 changes: 1 addition & 1 deletion etcdutl/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func SplitTestArgs(args []string) (testArgs, appArgs []string) {
appArgs = append(appArgs, arg)
}
}
return
return testArgs, appArgs
}

// TestEmpty is empty test to avoid no-tests warning.
Expand Down
3 changes: 1 addition & 2 deletions scripts/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -424,8 +424,7 @@ function ineffassign_pass {
}

function nakedret_pass {
# TODO: nakedret should work with -set_exit_status
run_for_modules generic_checker run_go_tool "github.com/alexkohler/nakedret"
run_for_modules generic_checker run_go_tool "github.com/alexkohler/nakedret/cmd/nakedret"
}

function license_header_per_module {
Expand Down
19 changes: 11 additions & 8 deletions server/etcdserver/bootstrap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,21 +222,24 @@ func createDataDir(t *testing.T) (dataDir string, err error) {

// create ${dataDir}/member/snap
if err = os.MkdirAll(datadir.ToSnapDir(dataDir), 0700); err != nil {
return
return "", err
}

// create ${dataDir}/member/wal
err = os.MkdirAll(datadir.ToWalDir(dataDir), 0700)
if err != nil {
return "", err
}

return
return dataDir, nil
}

// prepare data for the test case
func prepareData(cfg config.ServerConfig) (err error) {
var snapshotTerm, snapshotIndex uint64 = 2, 5

if err = createWALFileWithSnapshotRecord(cfg, snapshotTerm, snapshotIndex); err != nil {
return
return err
}

return createSnapshotAndBackendDB(cfg, snapshotTerm, snapshotIndex)
Expand All @@ -245,7 +248,7 @@ func prepareData(cfg config.ServerConfig) (err error) {
func createWALFileWithSnapshotRecord(cfg config.ServerConfig, snapshotTerm, snapshotIndex uint64) (err error) {
var w *wal.WAL
if w, err = wal.Create(cfg.Logger, cfg.WALDir(), []byte("somedata")); err != nil {
return
return err
}

defer func() {
Expand All @@ -262,7 +265,7 @@ func createWALFileWithSnapshotRecord(cfg config.ServerConfig, snapshotTerm, snap
}

if err = w.SaveSnapshot(walSnap); err != nil {
return
return err
}

return w.Save(raftpb.HardState{Term: snapshotTerm, Vote: 3, Commit: snapshotIndex}, nil)
Expand All @@ -283,7 +286,7 @@ func createSnapshotAndBackendDB(cfg config.ServerConfig, snapshotTerm, snapshotI
Term: snapshotTerm,
},
}); err != nil {
return
return err
}

// create snapshot db file: "%016x.snap.db"
Expand All @@ -292,11 +295,11 @@ func createSnapshotAndBackendDB(cfg config.ServerConfig, snapshotTerm, snapshotI
schema.UnsafeUpdateConsistentIndex(be.BatchTx(), snapshotIndex, snapshotTerm)
schema.MustUnsafeSaveConfStateToBackend(cfg.Logger, be.BatchTx(), &confState)
if err = be.Close(); err != nil {
return
return err
}
sdb := filepath.Join(cfg.SnapDir(), fmt.Sprintf("%016x.snap.db", snapshotIndex))
if err = os.Rename(cfg.BackendPath(), sdb); err != nil {
return
return err
}

// create backend db file
Expand Down
2 changes: 1 addition & 1 deletion server/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func SplitTestArgs(args []string) (testArgs, appArgs []string) {
appArgs = append(appArgs, arg)
}
}
return
return testArgs, appArgs
}

func TestEmpty(t *testing.T) {}
Expand Down
2 changes: 1 addition & 1 deletion server/storage/wal/wal.go
Original file line number Diff line number Diff line change
Expand Up @@ -553,7 +553,7 @@ func (w *WAL) ReadAll() (metadata []byte, state raftpb.HardState, ents []raftpb.
// create encoder (chain crc with the decoder), enable appending
w.encoder, err = newFileEncoder(w.tail().File, w.decoder.LastCRC())
if err != nil {
return
return nil, state, nil, err
}
}
w.decoder = nil
Expand Down
6 changes: 2 additions & 4 deletions tests/robustness/validate/operations.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,15 @@ func validateOperationsAndVisualize(t *testing.T, lg *zap.Logger, operations []p
switch result {
case porcupine.Illegal:
t.Error("Linearization failed")
return
case porcupine.Unknown:
t.Error("Linearization has timed out")
return
case porcupine.Ok:
t.Log("Linearization success")
lg.Info("Validating serializable operations")
validateSerializableOperations(t, operations, eventHistory)
default:
t.Fatalf("Unknown Linearization")
}
lg.Info("Validating serializable operations")
validateSerializableOperations(t, operations, eventHistory)
return visualize
}

Expand Down

0 comments on commit 30dd006

Please sign in to comment.