File tree 2 files changed +37
-0
lines changed
2 files changed +37
-0
lines changed Original file line number Diff line number Diff line change @@ -2,6 +2,10 @@ package coderdtest
2
2
3
3
import "github.com/google/uuid"
4
4
5
+ // DeterministicUUIDGenerator allows "naming" uuids for unit tests.
6
+ // An example of where this is useful, is when a tabled test references
7
+ // a UUID that is not yet known. An alternative to this would be to
8
+ // hard code some UUID strings, but these strings are not human friendly.
5
9
type DeterministicUUIDGenerator struct {
6
10
Named map [string ]uuid.UUID
7
11
}
Original file line number Diff line number Diff line change
1
+ package coderdtest_test
2
+
3
+ import (
4
+ "github.com/google/uuid"
5
+
6
+ "github.com/coder/coder/v2/coderd/coderdtest"
7
+ )
8
+
9
+ func ExampleNewDeterministicUUIDGenerator () {
10
+ det := coderdtest .NewDeterministicUUIDGenerator ()
11
+ testCases := []struct {
12
+ CreateUsers []uuid.UUID
13
+ ExpectedIDs []uuid.UUID
14
+ }{
15
+ {
16
+ CreateUsers : []uuid.UUID {
17
+ det .ID ("player1" ),
18
+ det .ID ("player2" ),
19
+ },
20
+ ExpectedIDs : []uuid.UUID {
21
+ det .ID ("player1" ),
22
+ det .ID ("player2" ),
23
+ },
24
+ },
25
+ }
26
+
27
+ for _ , tc := range testCases {
28
+ tc := tc
29
+ var _ = tc
30
+ // Do the test with CreateUsers as the setup, and the expected IDs
31
+ // will match.
32
+ }
33
+ }
You can’t perform that action at this time.
0 commit comments