TestNormalizeApplication verifies we normalize an application during reconciliation
(t *testing.T)
| 1641 | |
| 1642 | // TestNormalizeApplication verifies we normalize an application during reconciliation |
| 1643 | func TestNormalizeApplication(t *testing.T) { |
| 1644 | defaultProj := v1alpha1.AppProject{ |
| 1645 | ObjectMeta: metav1.ObjectMeta{ |
| 1646 | Name: "default", |
| 1647 | Namespace: test.FakeArgoCDNamespace, |
| 1648 | }, |
| 1649 | Spec: v1alpha1.AppProjectSpec{ |
| 1650 | SourceRepos: []string{"*"}, |
| 1651 | Destinations: []v1alpha1.ApplicationDestination{ |
| 1652 | { |
| 1653 | Server: "*", |
| 1654 | Namespace: "*", |
| 1655 | }, |
| 1656 | }, |
| 1657 | }, |
| 1658 | } |
| 1659 | app := newFakeApp() |
| 1660 | app.Spec.Project = "" |
| 1661 | app.Spec.Source.Kustomize = &v1alpha1.ApplicationSourceKustomize{NamePrefix: "foo-"} |
| 1662 | data := fakeData{ |
| 1663 | apps: []runtime.Object{app, &defaultProj}, |
| 1664 | manifestResponse: &apiclient.ManifestResponse{ |
| 1665 | Manifests: []string{}, |
| 1666 | Namespace: test.FakeDestNamespace, |
| 1667 | Server: test.FakeClusterURL, |
| 1668 | Revision: "abc123", |
| 1669 | }, |
| 1670 | managedLiveObjs: make(map[kube.ResourceKey]*unstructured.Unstructured), |
| 1671 | } |
| 1672 | |
| 1673 | { |
| 1674 | // Verify we normalize the app because project is missing |
| 1675 | ctrl := newFakeController(t.Context(), &data, nil) |
| 1676 | key, _ := cache.MetaNamespaceKeyFunc(app) |
| 1677 | ctrl.appRefreshQueue.AddRateLimited(key) |
| 1678 | fakeAppCs := ctrl.applicationClientset.(*appclientset.Clientset) |
| 1679 | fakeAppCs.ReactionChain = nil |
| 1680 | normalized := false |
| 1681 | fakeAppCs.AddReactor("patch", "*", func(action kubetesting.Action) (handled bool, ret runtime.Object, err error) { |
| 1682 | if patchAction, ok := action.(kubetesting.PatchAction); ok { |
| 1683 | if string(patchAction.GetPatch()) == `{"spec":{"project":"default"}}` { |
| 1684 | normalized = true |
| 1685 | } |
| 1686 | } |
| 1687 | return true, &v1alpha1.Application{}, nil |
| 1688 | }) |
| 1689 | ctrl.processAppRefreshQueueItem() |
| 1690 | assert.True(t, normalized) |
| 1691 | } |
| 1692 | |
| 1693 | { |
| 1694 | // Verify we don't unnecessarily normalize app when project is set |
| 1695 | app.Spec.Project = "default" |
| 1696 | data.apps[0] = app |
| 1697 | ctrl := newFakeController(t.Context(), &data, nil) |
| 1698 | key, _ := cache.MetaNamespaceKeyFunc(app) |
| 1699 | ctrl.appRefreshQueue.AddRateLimited(key) |
| 1700 | fakeAppCs := ctrl.applicationClientset.(*appclientset.Clientset) |
nothing calls this directly
no test coverage detected