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)
| 56 | // intentionally excluded from the workspace_build_with_user view to avoid |
| 57 | // loading the large Terraform state blob on hot paths. |
| 58 | func 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 |
| 88 | func TestViewSubsetWorkspace(t *testing.T) { |
nothing calls this directly
no test coverage detected