diff --git a/coderd/database/dbfake/databasefake.go b/coderd/database/dbfake/dbfake.go similarity index 99% rename from coderd/database/dbfake/databasefake.go rename to coderd/database/dbfake/dbfake.go index 4c4ba8d35997f..11172959cd637 100644 --- a/coderd/database/dbfake/databasefake.go +++ b/coderd/database/dbfake/dbfake.go @@ -27,13 +27,6 @@ import ( 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{ Code: "23505", Message: "duplicate key value violates unique constraint", @@ -218,7 +211,6 @@ func validateDatabaseType(args interface{}) error { return nil } -func (fakeQuerier) IsFakeDB() {} func (*fakeQuerier) Ping(_ context.Context) (time.Duration, error) { return 0, nil } diff --git a/coderd/database/dbfake/databasefake_test.go b/coderd/database/dbfake/dbfake_test.go similarity index 76% rename from coderd/database/dbfake/databasefake_test.go rename to coderd/database/dbfake/dbfake_test.go index dd1a3ee445ae4..445ba6be8ec49 100644 --- a/coderd/database/dbfake/databasefake_test.go +++ b/coderd/database/dbfake/dbfake_test.go @@ -3,8 +3,6 @@ package dbfake_test import ( "context" "database/sql" - "fmt" - "reflect" "sort" "testing" "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. func TestUserOrder(t *testing.T) { 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 -}