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

Function TestViewSubsetWorkspaceBuild

coderd/database/gentest/models_test.go:58–85  ·  view source on GitHub ↗

TestViewSubsetWorkspaceBuild ensures WorkspaceBuildTable is a subset of WorkspaceBuild, with the exception of ProvisionerState which is intentionally excluded from the workspace_build_with_user view to avoid loading the large Terraform state blob on hot paths.

(t *testing.T)

Source from the content-addressed store, hash-verified

56// intentionally excluded from the workspace_build_with_user view to avoid
57// loading the large Terraform state blob on hot paths.
58func TestViewSubsetWorkspaceBuild(t *testing.T) {
59 t.Parallel()
60 table := reflect.TypeOf(database.WorkspaceBuildTable{})
61 joined := reflect.TypeOf(database.WorkspaceBuild{})
62
63 tableFields := fieldNames(allFields(table))
64 joinedFields := fieldNames(allFields(joined))
65
66 // ProvisionerState is intentionally excluded from the
67 // workspace_build_with_user view to avoid loading multi-MB Terraform
68 // state blobs on hot paths. Callers that need it use
69 // GetWorkspaceBuildProvisionerStateByID instead.
70 excludedFields := map[string]bool{
71 "ProvisionerState": true,
72 }
73
74 var filtered []string
75 for _, name := range tableFields {
76 if !excludedFields[name] {
77 filtered = append(filtered, name)
78 }
79 }
80
81 if !assert.Subset(t, joinedFields, filtered, "table is not subset") {
82 t.Log("Some fields were added to the WorkspaceBuild Table without updating the 'workspace_build_with_user' view.")
83 t.Log("See migration 000141_join_users_build_version.up.sql to create the view.")
84 }
85}
86
87// TestViewSubsetWorkspace ensures WorkspaceTable is a subset of Workspace
88func TestViewSubsetWorkspace(t *testing.T) {

Callers

nothing calls this directly

Calls 3

fieldNamesFunction · 0.85
allFieldsFunction · 0.85
LogMethod · 0.80

Tested by

no test coverage detected