@@ -9,10 +9,11 @@ import (
9
9
"time"
10
10
11
11
"github.com/stretchr/testify/assert"
12
+ "github.com/stretchr/testify/require"
12
13
13
14
"github.com/coder/coder/coderd/database"
14
-
15
15
"github.com/coder/coder/coderd/database/dbfake"
16
+ "github.com/coder/coder/coderd/database/dbgen"
16
17
)
17
18
18
19
// test that transactions don't deadlock, and that we don't see intermediate state.
@@ -105,6 +106,29 @@ func TestExactMethods(t *testing.T) {
105
106
}
106
107
}
107
108
109
+ // TestUserOrder ensures that the fake database returns users in the order they
110
+ // were created.
111
+ func TestUserOrder (t * testing.T ) {
112
+ t .Parallel ()
113
+
114
+ db := dbfake .New ()
115
+ now := database .Now ()
116
+ count := 10
117
+ for i := 0 ; i < count ; i ++ {
118
+ dbgen .User (t , db , database.User {
119
+ Username : fmt .Sprintf ("user%d" , i ),
120
+ CreatedAt : now ,
121
+ })
122
+ }
123
+
124
+ users , err := db .GetUsers (context .Background (), database.GetUsersParams {})
125
+ require .NoError (t , err )
126
+ require .Lenf (t , users , count , "expected %d users" , count )
127
+ for i , user := range users {
128
+ require .Equal (t , fmt .Sprintf ("user%d" , i ), user .Username )
129
+ }
130
+ }
131
+
108
132
func methods (rt reflect.Type ) map [string ]bool {
109
133
methods := make (map [string ]bool )
110
134
for i := 0 ; i < rt .NumMethod (); i ++ {
0 commit comments