Browse Source

fix tests

Feroze Mohideen 2 years ago
parent
commit
a34de02d4e

+ 6 - 9
internal/porter_app/notifications/notification.go

@@ -31,14 +31,11 @@ func HandleNotification(ctx context.Context, inp HandleNotificationInput) error
 		return telemetry.Error(ctx, span, nil, "app event metadata is nil")
 	}
 
-	// 2. convert app event to notification
-	notification, err := appEventToNotification(*appEventMetadata)
-	if err != nil {
-		return telemetry.Error(ctx, span, err, "failed to convert app event to notification")
-	}
+	// 2. convert app event to baseNotification
+	baseNotification := appEventToNotification(*appEventMetadata)
 
 	// 3. dedupe notification
-	isDuplicate, err := isNotificationDuplicate(ctx, notification, inp.EventRepo, inp.DeploymentTargetID)
+	isDuplicate, err := isNotificationDuplicate(ctx, baseNotification, inp.EventRepo, inp.DeploymentTargetID)
 	if err != nil {
 		return telemetry.Error(ctx, span, err, "failed to check if app event is duplicate")
 	}
@@ -49,7 +46,7 @@ func HandleNotification(ctx context.Context, inp HandleNotificationInput) error
 
 	// 4. hydrate notification with k8s deployment info
 	hydratedNotification, err := hydrateNotification(ctx, hydrateNotificationInput{
-		Notification:       notification,
+		Notification:       baseNotification,
 		DeploymentTargetId: inp.DeploymentTargetID,
 		Namespace:          inp.Namespace,
 		K8sAgent:           inp.K8sAgent,
@@ -96,7 +93,7 @@ type Notification struct {
 }
 
 // appEventToNotification converts an app event to a notification
-func appEventToNotification(appEventMetadata AppEventMetadata) (Notification, error) {
+func appEventToNotification(appEventMetadata AppEventMetadata) Notification {
 	humanReadableDetail := appEventMetadata.Detail
 	humanReadableDetail = strings.ReplaceAll(humanReadableDetail, "application", "service")
 
@@ -111,5 +108,5 @@ func appEventToNotification(appEventMetadata AppEventMetadata) (Notification, er
 		Deployment:          Deployment{Status: DeploymentStatus_Unknown},
 		HumanReadableDetail: humanReadableDetail,
 	}
-	return notification, nil
+	return notification
 }

+ 4 - 0
internal/repository/test/porter_app_event.go

@@ -47,3 +47,7 @@ func (repo *PorterAppEventRepository) ReadDeployEventByRevision(ctx context.Cont
 func (repo *PorterAppEventRepository) ReadDeployEventByAppRevisionID(ctx context.Context, porterAppID uint, appRevisionID string) (models.PorterAppEvent, error) {
 	return models.PorterAppEvent{}, errors.New("cannot read database")
 }
+
+func (repo *PorterAppEventRepository) ReadNotificationsByAppRevisionID(ctx context.Context, porterAppID uint, appRevisionID string) ([]*models.PorterAppEvent, error) {
+	return nil, errors.New("cannot read database")
+}