@@ -80,35 +80,54 @@ func getAwsAccountId() (string, error) {
8080}
8181
8282func readOrCreateTestSuiteFile (testSuite * TestSuite , testName string ) (* TestSuite , error ) {
83+ // Initialize TestSuites structure
84+ var testSuites TestSuites
85+
8386 if data , err := os .ReadFile (testSuiteFile ); err == nil {
84- if err := json .Unmarshal (data , & testSuite ); err != nil {
87+ // File exists, try to unmarshal existing test suites
88+ if err := json .Unmarshal (data , & testSuites ); err != nil {
8589 return & TestSuite {}, fmt .Errorf ("failed to parse test_suites.json: %s" , err .Error ())
8690 }
8791
88- fmt .Printf ("running tests in %s\n " , testSuite .TempDir )
89- return testSuite , nil
90- } else {
91- randID := random .UniqueId ()
92- testSuite .RandomIdentifier = strings .ToLower (randID )
93-
94- testSuite .TempDir , err = os .MkdirTemp ("" , testName )
95- if err != nil {
96- return & TestSuite {}, err
92+ if len (testSuites .Suites ) > 1 && testSuite .Index < 0 {
93+ return & TestSuite {}, fmt .Errorf ("test suite index is required when multiple test suites are present" )
9794 }
98- fmt .Printf ("running tests in %s\n " , testSuite .TempDir )
9995
100- // Write new values to file
101- data , err := json .MarshalIndent (testSuite , "" , " " )
102-
103- if err != nil {
104- return & TestSuite {}, err
96+ if testSuite .Index == - 1 && len (testSuites .Suites ) == 1 {
97+ testSuite .Index = 0
10598 }
10699
107- if err := os . WriteFile ( testSuiteFile , data , 0644 ); err != nil {
108- return & TestSuite {}, err
100+ if ! testSuite . ForceNewSuite && len ( testSuites . Suites ) > 0 {
101+ return testSuites . Suites [ testSuite . Index ], nil
109102 }
110103 }
111104
105+ // If we get here, either the file doesn't exist or we didn't find a matching suite
106+ fmt .Println ("no matching test suite found for index" , testSuite .Index , "creating new test suite" )
107+ randID := random .UniqueId ()
108+ testSuite .RandomIdentifier = strings .ToLower (randID )
109+ testSuite .Index = len (testSuites .Suites ) // Set index to current length
110+
111+ var err error
112+ testSuite .TempDir , err = os .MkdirTemp ("" , testName )
113+ if err != nil {
114+ return & TestSuite {}, err
115+ }
116+ fmt .Printf ("running tests in %s\n " , testSuite .TempDir )
117+
118+ // Add new test suite to the collection
119+ testSuites .Suites = append (testSuites .Suites , testSuite )
120+
121+ // Write updated test suites to file
122+ data , err := json .MarshalIndent (testSuites , "" , " " )
123+ if err != nil {
124+ return & TestSuite {}, err
125+ }
126+
127+ if err := os .WriteFile (testSuiteFile , data , 0644 ); err != nil {
128+ return & TestSuite {}, err
129+ }
130+
112131 os .Setenv ("ATMOS_BASE_PATH" , testSuite .TempDir )
113132 os .Setenv ("ATMOS_CLI_CONFIG_PATH" , testSuite .TempDir )
114133 os .Setenv ("TEST_ACCOUNT_ID" , testSuite .AwsAccountId )
0 commit comments