(t *testing.T)
| 217 | } |
| 218 | |
| 219 | func TestFactory_Build(t *testing.T) { |
| 220 | t.Run("successfully builds repository with matching type", func(t *testing.T) { |
| 221 | expectedRepo := &MockConfigRepository{} |
| 222 | localExtra := &MockExtra{} |
| 223 | localExtra.On("Type").Return(provisioning.LocalRepositoryType) |
| 224 | localExtra.On("Build", mock.Anything, mock.Anything).Return(expectedRepo, nil) |
| 225 | |
| 226 | enabled := map[provisioning.RepositoryType]struct{}{ |
| 227 | provisioning.LocalRepositoryType: {}, |
| 228 | } |
| 229 | factory, err := ProvideFactory(enabled, []Extra{localExtra}) |
| 230 | require.NoError(t, err) |
| 231 | |
| 232 | ctx := context.Background() |
| 233 | repoConfig := &provisioning.Repository{ |
| 234 | Spec: provisioning.RepositorySpec{ |
| 235 | Type: provisioning.LocalRepositoryType, |
| 236 | }, |
| 237 | } |
| 238 | |
| 239 | result, err := factory.Build(ctx, repoConfig) |
| 240 | |
| 241 | require.NoError(t, err) |
| 242 | assert.Equal(t, expectedRepo, result) |
| 243 | localExtra.AssertExpectations(t) |
| 244 | }) |
| 245 | |
| 246 | t.Run("returns error for unsupported repository type", func(t *testing.T) { |
| 247 | gitExtra := &MockExtra{} |
| 248 | gitExtra.On("Type").Return(provisioning.GitRepositoryType) |
| 249 | |
| 250 | enabled := map[provisioning.RepositoryType]struct{}{ |
| 251 | provisioning.GitRepositoryType: {}, |
| 252 | } |
| 253 | factory, err := ProvideFactory(enabled, []Extra{gitExtra}) |
| 254 | require.NoError(t, err) |
| 255 | |
| 256 | ctx := context.Background() |
| 257 | repoConfig := &provisioning.Repository{ |
| 258 | Spec: provisioning.RepositorySpec{ |
| 259 | Type: provisioning.LocalRepositoryType, // Different from registered type |
| 260 | }, |
| 261 | } |
| 262 | |
| 263 | result, err := factory.Build(ctx, repoConfig) |
| 264 | |
| 265 | assert.Error(t, err) |
| 266 | assert.Nil(t, result) |
| 267 | assert.Contains(t, err.Error(), "repository type \"local\" is not supported") |
| 268 | gitExtra.AssertNotCalled(t, "Build") |
| 269 | gitExtra.AssertExpectations(t) |
| 270 | }) |
| 271 | |
| 272 | t.Run("propagates error from extra.Build", func(t *testing.T) { |
| 273 | expectedError := errors.New("build failed") |
| 274 | localExtra := &MockExtra{} |
| 275 | localExtra.On("Type").Return(provisioning.LocalRepositoryType) |
| 276 | localExtra.On("Build", mock.Anything, mock.Anything).Return(nil, expectedError) |
nothing calls this directly
no test coverage detected