From b51990075c7a0bdff7c5e8d289c9401698dde78b Mon Sep 17 00:00:00 2001 From: Anton Ovchinnikov Date: Thu, 21 Dec 2023 10:38:29 +0100 Subject: [PATCH] more fixes --- crons_monitor_data_test.go | 10 ---------- enhancers.go | 8 -------- sentry_dsn_data_test.go | 8 -------- 3 files changed, 26 deletions(-) diff --git a/crons_monitor_data_test.go b/crons_monitor_data_test.go index 7a66226..5e12ce1 100644 --- a/crons_monitor_data_test.go +++ b/crons_monitor_data_test.go @@ -9,7 +9,6 @@ import ( ) func TestNewCronsJobData(t *testing.T) { - fakeId := "080181f33ca343f89b0bf55d50abfeee" cronsJobData := NewCronsJobData(sentry.EventID(fakeId)) @@ -23,7 +22,6 @@ func TestNewCronsJobData(t *testing.T) { } func TestGetCheckinId(t *testing.T) { - fakeId := "080181f33ca343f89b0bf55d50abfeee" cronsJobData := NewCronsJobData(sentry.EventID(fakeId)) @@ -37,7 +35,6 @@ func TestGetCheckinId(t *testing.T) { } func TestNewCronsMonitorData(t *testing.T) { - fakeMonitorSlug := "cronjob-slug" fakeSchedule := "* * * * *" var fakeCompletions int32 = 3 @@ -59,7 +56,6 @@ func TestNewCronsMonitorData(t *testing.T) { } func TestAddJob(t *testing.T) { - fakeId := "080181f33ca343f89b0bf55d50abfeee" fakeMonitorSlug := "cronjob-slug" fakeSchedule := "* * * * *" @@ -84,7 +80,6 @@ func TestAddJob(t *testing.T) { } func TestNewCronsMetaData(t *testing.T) { - cronsMetaData := NewCronsMetaData() if cronsMetaData.cronsMonitorDataMap == nil { t.Errorf("Failed to create cronsMonitorDataMap") @@ -92,7 +87,6 @@ func TestNewCronsMetaData(t *testing.T) { } func TestAddCronsMonitorData(t *testing.T) { - cronsMetaData := NewCronsMetaData() if cronsMetaData.cronsMonitorDataMap == nil { t.Errorf("Failed to create cronsMonitorDataMap") @@ -115,7 +109,6 @@ func TestAddCronsMonitorData(t *testing.T) { } func TestDeleteCronsMonitorData(t *testing.T) { - cronsMetaData := NewCronsMetaData() if cronsMetaData.cronsMonitorDataMap == nil { t.Errorf("Failed to create cronsMonitorDataMap") @@ -135,11 +128,9 @@ func TestDeleteCronsMonitorData(t *testing.T) { if ok { t.Errorf("Failed to delete cronsMonitorData from map") } - } func TestGetCronsMonitorData(t *testing.T) { - cronsMetaData := NewCronsMetaData() if cronsMetaData.cronsMonitorDataMap == nil { t.Errorf("Failed to create cronsMonitorDataMap") @@ -159,5 +150,4 @@ func TestGetCronsMonitorData(t *testing.T) { if retCronsMonitorData != cronsMonitorData { t.Errorf("Failed to get correct cronsMonitorData to map") } - } diff --git a/enhancers.go b/enhancers.go index f7275ea..2f704e4 100644 --- a/enhancers.go +++ b/enhancers.go @@ -16,7 +16,6 @@ import ( const breadcrumbLimit = 20 func runEnhancers(ctx context.Context, eventObject *v1.Event, kind string, object metav1.Object, scope *sentry.Scope, sentryEvent *sentry.Event) error { - logger := zerolog.Ctx(ctx) logger.Debug().Msgf("Running the enhancer") @@ -88,7 +87,6 @@ func eventEnhancer(ctx context.Context, scope *sentry.Scope, object metav1.Objec } func objectEnhancer(ctx context.Context, scope *sentry.Scope, kindObjectPair *KindObjectPair, sentryEvent *sentry.Event) error { - objectTag := fmt.Sprintf("%s/%s", kindObjectPair.kind, kindObjectPair.object.GetName()) ctx, logger := getLoggerWithTag(ctx, "object", objectTag) @@ -196,7 +194,6 @@ func podEnhancer(ctx context.Context, scope *sentry.Scope, object metav1.Object, } func jobEnhancer(ctx context.Context, scope *sentry.Scope, object metav1.Object, sentryEvent *sentry.Event) error { - jobObj, ok := object.(*batchv1.Job) if !ok { return errors.New("failed to cast object to Job object") @@ -226,7 +223,6 @@ func jobEnhancer(ctx context.Context, scope *sentry.Scope, object metav1.Object, } func cronjobEnhancer(ctx context.Context, scope *sentry.Scope, object metav1.Object, sentryEvent *sentry.Event) error { - cronjobObj, ok := object.(*batchv1.CronJob) if !ok { return errors.New("failed to cast object to CronJob object") @@ -261,7 +257,6 @@ func cronjobEnhancer(ctx context.Context, scope *sentry.Scope, object metav1.Obj } func replicaSetEnhancer(ctx context.Context, scope *sentry.Scope, object metav1.Object, sentryEvent *sentry.Event) error { - replicasetObj, ok := object.(*appsv1.ReplicaSet) if !ok { return errors.New("failed to cast object to ReplicaSet object") @@ -291,7 +286,6 @@ func replicaSetEnhancer(ctx context.Context, scope *sentry.Scope, object metav1. } func deploymentEnhancer(ctx context.Context, scope *sentry.Scope, object metav1.Object, sentryEvent *sentry.Event) error { - deploymentObj, ok := object.(*appsv1.Deployment) if !ok { return errors.New("failed to cast object to Deployment object") @@ -323,7 +317,6 @@ func deploymentEnhancer(ctx context.Context, scope *sentry.Scope, object metav1. // and returns an empty slice if the object has // no owning objects func findRootOwners(ctx context.Context, kindObjPair *KindObjectPair) ([]KindObjectPair, error) { - // Use DFS to find the leaves of the owner references graph rootOwners, err := ownerRefDFS(ctx, kindObjPair) if err != nil { @@ -340,7 +333,6 @@ func findRootOwners(ctx context.Context, kindObjPair *KindObjectPair) ([]KindObj // Performs DFS to find the leaves the owner references graph func ownerRefDFS(ctx context.Context, kindObjPair *KindObjectPair) ([]KindObjectPair, error) { - parents := kindObjPair.object.GetOwnerReferences() // the owners slice to be returned rootOwners := []KindObjectPair{} diff --git a/sentry_dsn_data_test.go b/sentry_dsn_data_test.go index 73ce65b..c4d4f77 100644 --- a/sentry_dsn_data_test.go +++ b/sentry_dsn_data_test.go @@ -13,7 +13,6 @@ import ( ) func TestNewDsnClientMapping(t *testing.T) { - // Set the custom dsn flag as true t.Setenv("SENTRY_K8S_CUSTOM_DSNS", "TRUE") clientMapping := NewDsnClientMapping() @@ -30,11 +29,9 @@ func TestNewDsnClientMapping(t *testing.T) { if clientMapping.customDsnFlag { t.Errorf("Failed to read custom dsn flag as false") } - } func TestAddClientToMap(t *testing.T) { - fakeDsn := "https://c6f9a148ee0775891414b50b9af35959@o4506191942320128.ingest.sentry.io/1234567890" clientOptions := sentry.ClientOptions{ Dsn: fakeDsn, @@ -83,7 +80,6 @@ func TestGetClientFromMap(t *testing.T) { } func TestGetClientFromObject(t *testing.T) { - // Set the custom dsn flag as true t.Setenv("SENTRY_K8S_CUSTOM_DSNS", "TRUE") clientMapping := NewDsnClientMapping() @@ -141,11 +137,9 @@ func TestGetClientFromObject(t *testing.T) { if !reflect.DeepEqual(firstClient, secondClient) { t.Errorf("The function failed to retrieve the client it originally created") } - } func TestSearchDsn(t *testing.T) { - // Create empty context ctx := context.Background() // Create simple fake client @@ -220,11 +214,9 @@ func TestSearchDsn(t *testing.T) { if podDsn != fakeDsn { t.Errorf("DSN expected: %s, actual: %s", fakeDsn, podDsn) } - } func TestFindObject(t *testing.T) { - // Create empty context ctx := context.Background() // Create simple fake client