@@ -66,16 +66,21 @@ func BidirectionalConversion(t *testing.T, ignoredFields []string, primaryResour
6666 t .Run (stepName , func (t * testing.T ) {
6767 retries := 0
6868 tName := fmt .Sprintf ("%s_%s" , subTestName , stepName )
69+ var attemptErrors []error
6970 flakyAction := func (ctx context.Context ) error {
7071 testData , err := prepareTestData (subTestName , stepN , retries )
7172 retries ++
7273 log .Printf ("%s: Starting the attempt %d" , tName , retries )
7374 if err != nil {
74- return fmt .Errorf ("%s: error preparing the input data: %v" , tName , err )
75+ err = fmt .Errorf ("%s: error preparing the input data: %v" , tName , err )
76+ attemptErrors = append (attemptErrors , err )
77+ return err
7578 }
7679
7780 if testData == nil {
78- return retry .RetryableError (fmt .Errorf ("fail: test data is unavailable" ))
81+ err = retry .RetryableError (fmt .Errorf ("fail: test data is unavailable" ))
82+ attemptErrors = append (attemptErrors , err )
83+ return err
7984 }
8085
8186 // If the primary resource is specified, only test the primary resource.
@@ -86,6 +91,7 @@ func BidirectionalConversion(t *testing.T, ignoredFields []string, primaryResour
8691 t .Logf ("%s: Test for the primary resource %s begins." , tName , primaryResource )
8792 err = testSingleResource (t , tName , resourceTestData [primaryResource ], tfDir , ignoredFields , logger , true )
8893 if err != nil {
94+ attemptErrors = append (attemptErrors , err )
8995 return err
9096 }
9197 } else {
@@ -95,6 +101,7 @@ func BidirectionalConversion(t *testing.T, ignoredFields []string, primaryResour
95101 }
96102 err = testSingleResource (t , tName , testData , tfDir , ignoredFields , logger , false )
97103 if err != nil {
104+ attemptErrors = append (attemptErrors , err )
98105 return err
99106 }
100107 }
@@ -109,10 +116,18 @@ func BidirectionalConversion(t *testing.T, ignoredFields []string, primaryResour
109116 t .Logf ("%s: Starting test with retry logic." , tName )
110117
111118 if err := retry .Do (context .Background (), backoffPolicy , flakyAction ); err != nil {
112- if strings .Contains (err .Error (), "test data is unavailable" ) {
113- t .Skipf ("%s: Test skipped because data was unavailable after all retries: %v" , tName , err )
119+ allUnavailable := len (attemptErrors ) > 0
120+ for _ , e := range attemptErrors {
121+ if ! strings .Contains (e .Error (), "test data is unavailable" ) {
122+ allUnavailable = false
123+ break
124+ }
125+ }
126+
127+ if allUnavailable {
128+ t .Skipf ("%s: Test skipped because data was unavailable after all %d attempts: %v" , tName , len (attemptErrors ), err )
114129 } else {
115- t .Fatalf ("%s: Failed after all attempts %d : %v" , tName , maxAttempts , err )
130+ t .Fatalf ("%s: Failed after %d attempts. Last error : %v" , tName , len ( attemptErrors ) , err )
116131 }
117132 }
118133 })
@@ -129,7 +144,7 @@ func testSingleResource(t *testing.T, testName string, testData ResourceTestData
129144
130145 if testData .Cai == nil {
131146 log .Printf ("SKIP: cai asset is unavailable for resource %s" , testData .ResourceAddress )
132- return nil
147+ return retry . RetryableError ( fmt . Errorf ( "fail: test data is unavailable" ))
133148 }
134149
135150 assets := make ([]caiasset.Asset , 0 )
@@ -146,12 +161,7 @@ func testSingleResource(t *testing.T, testName string, testData ResourceTestData
146161 }
147162
148163 if ! tfplan2caiSupported && ! cai2hclSupported {
149- if primaryResource {
150- return fmt .Errorf ("conversion of the primary resource %s is not supported in tgc" , testData .ResourceAddress )
151- } else {
152- log .Printf ("SKIP: conversion of the resource %s is not supported in tgc." , resourceType )
153- return nil
154- }
164+ return fmt .Errorf ("conversion of the resource %s is not supported in tgc" , testData .ResourceAddress )
155165 }
156166
157167 if ! (tfplan2caiSupported && cai2hclSupported ) {
0 commit comments