@@ -3,8 +3,6 @@ package dbfake_test
3
3
import (
4
4
"context"
5
5
"database/sql"
6
- "fmt"
7
- "reflect"
8
6
"sort"
9
7
"testing"
10
8
"time"
@@ -64,49 +62,6 @@ func TestInTx(t *testing.T) {
64
62
}
65
63
}
66
64
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
-
110
65
// TestUserOrder ensures that the fake database returns users sorted by username.
111
66
func TestUserOrder (t * testing.T ) {
112
67
t .Parallel ()
@@ -252,11 +207,3 @@ func TestProxyByHostname(t *testing.T) {
252
207
})
253
208
}
254
209
}
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