chore: rename databasefake to dbfake (#7979)

* chore: rename `databasefake` to `dbfake`

* Remove unused method
This commit is contained in:
Kyle Carberry
2023-06-12 16:05:37 -05:00
committed by GitHub
parent 4a0ac13bb7
commit 685abfc6d7
2 changed files with 0 additions and 61 deletions

View File

@ -27,13 +27,6 @@ import (
var validProxyByHostnameRegex = regexp.MustCompile(`^[a-zA-Z0-9._-]+$`) var validProxyByHostnameRegex = regexp.MustCompile(`^[a-zA-Z0-9._-]+$`)
// FakeDatabase is helpful for knowing if the underlying db is an in memory fake
// database. This is only in the databasefake package, so will only be used
// by unit tests.
type FakeDatabase interface {
IsFakeDB()
}
var errDuplicateKey = &pq.Error{ var errDuplicateKey = &pq.Error{
Code: "23505", Code: "23505",
Message: "duplicate key value violates unique constraint", Message: "duplicate key value violates unique constraint",
@ -218,7 +211,6 @@ func validateDatabaseType(args interface{}) error {
return nil return nil
} }
func (fakeQuerier) IsFakeDB() {}
func (*fakeQuerier) Ping(_ context.Context) (time.Duration, error) { func (*fakeQuerier) Ping(_ context.Context) (time.Duration, error) {
return 0, nil return 0, nil
} }

View File

@ -3,8 +3,6 @@ package dbfake_test
import ( import (
"context" "context"
"database/sql" "database/sql"
"fmt"
"reflect"
"sort" "sort"
"testing" "testing"
"time" "time"
@ -64,49 +62,6 @@ func TestInTx(t *testing.T) {
} }
} }
// TestExactMethods will ensure the fake database does not hold onto excessive
// functions. The fake database is a manual implementation, so it is possible
// we forget to delete functions that we remove. This unit test just ensures
// we remove the extra methods.
func TestExactMethods(t *testing.T) {
t.Parallel()
// extraFakeMethods contains the extra allowed methods that are not a part
// of the database.Store interface.
extraFakeMethods := map[string]string{
// Example
// "SortFakeLists": "Helper function used",
"IsFakeDB": "Helper function used for unit testing",
}
fake := reflect.TypeOf(dbfake.New())
fakeMethods := methods(fake)
store := reflect.TypeOf((*database.Store)(nil)).Elem()
storeMethods := methods(store)
// Store should be a subset
for k := range storeMethods {
_, ok := fakeMethods[k]
if !ok {
panic(fmt.Sprintf("This should never happen. FakeDB missing method %s, so doesn't fit the interface", k))
}
delete(storeMethods, k)
delete(fakeMethods, k)
}
for k := range fakeMethods {
_, ok := extraFakeMethods[k]
if ok {
continue
}
// If you are seeing this error, you have an extra function not required
// for the database.Store. If you still want to keep it, add it to
// 'extraFakeMethods' to allow it.
t.Errorf("Fake method '%s()' is excessive and not needed to fit interface, delete it", k)
}
}
// TestUserOrder ensures that the fake database returns users sorted by username. // TestUserOrder ensures that the fake database returns users sorted by username.
func TestUserOrder(t *testing.T) { func TestUserOrder(t *testing.T) {
t.Parallel() t.Parallel()
@ -252,11 +207,3 @@ func TestProxyByHostname(t *testing.T) {
}) })
} }
} }
func methods(rt reflect.Type) map[string]bool {
methods := make(map[string]bool)
for i := 0; i < rt.NumMethod(); i++ {
methods[rt.Method(i).Name] = true
}
return methods
}