Skip to content

Commit

Permalink
Extend adapter interface with Name function (#346)
Browse files Browse the repository at this point in the history
  • Loading branch information
lafriks committed Oct 7, 2023
1 parent 0384795 commit 2e07fc1
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
1 change: 1 addition & 0 deletions adapter.go
Expand Up @@ -6,6 +6,7 @@ import (

// Adapter interface
type Adapter interface {
Name() string
Close() error

Instrumentation(instrumenter Instrumenter)
Expand Down
5 changes: 5 additions & 0 deletions adapter_test.go
Expand Up @@ -90,3 +90,8 @@ func (ta *testAdapter) Exec(ctx context.Context, stmt string, args []any) (int64
mockArgs := ta.Called(ctx, stmt, args)
return int64(mockArgs.Int(0)), int64(mockArgs.Int(1)), mockArgs.Error(2)
}

func (ta *testAdapter) Name() string {
args := ta.Called()
return args.String(0)
}
16 changes: 13 additions & 3 deletions repository_test.go
Expand Up @@ -47,9 +47,7 @@ func TestNew(t *testing.T) {
}

func TestRepository_Instrumentation(t *testing.T) {
var (
repo = repository{rootAdapter: &testAdapter{}}
)
repo := repository{rootAdapter: &testAdapter{}}

assert.Nil(t, repo.instrumenter)
assert.NotPanics(t, func() {
Expand All @@ -75,6 +73,18 @@ func TestRepository_Ping(t *testing.T) {
adapter.AssertExpectations(t)
}

func TestRepository_AdapterName(t *testing.T) {
var (
adapter = &testAdapter{}
repo = New(adapter)
)

adapter.On("Name").Return("test").Once()

assert.Equal(t, "test", repo.Adapter(context.TODO()).Name())
adapter.AssertExpectations(t)
}

func TestRepository_Iterate(t *testing.T) {
var (
user User
Expand Down

0 comments on commit 2e07fc1

Please sign in to comment.