|
| 1 | +package argocd |
| 2 | + |
| 3 | +import ( |
| 4 | + "testing" |
| 5 | + |
| 6 | + "github.com/argoproj/gitops-engine/pkg/utils/kube" |
| 7 | + "github.com/stretchr/testify/assert" |
| 8 | + "github.com/stretchr/testify/require" |
| 9 | + "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" |
| 10 | + |
| 11 | + "github.com/argoproj/argo-cd/v2/pkg/apis/application/v1alpha1" |
| 12 | +) |
| 13 | + |
| 14 | +func Test_getRefreshType(t *testing.T) { |
| 15 | + t.Parallel() |
| 16 | + |
| 17 | + var no *string |
| 18 | + normal := string(v1alpha1.RefreshTypeNormal) |
| 19 | + hard := string(v1alpha1.RefreshTypeHard) |
| 20 | + |
| 21 | + t.Run("no refresh", func(t *testing.T) { |
| 22 | + assert.Equal(t, no, getRefreshType(false, false)) |
| 23 | + }) |
| 24 | + |
| 25 | + t.Run("normal refresh", func(t *testing.T) { |
| 26 | + assert.Equal(t, &normal, getRefreshType(true, false)) |
| 27 | + }) |
| 28 | + |
| 29 | + t.Run("hard refresh", func(t *testing.T) { |
| 30 | + assert.Equal(t, &hard, getRefreshType(false, true)) |
| 31 | + assert.Equal(t, &hard, getRefreshType(true, true)) |
| 32 | + }) |
| 33 | +} |
| 34 | + |
| 35 | +func Test_groupObjsByKey(t *testing.T) { |
| 36 | + t.Parallel() |
| 37 | + |
| 38 | + t.Run("single", func(t *testing.T) { |
| 39 | + localObjs := []*unstructured.Unstructured{ |
| 40 | + { |
| 41 | + Object: map[string]interface{}{ |
| 42 | + "apiVersion": "apps/v1", |
| 43 | + "kind": "Deployment", |
| 44 | + "metadata": map[string]interface{}{ |
| 45 | + "name": "my-deployment", |
| 46 | + "namespace": "my-namespace", |
| 47 | + }, |
| 48 | + }, |
| 49 | + }, |
| 50 | + } |
| 51 | + grouped, err := groupObjsByKey(localObjs, localObjs, "my-namespace") |
| 52 | + require.NoError(t, err) |
| 53 | + assert.Equal(t, map[kube.ResourceKey]*unstructured.Unstructured{ |
| 54 | + kube.ResourceKey{ |
| 55 | + Group: "apps", |
| 56 | + Kind: "Deployment", |
| 57 | + Name: "my-deployment", |
| 58 | + Namespace: "my-namespace", |
| 59 | + }: localObjs[0], |
| 60 | + }, grouped) |
| 61 | + }) |
| 62 | +} |
0 commit comments