Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitc343f86

Browse files
committed
add comment for test helper
1 parent2b8ae1d commitc343f86

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

‎coderd/coderdtest/uuids.go

Lines changed: 4 additions & 0 deletions
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
typeDeterministicUUIDGeneratorstruct {
610
Namedmap[string]uuid.UUID
711
}

‎coderd/coderdtest/uuids_test.go

Lines changed: 33 additions & 0 deletions
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+
funcExampleNewDeterministicUUIDGenerator() {
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:=rangetestCases {
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)

[8]ページ先頭

©2009-2025 Movatter.jp