github.com/argoproj/argo-cd/v3@v3.2.1/test/e2e/app_k8s_events_test.go (about)

     1  package e2e
     2  
     3  import (
     4  	"fmt"
     5  	"testing"
     6  
     7  	"github.com/stretchr/testify/assert"
     8  	"github.com/stretchr/testify/require"
     9  	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
    10  
    11  	. "github.com/argoproj/argo-cd/v3/pkg/apis/application/v1alpha1"
    12  	. "github.com/argoproj/argo-cd/v3/test/e2e/fixture"
    13  	. "github.com/argoproj/argo-cd/v3/test/e2e/fixture/app"
    14  )
    15  
    16  // resource.includeEventLabelKeys keys set in argocd-cm
    17  func TestLabelsOnAppK8sEvents(t *testing.T) {
    18  	expectedLabels := map[string]string{"app": "test", "environment": "dev"}
    19  
    20  	Given(t).
    21  		Timeout(60).
    22  		Path("two-nice-pods").
    23  		When().
    24  		SetParamInSettingConfigMap("resource.includeEventLabelKeys", "app,team,env*").
    25  		SetParamInSettingConfigMap("resource.excludeEventLabelKeys", "team").
    26  		CreateApp("--label=app=test", "--label=environment=dev", "--label=team=A", "--label=tier=ui").
    27  		Sync().
    28  		Then().
    29  		Expect(SyncStatusIs(SyncStatusCodeSynced)).
    30  		And(func(app *Application) {
    31  			events, err := KubeClientset.CoreV1().Events(app.Namespace).List(t.Context(), metav1.ListOptions{
    32  				FieldSelector: fmt.Sprintf("involvedObject.name=%s,involvedObject.kind=Application", app.Name),
    33  			})
    34  			require.NoError(t, err)
    35  			for _, event := range events.Items {
    36  				for k, v := range event.Labels {
    37  					ev, found := expectedLabels[k]
    38  					assert.True(t, found)
    39  					assert.Equal(t, ev, v)
    40  				}
    41  			}
    42  		})
    43  }
    44  
    45  // resource.includeEventLabelKeys keys not set in argocd-cm
    46  func TestNoLabelsOnAppK8sEvents(t *testing.T) {
    47  	Given(t).
    48  		Timeout(60).
    49  		Path("two-nice-pods").
    50  		When().
    51  		CreateApp("--label=app=test", "--label=environment=dev", "--label=team=A", "--label=tier=ui").
    52  		Sync().
    53  		Then().
    54  		Expect(SyncStatusIs(SyncStatusCodeSynced)).
    55  		And(func(app *Application) {
    56  			events, err := KubeClientset.CoreV1().Events(app.Namespace).List(t.Context(), metav1.ListOptions{
    57  				FieldSelector: fmt.Sprintf("involvedObject.name=%s,involvedObject.kind=Application", app.Name),
    58  			})
    59  			require.NoError(t, err)
    60  			for _, event := range events.Items {
    61  				assert.Nil(t, event.Labels)
    62  			}
    63  		})
    64  }