MCPcopy Index your code
hub / github.com/coder/coder / TestWorkspaceTableConvert

Function TestWorkspaceTableConvert

coderd/database/modelqueries_internal_test.go:28–61  ·  view source on GitHub ↗

TestWorkspaceTableConvert verifies all workspace fields are converted when reducing a `Workspace` to a `WorkspaceTable`. This test is a guard rail to prevent developer oversight mistakes.

(t *testing.T)

Source from the content-addressed store, hash-verified

26// when reducing a `Workspace` to a `WorkspaceTable`.
27// This test is a guard rail to prevent developer oversight mistakes.
28func TestWorkspaceTableConvert(t *testing.T) {
29 t.Parallel()
30
31 staticRandoms := &testutil.Random{
32 String: func() string { return "foo" },
33 Bool: func() bool { return true },
34 Int: func() int64 { return 500 },
35 Uint: func() uint64 { return 126 },
36 Float: func() float64 { return 3.14 },
37 Complex: func() complex128 { return 6.24 },
38 Time: func() time.Time {
39 return time.Date(2020, 5, 2, 5, 19, 21, 30, time.UTC)
40 },
41 }
42
43 // This feels a bit janky, but it works.
44 // If you use 'PopulateStruct' to create 2 workspaces, using the same
45 // "random" values for each type. Then they should be identical.
46 //
47 // So if 'workspace.WorkspaceTable()' was missing any fields in its
48 // conversion, the comparison would fail.
49
50 var workspace Workspace
51 err := testutil.PopulateStruct(&workspace, staticRandoms)
52 require.NoError(t, err)
53
54 var subset WorkspaceTable
55 err = testutil.PopulateStruct(&subset, staticRandoms)
56 require.NoError(t, err)
57
58 require.Equal(t, workspace.WorkspaceTable(), subset,
59 "'workspace.WorkspaceTable()' is not missing at least 1 field when converting to 'WorkspaceTable'. "+
60 "To resolve this, go to the 'func (w Workspace) WorkspaceTable()' and ensure all fields are converted.")
61}
62
63// TestTaskTableConvert verifies all task fields are converted
64// when reducing a `Task` to a `TaskTable`.

Callers

nothing calls this directly

Calls 3

WorkspaceTableMethod · 0.95
PopulateStructFunction · 0.92
EqualMethod · 0.45

Tested by

no test coverage detected