TestErrorCollectorIntegration tests the full flow of error collection
(t *testing.T)
| 132 | |
| 133 | // TestErrorCollectorIntegration tests the full flow of error collection |
| 134 | func TestErrorCollectorIntegration(t *testing.T) { |
| 135 | tests := []struct { |
| 136 | name string |
| 137 | failFast bool |
| 138 | errors []error |
| 139 | expectError bool |
| 140 | expectCount int |
| 141 | shouldContain []string |
| 142 | }{ |
| 143 | { |
| 144 | name: "no errors collected", |
| 145 | failFast: false, |
| 146 | errors: []error{}, |
| 147 | expectError: false, |
| 148 | expectCount: 0, |
| 149 | }, |
| 150 | { |
| 151 | name: "single error aggregated", |
| 152 | failFast: false, |
| 153 | errors: []error{errors.New("error 1")}, |
| 154 | expectError: true, |
| 155 | expectCount: 1, |
| 156 | shouldContain: []string{"error 1"}, |
| 157 | }, |
| 158 | { |
| 159 | name: "multiple errors aggregated", |
| 160 | failFast: false, |
| 161 | errors: []error{errors.New("error 1"), errors.New("error 2"), errors.New("error 3")}, |
| 162 | expectError: true, |
| 163 | expectCount: 3, |
| 164 | shouldContain: []string{"error 1", "error 2", "error 3"}, |
| 165 | }, |
| 166 | { |
| 167 | name: "fail-fast stops at first error", |
| 168 | failFast: true, |
| 169 | errors: []error{errors.New("error 1"), errors.New("error 2")}, |
| 170 | expectError: true, |
| 171 | expectCount: 0, // No errors collected in fail-fast mode |
| 172 | shouldContain: []string{}, |
| 173 | }, |
| 174 | } |
| 175 | |
| 176 | for _, tt := range tests { |
| 177 | t.Run(tt.name, func(t *testing.T) { |
| 178 | collector := NewErrorCollector(tt.failFast) |
| 179 | |
| 180 | // Add all errors |
| 181 | for _, err := range tt.errors { |
| 182 | result := collector.Add(err) |
| 183 | if tt.failFast && err != nil { |
| 184 | // In fail-fast mode, Add should return error immediately |
| 185 | assert.Error(t, result, "Should return error in fail-fast mode") |
| 186 | return // Stop test here for fail-fast mode |
| 187 | } |
| 188 | } |
| 189 | |
| 190 | // Get the aggregated error |
| 191 | err := collector.Error() |