@@ -3,8 +3,6 @@ package dbfake_test
33import (
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.
11166func 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