@@ -29,6 +29,35 @@ func setupTestStore(t *testing.T) *V1Store {
2929
3030// --- V1Store Tests ---
3131
32+ func mustCreateCompany (t * testing.T , store * V1Store , name , desc , userID string ) * V1Company {
33+ t .Helper ()
34+ company , err := store .CreateCompany (name , desc , userID )
35+ if err != nil {
36+ t .Fatalf ("CreateCompany(%q) failed: %v" , name , err )
37+ }
38+ return company
39+ }
40+
41+ func mustCreateOrganization (t * testing.T , store * V1Store , companyID , name , desc , userID string ) * V1Company {
42+ t .Helper ()
43+ org , err := store .CreateOrganization (companyID , name , desc , userID )
44+ if err != nil {
45+ t .Fatalf ("CreateOrganization(%q) failed: %v" , name , err )
46+ }
47+ return org
48+ }
49+
50+ func mustCreateProject (t * testing.T , store * V1Store , orgID , name , desc , userID string ) * V1Project {
51+ t .Helper ()
52+ proj , err := store .CreateProject (orgID , name , desc , userID )
53+ if err != nil {
54+ t .Fatalf ("CreateProject(%q) failed: %v" , name , err )
55+ }
56+ return proj
57+ }
58+
59+ // --- V1Store Tests ---
60+
3261func TestV1Store_CreateAndListCompanies (t * testing.T ) {
3362 store := setupTestStore (t )
3463
@@ -116,8 +145,14 @@ func TestV1Store_CreateAndListOrganizations(t *testing.T) {
116145func TestV1Store_CreateAndListProjects (t * testing.T ) {
117146 store := setupTestStore (t )
118147
119- company , _ := store .CreateCompany ("Co" , "" , "u1" )
120- org , _ := store .CreateOrganization (company .ID , "Org" , "" , "u1" )
148+ company , err := store .CreateCompany ("Co" , "" , "u1" )
149+ if err != nil {
150+ t .Fatalf ("CreateCompany: %v" , err )
151+ }
152+ org , err := store .CreateOrganization (company .ID , "Org" , "" , "u1" )
153+ if err != nil {
154+ t .Fatalf ("CreateOrganization: %v" , err )
155+ }
121156
122157 p , err := store .CreateProject (org .ID , "My Project" , "" , "A cool project" )
123158 if err != nil {
@@ -151,9 +186,9 @@ func TestV1Store_CreateAndListProjects(t *testing.T) {
151186func TestV1Store_WorkflowCRUD (t * testing.T ) {
152187 store := setupTestStore (t )
153188
154- company , _ := store . CreateCompany ( "Co" , "" , "u1" )
155- org , _ := store . CreateOrganization ( company .ID , "Org" , "" , "u1" )
156- proj , _ := store . CreateProject ( org .ID , "Proj" , "" , "" )
189+ company := mustCreateCompany ( t , store , "Co" , "" , "u1" )
190+ org := mustCreateOrganization ( t , store , company .ID , "Org" , "" , "u1" )
191+ proj := mustCreateProject ( t , store , org .ID , "Proj" , "" , "" )
157192
158193 // Create
159194 wf , err := store .CreateWorkflow (proj .ID , "Test Workflow" , "" , "desc" , "modules: []" , "u1" )
@@ -221,7 +256,10 @@ func TestV1Store_WorkflowCRUD(t *testing.T) {
221256 t .Fatalf ("DeleteWorkflow: %v" , err )
222257 }
223258
224- wfs , _ = store .ListWorkflows (proj .ID )
259+ wfs , err = store .ListWorkflows (proj .ID )
260+ if err != nil {
261+ t .Fatalf ("ListWorkflows after delete: %v" , err )
262+ }
225263 if len (wfs ) != 0 {
226264 t .Errorf ("got %d workflows after delete, want 0" , len (wfs ))
227265 }
@@ -230,15 +268,21 @@ func TestV1Store_WorkflowCRUD(t *testing.T) {
230268func TestV1Store_WorkflowVersioning (t * testing.T ) {
231269 store := setupTestStore (t )
232270
233- company , _ := store . CreateCompany ( "Co" , "" , "u1" )
234- org , _ := store . CreateOrganization ( company .ID , "Org" , "" , "u1" )
235- proj , _ := store . CreateProject ( org .ID , "Proj" , "" , "" )
271+ company := mustCreateCompany ( t , store , "Co" , "" , "u1" )
272+ org := mustCreateOrganization ( t , store , company .ID , "Org" , "" , "u1" )
273+ proj := mustCreateProject ( t , store , org .ID , "Proj" , "" , "" )
236274 wf , _ := store .CreateWorkflow (proj .ID , "WF" , "" , "" , "v1 config" , "u1" )
237275
238276 // Update config 3 times to create versions 2, 3, 4
239- store .UpdateWorkflow (wf .ID , "" , "" , "v2 config" , "u1" )
240- store .UpdateWorkflow (wf .ID , "" , "" , "v3 config" , "u1" )
241- store .UpdateWorkflow (wf .ID , "" , "" , "v4 config" , "u1" )
277+ if _ , err := store .UpdateWorkflow (wf .ID , "" , "" , "v2 config" , "u1" ); err != nil {
278+ t .Fatalf ("UpdateWorkflow v2: %v" , err )
279+ }
280+ if _ , err := store .UpdateWorkflow (wf .ID , "" , "" , "v3 config" , "u1" ); err != nil {
281+ t .Fatalf ("UpdateWorkflow v3: %v" , err )
282+ }
283+ if _ , err := store .UpdateWorkflow (wf .ID , "" , "" , "v4 config" , "u1" ); err != nil {
284+ t .Fatalf ("UpdateWorkflow v4: %v" , err )
285+ }
242286
243287 versions , err := store .ListVersions (wf .ID )
244288 if err != nil {
@@ -311,12 +355,18 @@ func TestV1Store_EnsureSystemHierarchy(t *testing.T) {
311355 if err != nil {
312356 t .Fatalf ("EnsureSystemHierarchy (second call): %v" , err )
313357 }
358+ if c2 != companyID {
359+ t .Errorf ("expected same company ID %q, got %q" , companyID , c2 )
360+ }
361+ if o2 != orgID {
362+ t .Errorf ("expected same organization ID %q, got %q" , orgID , o2 )
363+ }
364+ if p2 != projectID {
365+ t .Errorf ("expected same project ID %q, got %q" , projectID , p2 )
366+ }
314367 if w2 != workflowID {
315368 t .Errorf ("expected same workflow ID %q, got %q" , workflowID , w2 )
316369 }
317- _ = c2
318- _ = o2
319- _ = p2
320370}
321371
322372func TestV1Store_ResetSystemWorkflow (t * testing.T ) {
0 commit comments