Skip to content

Commit

Permalink
Rename NoOp to Nop (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
nhatthm authored Feb 2, 2022
1 parent 385b280 commit 010b1a7
Show file tree
Hide file tree
Showing 15 changed files with 43 additions and 43 deletions.
4 changes: 2 additions & 2 deletions begin.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ type beginFuncMiddleware func(next beginFunc) beginFunc
// beginFunc is a callback for beginFunc.
type beginFunc func(ctx context.Context, opts driver.TxOptions) (driver.Tx, error)

// noOpBegin pings nothing.
func noOpBegin(_ context.Context, _ driver.TxOptions) (driver.Tx, error) {
// nopBegin pings nothing.
func nopBegin(_ context.Context, _ driver.TxOptions) (driver.Tx, error) {
return nil, nil
}

Expand Down
10 changes: 5 additions & 5 deletions begin_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,17 @@ func BenchmarkBeginStats(b *testing.B) {

begin := chainBeginFuncMiddlewares([]beginFuncMiddleware{
beginStats(r),
}, noOpBegin)
}, nopBegin)

for i := 0; i < b.N; i++ {
_, _ = begin(context.Background(), driver.TxOptions{}) // nolint: errcheck
}
}

func TestNoOpBegin(t *testing.T) {
func TestNopBegin(t *testing.T) {
t.Parallel()

result, err := noOpBegin(context.Background(), driver.TxOptions{})
result, err := nopBegin(context.Background(), driver.TxOptions{})

assert.Nil(t, result)
assert.NoError(t, err)
Expand Down Expand Up @@ -84,7 +84,7 @@ func TestEnsureBegin(t *testing.T) {
func TestChainBeginFuncMiddlewares_NoMiddleware(t *testing.T) {
t.Parallel()

begin := chainBeginFuncMiddlewares(nil, noOpBegin)
begin := chainBeginFuncMiddlewares(nil, nopBegin)

result, err := begin(context.Background(), driver.TxOptions{})

Expand Down Expand Up @@ -158,7 +158,7 @@ func TestBeginStats(t *testing.T) {
},
{
scenario: "no error",
begin: noOpBegin,
begin: nopBegin,
expected: `[
{
"Name": "db.sql.client.calls{service.name=otelsql,instrumentation.name=begin_test,db.instance=test,db.operation=go.sql.begin,db.sql.status=OK,db.system=other_sql}",
Expand Down
2 changes: 1 addition & 1 deletion conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ func wrapConn(parent driver.Conn, opt connConfig) driver.Conn {

func makeConn(parent driver.Conn, cfg connConfig) conn {
c := conn{
ping: noOpPing,
ping: nopPing,
exec: skippedExecContext,
query: skippedQueryContext,
close: parent.Close,
Expand Down
4 changes: 2 additions & 2 deletions exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ type execContextFuncMiddleware func(next execContextFunc) execContextFunc

type execContextFunc func(ctx context.Context, query string, args []driver.NamedValue) (driver.Result, error)

// noOpExecContext executes nothing.
func noOpExecContext(_ context.Context, _ string, _ []driver.NamedValue) (driver.Result, error) {
// nopExecContext executes nothing.
func nopExecContext(_ context.Context, _ string, _ []driver.NamedValue) (driver.Result, error) {
return nil, nil
}

Expand Down
10 changes: 5 additions & 5 deletions exec_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,17 @@ func BenchmarkExecStats(b *testing.B) {

exec := chainExecContextFuncMiddlewares([]execContextFuncMiddleware{
execStats(r, metricMethodExec),
}, noOpExecContext)
}, nopExecContext)

for i := 0; i < b.N; i++ {
_, _ = exec(context.Background(), "", nil) // nolint: errcheck
}
}

func TestNoOpExecContext(t *testing.T) {
func TestNopExecContext(t *testing.T) {
t.Parallel()

result, err := noOpExecContext(context.Background(), "", nil)
result, err := nopExecContext(context.Background(), "", nil)

assert.Nil(t, result)
assert.NoError(t, err)
Expand All @@ -58,7 +58,7 @@ func TestSkippedExecContext(t *testing.T) {
func TestChainExecContextFuncMiddlewares_NoMiddleware(t *testing.T) {
t.Parallel()

exec := chainExecContextFuncMiddlewares(nil, noOpExecContext)
exec := chainExecContextFuncMiddlewares(nil, nopExecContext)

result, err := exec(context.Background(), "", nil)

Expand Down Expand Up @@ -132,7 +132,7 @@ func TestExecStats(t *testing.T) {
},
{
scenario: "no error",
execer: noOpExecContext,
execer: nopExecContext,
expected: `[
{
"Name": "db.sql.client.calls{service.name=otelsql,instrumentation.name=exec_test,db.instance=test,db.operation=go.sql.exec,db.sql.status=OK,db.system=other_sql}",
Expand Down
4 changes: 2 additions & 2 deletions internal/test/assert/assert.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ func EqualJSON(expect string) Func {
}
}

// NoOp creates a new Func that does not assert anything.
func NoOp() Func {
// Nop creates a new Func that does not assert anything.
func Nop() Func {
return func(_ assert.TestingT, _ string, _ ...interface{}) bool {
return true
}
Expand Down
4 changes: 2 additions & 2 deletions ping.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ type pingFuncMiddleware func(next pingFunc) pingFunc
// pingFunc is a callback for pingFunc.
type pingFunc func(ctx context.Context) error

// noOpPing pings nothing.
func noOpPing(_ context.Context) error {
// nopPing pings nothing.
func nopPing(_ context.Context) error {
return nil
}

Expand Down
10 changes: 5 additions & 5 deletions ping_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,25 +29,25 @@ func BenchmarkPingStats(b *testing.B) {

ping := chainPingFuncMiddlewares([]pingFuncMiddleware{
pingStats(r),
}, noOpPing)
}, nopPing)

for i := 0; i < b.N; i++ {
_ = ping(context.Background()) // nolint: errcheck
}
}

func TestNoOpPing(t *testing.T) {
func TestNopPing(t *testing.T) {
t.Parallel()

err := noOpPing(context.Background())
err := nopPing(context.Background())

assert.NoError(t, err)
}

func TestChainPingFuncMiddlewares_NoMiddleware(t *testing.T) {
t.Parallel()

f := chainPingFuncMiddlewares(nil, noOpPing)
f := chainPingFuncMiddlewares(nil, nopPing)

err := f(context.Background())

Expand Down Expand Up @@ -119,7 +119,7 @@ func TestPingStats(t *testing.T) {
},
{
scenario: "no error",
ping: noOpPing,
ping: nopPing,
expected: `[
{
"Name": "db.sql.client.calls{service.name=otelsql,instrumentation.name=ping_test,db.instance=test,db.operation=go.sql.ping,db.sql.status=OK,db.system=other_sql}",
Expand Down
4 changes: 2 additions & 2 deletions prepare.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ type prepareContextFuncMiddleware func(next prepareContextFunc) prepareContextFu

type prepareContextFunc func(ctx context.Context, query string) (driver.Stmt, error)

// noOpPrepareContext prepares nothing.
func noOpPrepareContext(_ context.Context, _ string) (driver.Stmt, error) {
// nopPrepareContext prepares nothing.
func nopPrepareContext(_ context.Context, _ string) (driver.Stmt, error) {
return nil, nil
}

Expand Down
10 changes: 5 additions & 5 deletions prepare_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,17 @@ func BenchmarkPrepareStats(b *testing.B) {

prepare := chainPrepareContextFuncMiddlewares([]prepareContextFuncMiddleware{
prepareStats(r),
}, noOpPrepareContext)
}, nopPrepareContext)

for i := 0; i < b.N; i++ {
_, _ = prepare(context.Background(), "") // nolint: errcheck
}
}

func TestNoOpPrepareContext(t *testing.T) {
func TestNopPrepareContext(t *testing.T) {
t.Parallel()

result, err := noOpPrepareContext(context.Background(), "")
result, err := nopPrepareContext(context.Background(), "")

assert.Nil(t, result)
assert.NoError(t, err)
Expand Down Expand Up @@ -84,7 +84,7 @@ func TestEnsurePrepareContext(t *testing.T) {
func TestChainPrepareContextFuncMiddlewares_NoMiddleware(t *testing.T) {
t.Parallel()

prepare := chainPrepareContextFuncMiddlewares(nil, noOpPrepareContext)
prepare := chainPrepareContextFuncMiddlewares(nil, nopPrepareContext)

result, err := prepare(context.Background(), "")

Expand Down Expand Up @@ -158,7 +158,7 @@ func TestPrepareStats(t *testing.T) {
},
{
scenario: "no error",
prepare: noOpPrepareContext,
prepare: nopPrepareContext,
expected: `[
{
"Name": "db.sql.client.calls{service.name=otelsql,instrumentation.name=prepare_test,db.instance=test,db.operation=go.sql.prepare,db.sql.status=OK,db.system=other_sql}",
Expand Down
4 changes: 2 additions & 2 deletions query.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ type queryContextFuncMiddleware func(next queryContextFunc) queryContextFunc

type queryContextFunc func(ctx context.Context, query string, args []driver.NamedValue) (driver.Rows, error)

// noOpQueryContext queries nothing.
func noOpQueryContext(_ context.Context, _ string, _ []driver.NamedValue) (driver.Rows, error) {
// nopQueryContext queries nothing.
func nopQueryContext(_ context.Context, _ string, _ []driver.NamedValue) (driver.Rows, error) {
return nil, nil
}

Expand Down
10 changes: 5 additions & 5 deletions query_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,17 @@ func BenchmarkQueryStats(b *testing.B) {

query := chainQueryContextFuncMiddlewares([]queryContextFuncMiddleware{
queryStats(r, metricMethodQuery),
}, noOpQueryContext)
}, nopQueryContext)

for i := 0; i < b.N; i++ {
_, _ = query(context.Background(), "", nil) // nolint: errcheck
}
}

func TestNoOpQueryContext(t *testing.T) {
func TestNopQueryContext(t *testing.T) {
t.Parallel()

result, err := noOpQueryContext(context.Background(), "", nil)
result, err := nopQueryContext(context.Background(), "", nil)

assert.Nil(t, result)
assert.NoError(t, err)
Expand All @@ -58,7 +58,7 @@ func TestSkippedQueryContext(t *testing.T) {
func TestChainQueryContextFuncMiddlewares_NoMiddleware(t *testing.T) {
t.Parallel()

query := chainQueryContextFuncMiddlewares(nil, noOpQueryContext)
query := chainQueryContextFuncMiddlewares(nil, nopQueryContext)

result, err := query(context.Background(), "", nil)

Expand Down Expand Up @@ -132,7 +132,7 @@ func TestQueryStats(t *testing.T) {
},
{
scenario: "no error",
query: noOpQueryContext,
query: nopQueryContext,
expected: `[
{
"Name": "db.sql.client.calls{service.name=otelsql,instrumentation.name=query_test,db.instance=test,db.operation=go.sql.query,db.sql.status=OK,db.system=other_sql}",
Expand Down
4 changes: 2 additions & 2 deletions statement.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ func makeStmtExecFunc(parent driver.Stmt, execContextFuncMiddlewares []execConte
func makeStmtExecContextFunc(parent driver.Stmt, execContextFuncMiddlewares []execContextFuncMiddleware) execContextFunc {
execer, ok := parent.(driver.StmtExecContext)
if !ok {
return noOpExecContext
return nopExecContext
}

return chainExecContextFuncMiddlewares(execContextFuncMiddlewares, func(ctx context.Context, _ string, args []driver.NamedValue) (driver.Result, error) {
Expand All @@ -228,7 +228,7 @@ func makeStmtQueryFunc(parent driver.Stmt, queryContextFuncMiddlewares []queryCo
func makeStmtQueryContextFunc(parent driver.Stmt, queryContextFuncMiddlewares []queryContextFuncMiddleware) queryContextFunc {
queryer, ok := parent.(driver.StmtQueryContext)
if !ok {
return noOpQueryContext
return nopQueryContext
}

return chainQueryContextFuncMiddlewares(queryContextFuncMiddlewares, func(ctx context.Context, _ string, args []driver.NamedValue) (driver.Rows, error) {
Expand Down
2 changes: 1 addition & 1 deletion transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func wrapTx(ctx context.Context, parent driver.Tx, r methodRecorder, t methodTra
}
}

func noOpTxFunc() error {
func nopTxFunc() error {
return nil
}

Expand Down
4 changes: 2 additions & 2 deletions transaction_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
func TestChainTxFuncMiddlewares_NoMiddleware(t *testing.T) {
t.Parallel()

f := chainTxFuncMiddlewares(nil, noOpTxFunc)
f := chainTxFuncMiddlewares(nil, nopTxFunc)

err := f()

Expand Down Expand Up @@ -87,7 +87,7 @@ func TestTxStats(t *testing.T) {
},
{
scenario: "no error",
beginner: noOpTxFunc,
beginner: nopTxFunc,
expected: `[
{
"Name": "db.sql.client.calls{service.name=otelsql,instrumentation.name=tx_test,db.instance=test,db.operation=go.sql.commit,db.sql.status=OK,db.system=other_sql}",
Expand Down

0 comments on commit 010b1a7

Please sign in to comment.