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

Commitbbbe7aa

Browse files
committed
add guard rail
1 parente2d1545 commitbbbe7aa

File tree

1 file changed

+24
-6
lines changed

1 file changed

+24
-6
lines changed

‎coderd/database/modelqueries_internal_test.go

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package database
22

33
import (
4-
"fmt"
54
"testing"
65

76
"github.com/stretchr/testify/require"
@@ -19,16 +18,35 @@ func TestIsAuthorizedQuery(t *testing.T) {
1918

2019
// TestWorkspaceTableConvert verifies all workspace fields are converted
2120
// when reducing a `Workspace` to a `WorkspaceTable`.
21+
// This test is a guard rail to prevent developer oversight mistakes.
2222
funcTestWorkspaceTableConvert(t*testing.T) {
2323
t.Parallel()
2424

25+
staticRandoms:=&testutil.Random{
26+
String:func()string {return"foo" },
27+
Bool:func()bool {returntrue },
28+
Int:func()int64 {return500 },
29+
Uint:func()uint64 {return126 },
30+
Float:func()float64 {return3.14 },
31+
Complex:func()complex128 {return6.24 },
32+
}
33+
34+
// This feels a bit janky, but it works.
35+
// If you use 'PopulateStruct' to create 2 workspaces, using the same
36+
// "random" values for each type. Then they should be identical.
37+
//
38+
// So if 'workspace.WorkspaceTable()' was missing any fields in its
39+
// conversion, the comparison would fail.
40+
2541
varworkspaceWorkspace
26-
err:=testutil.PopulateStruct(&workspace,nil)
42+
err:=testutil.PopulateStruct(&workspace,staticRandoms)
2743
require.NoError(t,err)
2844

29-
workspace.WorkspaceTable()
30-
require.JSONEq(t)
31-
32-
fmt.Println(workspace)
45+
varsubsetWorkspaceTable
46+
err=testutil.PopulateStruct(&subset,staticRandoms)
47+
require.NoError(t,err)
3348

49+
require.Equal(t,workspace.WorkspaceTable(),subset,
50+
"'workspace.WorkspaceTable()' is not missing at least 1 field when converting to 'WorkspaceTable'. "+
51+
"To resolve this, go to the 'func (w Workspace) WorkspaceTable()' and ensure all fields are converted.")
3452
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp