Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
Signed-off-by: Remington Breeze <remington@breeze.software>
  • Loading branch information
rbreeze committed Jul 24, 2024
1 parent cb385d9 commit eb20c33
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 8 deletions.
19 changes: 11 additions & 8 deletions internal/controller/promotion/argocd.go
Original file line number Diff line number Diff line change
Expand Up @@ -351,14 +351,17 @@ func (a *argoCDMechanism) updateApplicationSources(
app.Spec.Source = desiredSource.DeepCopy()
app.Spec.Sources = desiredSources.DeepCopy()

// retrieve AppProject object
project, err := argocd.GetAppProject(ctx, a.argocdClient, app.Spec.Project)
if err != nil {
return fmt.Errorf("error finding Argo CD AppProject %q in namespace %q: %w", app.Spec.Project, app.Namespace, err)
}

if !project.Spec.SyncWindows.Matches(app).CanSync(true) {
return fmt.Errorf("cannot sync: blocked by sync window")
if app.Spec.Project != "" {
// retrieve AppProject object
project, err := argocd.GetAppProject(ctx, a.argocdClient, app.Spec.Project)
if err != nil || project == nil {
return fmt.Errorf("error finding Argo CD AppProject %s: %w", app.Spec.Project, err)

Check warning on line 358 in internal/controller/promotion/argocd.go

View check run for this annotation

Codecov / codecov/patch

internal/controller/promotion/argocd.go#L356-L358

Added lines #L356 - L358 were not covered by tests
}
if project.Spec.SyncWindows != nil {
if !project.Spec.SyncWindows.Matches(app).CanSync(true) {
return fmt.Errorf("cannot sync: blocked by sync window")

Check warning on line 362 in internal/controller/promotion/argocd.go

View check run for this annotation

Codecov / codecov/patch

internal/controller/promotion/argocd.go#L360-L362

Added lines #L360 - L362 were not covered by tests
}
}
}

// Initiate a new operation.
Expand Down
12 changes: 12 additions & 0 deletions internal/controller/promotion/argocd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1179,6 +1179,17 @@ func TestArgoCDMustPerformUpdate(t *testing.T) {
}

func TestArgoCDUpdateApplicationSources(t *testing.T) {
scheme := runtime.NewScheme()
c := fake.NewClientBuilder().WithScheme(scheme)
err := argocd.AddToScheme(scheme)
require.NoError(t, err)
proj := &argocd.AppProject{
ObjectMeta: metav1.ObjectMeta{
Name: "fake-project",
},
}
c.WithObjects(proj)

testCases := []struct {
name string
promoMech *argoCDMechanism
Expand Down Expand Up @@ -1241,6 +1252,7 @@ func TestArgoCDUpdateApplicationSources(t *testing.T) {
},
}
for _, testCase := range testCases {
testCase.promoMech.argocdClient = c.Build()
t.Run(testCase.name, func(t *testing.T) {
testCase.assertions(
t,
Expand Down

0 comments on commit eb20c33

Please sign in to comment.