1
1
package database
2
2
3
3
import (
4
- "fmt"
5
4
"testing"
6
5
7
6
"github.com/stretchr/testify/require"
@@ -19,16 +18,35 @@ func TestIsAuthorizedQuery(t *testing.T) {
19
18
20
19
// TestWorkspaceTableConvert verifies all workspace fields are converted
21
20
// when reducing a `Workspace` to a `WorkspaceTable`.
21
+ // This test is a guard rail to prevent developer oversight mistakes.
22
22
func TestWorkspaceTableConvert (t * testing.T ) {
23
23
t .Parallel ()
24
24
25
+ staticRandoms := & testutil.Random {
26
+ String : func () string { return "foo" },
27
+ Bool : func () bool { return true },
28
+ Int : func () int64 { return 500 },
29
+ Uint : func () uint64 { return 126 },
30
+ Float : func () float64 { return 3.14 },
31
+ Complex : func () complex128 { return 6.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
+
25
41
var workspace Workspace
26
- err := testutil .PopulateStruct (& workspace , nil )
42
+ err := testutil .PopulateStruct (& workspace , staticRandoms )
27
43
require .NoError (t , err )
28
44
29
- workspace .WorkspaceTable ()
30
- require .JSONEq (t )
31
-
32
- fmt .Println (workspace )
45
+ var subset WorkspaceTable
46
+ err = testutil .PopulateStruct (& subset , staticRandoms )
47
+ require .NoError (t , err )
33
48
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." )
34
52
}
0 commit comments