Skip to content

Commit 07fa2b1

Browse files
committed
add comment for test helper
1 parent ff53e18 commit 07fa2b1

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

coderd/coderdtest/uuids.go

+4
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ package coderdtest
22

33
import "github.com/google/uuid"
44

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.
59
type DeterministicUUIDGenerator struct {
610
Named map[string]uuid.UUID
711
}

coderd/coderdtest/uuids_test.go

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
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+
}

0 commit comments

Comments
 (0)