Skip to content

Commit 685abfc

Browse files
authored
chore: rename databasefake to dbfake (#7979)
* chore: rename `databasefake` to `dbfake` * Remove unused method
1 parent 4a0ac13 commit 685abfc

File tree

2 files changed

+0
-61
lines changed

2 files changed

+0
-61
lines changed

coderd/database/dbfake/databasefake.go renamed to coderd/database/dbfake/dbfake.go

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,6 @@ import (
2727

2828
var validProxyByHostnameRegex = regexp.MustCompile(`^[a-zA-Z0-9._-]+$`)
2929

30-
// FakeDatabase is helpful for knowing if the underlying db is an in memory fake
31-
// database. This is only in the databasefake package, so will only be used
32-
// by unit tests.
33-
type FakeDatabase interface {
34-
IsFakeDB()
35-
}
36-
3730
var errDuplicateKey = &pq.Error{
3831
Code: "23505",
3932
Message: "duplicate key value violates unique constraint",
@@ -218,7 +211,6 @@ func validateDatabaseType(args interface{}) error {
218211
return nil
219212
}
220213

221-
func (fakeQuerier) IsFakeDB() {}
222214
func (*fakeQuerier) Ping(_ context.Context) (time.Duration, error) {
223215
return 0, nil
224216
}

coderd/database/dbfake/databasefake_test.go renamed to coderd/database/dbfake/dbfake_test.go

Lines changed: 0 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ package dbfake_test
33
import (
44
"context"
55
"database/sql"
6-
"fmt"
7-
"reflect"
86
"sort"
97
"testing"
108
"time"
@@ -64,49 +62,6 @@ func TestInTx(t *testing.T) {
6462
}
6563
}
6664

67-
// TestExactMethods will ensure the fake database does not hold onto excessive
68-
// functions. The fake database is a manual implementation, so it is possible
69-
// we forget to delete functions that we remove. This unit test just ensures
70-
// we remove the extra methods.
71-
func TestExactMethods(t *testing.T) {
72-
t.Parallel()
73-
74-
// extraFakeMethods contains the extra allowed methods that are not a part
75-
// of the database.Store interface.
76-
extraFakeMethods := map[string]string{
77-
// Example
78-
// "SortFakeLists": "Helper function used",
79-
"IsFakeDB": "Helper function used for unit testing",
80-
}
81-
82-
fake := reflect.TypeOf(dbfake.New())
83-
fakeMethods := methods(fake)
84-
85-
store := reflect.TypeOf((*database.Store)(nil)).Elem()
86-
storeMethods := methods(store)
87-
88-
// Store should be a subset
89-
for k := range storeMethods {
90-
_, ok := fakeMethods[k]
91-
if !ok {
92-
panic(fmt.Sprintf("This should never happen. FakeDB missing method %s, so doesn't fit the interface", k))
93-
}
94-
delete(storeMethods, k)
95-
delete(fakeMethods, k)
96-
}
97-
98-
for k := range fakeMethods {
99-
_, ok := extraFakeMethods[k]
100-
if ok {
101-
continue
102-
}
103-
// If you are seeing this error, you have an extra function not required
104-
// for the database.Store. If you still want to keep it, add it to
105-
// 'extraFakeMethods' to allow it.
106-
t.Errorf("Fake method '%s()' is excessive and not needed to fit interface, delete it", k)
107-
}
108-
}
109-
11065
// TestUserOrder ensures that the fake database returns users sorted by username.
11166
func TestUserOrder(t *testing.T) {
11267
t.Parallel()
@@ -252,11 +207,3 @@ func TestProxyByHostname(t *testing.T) {
252207
})
253208
}
254209
}
255-
256-
func methods(rt reflect.Type) map[string]bool {
257-
methods := make(map[string]bool)
258-
for i := 0; i < rt.NumMethod(); i++ {
259-
methods[rt.Method(i).Name] = true
260-
}
261-
return methods
262-
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy