From 532af4ba32f9e6f1752a79795fcfcf726289a548 Mon Sep 17 00:00:00 2001 From: Mateus Marquezini Date: Sun, 17 Dec 2023 14:21:58 -0300 Subject: [PATCH 1/5] #479 CloudWatchEvent renamed to EventBridgeEvent --- events/README_CloudWatch_Events.md | 4 +-- events/cloudwatch_events.go | 6 ++--- events/cloudwatch_events_test.go | 4 +-- events/cloudwatch_logs.go | 36 +++++++++++++------------- events/cloudwatch_logs_test.go | 26 +++++++++---------- events/codedeploy.go | 2 +- events/codepipeline_cloudwatch.go | 2 +- events/codepipeline_cloudwatch_test.go | 13 +++++----- 8 files changed, 47 insertions(+), 46 deletions(-) diff --git a/events/README_CloudWatch_Events.md b/events/README_CloudWatch_Events.md index b1d16dc7..52ea90c2 100644 --- a/events/README_CloudWatch_Events.md +++ b/events/README_CloudWatch_Events.md @@ -1,7 +1,7 @@ # Sample Function -The following is a Lambda function that receives Amazon CloudWatch event record data as input and writes event detail to Lambda's CloudWatch Logs. Note that by default anything written to Console will be logged as CloudWatch Logs events. +The following is a Lambda function that receives Amazon EventBridge event record data as input and writes event detail to Lambda's CloudWatch Logs. Note that by default anything written to Console will be logged as CloudWatch Logs events. ```go import ( @@ -11,7 +11,7 @@ import ( "github.com/aws/aws-lambda-go/events" ) -func handler(ctx context.Context, event events.CloudWatchEvent) { +func handler(ctx context.Context, event events.EventBridgeEvent) { fmt.Printf("Detail = %s\n", event.Detail) } ``` diff --git a/events/cloudwatch_events.go b/events/cloudwatch_events.go index e3201fdb..8cf7ef51 100644 --- a/events/cloudwatch_events.go +++ b/events/cloudwatch_events.go @@ -5,9 +5,9 @@ import ( "time" ) -// CloudWatchEvent is the outer structure of an event sent via CloudWatch Events. -// For examples of events that come via CloudWatch Events, see https://docs.aws.amazon.com/AmazonCloudWatch/latest/events/EventTypes.html -type CloudWatchEvent struct { +// EventBridgeEvent is the outer structure of an event sent via EventBridge serverless service. +// For examples of events that come via EventBridge, see https://docs.aws.amazon.com/eventbridge/latest/userguide/eb-service-event.html +type EventBridgeEvent struct { Version string `json:"version"` ID string `json:"id"` DetailType string `json:"detail-type"` diff --git a/events/cloudwatch_events_test.go b/events/cloudwatch_events_test.go index 3f49caba..96ef4a6d 100644 --- a/events/cloudwatch_events_test.go +++ b/events/cloudwatch_events_test.go @@ -17,7 +17,7 @@ func TestCloudwatchScheduledEventIdempotency(t *testing.T) { "\"resources\":[\"arn:aws:events:us-east-1:123456789012:rule/SampleRule\"]," + "\"detail\":{}}") - var inputEvent CloudWatchEvent + var inputEvent EventBridgeEvent err := json.Unmarshal(inputJSON, &inputEvent) if err != nil { t.Errorf("Could not unmarshal scheduled event: %v", err) @@ -32,5 +32,5 @@ func TestCloudwatchScheduledEventIdempotency(t *testing.T) { } func TestCloudwatchScheduledEventRequestMalformedJson(t *testing.T) { - test.TestMalformedJson(t, CloudWatchEvent{}) + test.TestMalformedJson(t, EventBridgeEvent{}) } diff --git a/events/cloudwatch_logs.go b/events/cloudwatch_logs.go index 6b74b3b2..8047ee84 100644 --- a/events/cloudwatch_logs.go +++ b/events/cloudwatch_logs.go @@ -7,19 +7,19 @@ import ( "encoding/json" ) -// CloudwatchLogsEvent represents raw data from a cloudwatch logs event -type CloudwatchLogsEvent struct { - AWSLogs CloudwatchLogsRawData `json:"awslogs"` +// EventBridgeEventLogs represents raw data from an eventbridge logs event +type EventBridgeEventLogs struct { + AWSLogs EventBridgeLogsRawData `json:"awslogs"` } -// CloudwatchLogsRawData contains gzipped base64 json representing the bulk -// of a cloudwatch logs event -type CloudwatchLogsRawData struct { +// EventBridgeLogsRawData contains gzipped base64 json representing the bulk +// of an eventbridge logs event +type EventBridgeLogsRawData struct { Data string `json:"data"` } -// Parse returns a struct representing a usable CloudwatchLogs event -func (c CloudwatchLogsRawData) Parse() (d CloudwatchLogsData, err error) { +// Parse returns a struct representing a usable EventBridgeLogs event +func (c EventBridgeLogsRawData) Parse() (d EventBridgeLogsData, err error) { data, err := base64.StdEncoding.DecodeString(c.Data) if err != nil { return @@ -37,18 +37,18 @@ func (c CloudwatchLogsRawData) Parse() (d CloudwatchLogsData, err error) { return } -// CloudwatchLogsData is an unmarshal'd, ungzip'd, cloudwatch logs event -type CloudwatchLogsData struct { - Owner string `json:"owner"` - LogGroup string `json:"logGroup"` - LogStream string `json:"logStream"` - SubscriptionFilters []string `json:"subscriptionFilters"` - MessageType string `json:"messageType"` - LogEvents []CloudwatchLogsLogEvent `json:"logEvents"` +// EventBridgeLogsData is an unmarshal'd, ungzip'd, eventbridge logs event +type EventBridgeLogsData struct { + Owner string `json:"owner"` + LogGroup string `json:"logGroup"` + LogStream string `json:"logStream"` + SubscriptionFilters []string `json:"subscriptionFilters"` + MessageType string `json:"messageType"` + LogEvents []EventBridgeLogEvent `json:"logEvents"` } -// CloudwatchLogsLogEvent represents a log entry from cloudwatch logs -type CloudwatchLogsLogEvent struct { +// EventBridgeLogEvent represents a log entry from eventbridge logs +type EventBridgeLogEvent struct { ID string `json:"id"` Timestamp int64 `json:"timestamp"` Message string `json:"message"` diff --git a/events/cloudwatch_logs_test.go b/events/cloudwatch_logs_test.go index ef0b93e7..9da65a9c 100644 --- a/events/cloudwatch_logs_test.go +++ b/events/cloudwatch_logs_test.go @@ -10,16 +10,16 @@ import ( func TestCloudwatchLogs(t *testing.T) { for _, test := range []struct { - name string - eventJSON string - expectError bool - expectCloudwatchEventData CloudwatchLogsEvent + name string + eventJSON string + expectError bool + expectEventBridgeData EventBridgeEventLogs }{ {"Well formed cloudwatch event", "./testdata/cloudwatch-logs-event.json", false, - CloudwatchLogsEvent{ - AWSLogs: CloudwatchLogsRawData{ + EventBridgeEventLogs{ + AWSLogs: EventBridgeLogsRawData{ Data: "H4sIAAAAAAAAAHWPwQqCQBCGX0Xm7EFtK+smZBEUgXoLCdMhFtKV3akI8d0bLYmibvPPN3wz00CJxmQnTO41whwWQRIctmEcB6sQbFC3CjW3XW8kxpOpP+OC22d1Wml1qZkQGtoMsScxaczKN3plG8zlaHIta5KqWsozoTYw3/djzwhpLwivWFGHGpAFe7DL68JlBUk+l7KSN7tCOEJ4M3/qOI49vMHj+zCKdlFqLaU2ZHV2a4Ct/an0/ivdX8oYc1UVX860fQDQiMdxRQEAAA==", }, }, @@ -29,7 +29,7 @@ func TestCloudwatchLogs(t *testing.T) { t.Run(test.name, func(t *testing.T) { inputJSON := tst.ReadJSONFromFile(t, test.eventJSON) - var inputEvent CloudwatchLogsEvent + var inputEvent EventBridgeEventLogs err := json.Unmarshal(inputJSON, &inputEvent) if err != nil && !test.expectError { @@ -40,8 +40,8 @@ func TestCloudwatchLogs(t *testing.T) { t.Errorf("expected parse error") } - if !reflect.DeepEqual(test.expectCloudwatchEventData, inputEvent) { - t.Errorf("expected: %+v, received: %v", test.expectCloudwatchEventData, inputEvent) + if !reflect.DeepEqual(test.expectEventBridgeData, inputEvent) { + t.Errorf("expected: %+v, received: %v", test.expectEventBridgeData, inputEvent) } }) } @@ -52,12 +52,12 @@ func TestCloudwatchLogsParse(t *testing.T) { name string eventJSON string expectError bool - expectCloudwatchLogsData CloudwatchLogsData + expectCloudwatchLogsData EventBridgeLogsData }{ {"Well formed cloudwatch event", "./testdata/cloudwatch-logs-event.json", false, - CloudwatchLogsData{ + EventBridgeLogsData{ Owner: "123456789123", LogGroup: "testLogGroup", LogStream: "testLogStream", @@ -65,7 +65,7 @@ func TestCloudwatchLogsParse(t *testing.T) { "testFilter", }, MessageType: "DATA_MESSAGE", - LogEvents: []CloudwatchLogsLogEvent{ + LogEvents: []EventBridgeLogEvent{ {ID: "eventId1", Timestamp: 1440442987000, Message: "[ERROR] First test message"}, {ID: "eventId2", Timestamp: 1440442987001, Message: "[ERROR], Second test message"}, }, @@ -76,7 +76,7 @@ func TestCloudwatchLogsParse(t *testing.T) { t.Run(test.name, func(t *testing.T) { inputJSON := tst.ReadJSONFromFile(t, test.eventJSON) - var inputEvent CloudwatchLogsEvent + var inputEvent EventBridgeEventLogs if err := json.Unmarshal(inputJSON, &inputEvent); err != nil { t.Errorf("could not unmarshal event. details: %v", err) } diff --git a/events/codedeploy.go b/events/codedeploy.go index e54eeded..24734aa9 100644 --- a/events/codedeploy.go +++ b/events/codedeploy.go @@ -21,7 +21,7 @@ const ( ) // CodeDeployEvent is documented at: -// https://docs.aws.amazon.com/AmazonCloudWatch/latest/events/EventTypes.html#acd_event_types +// https://docs.aws.amazon.com/eventbridge/latest/userguide/eb-service-event.html#acd_event_types type CodeDeployEvent struct { // AccountID is the id of the AWS account from which the event originated. AccountID string `json:"account"` diff --git a/events/codepipeline_cloudwatch.go b/events/codepipeline_cloudwatch.go index 0beea862..92750f46 100644 --- a/events/codepipeline_cloudwatch.go +++ b/events/codepipeline_cloudwatch.go @@ -43,7 +43,7 @@ const ( // CodePipelineEvent is documented at: // https://docs.aws.amazon.com/AmazonCloudWatch/latest/events/EventTypes.html#codepipeline_event_type -type CodePipelineCloudWatchEvent struct { +type CodePipelineEventBridgeEvent struct { // Version is the version of the event's schema. Version string `json:"version"` diff --git a/events/codepipeline_cloudwatch_test.go b/events/codepipeline_cloudwatch_test.go index e1e21748..cf20b70c 100644 --- a/events/codepipeline_cloudwatch_test.go +++ b/events/codepipeline_cloudwatch_test.go @@ -2,20 +2,21 @@ package events import ( "encoding/json" - "github.com/stretchr/testify/require" "io/ioutil" //nolint: staticcheck "testing" "time" + + "github.com/stretchr/testify/require" ) func TestUnmarshalCodePipelineEvent(t *testing.T) { tests := []struct { input string - expect CodePipelineCloudWatchEvent + expect CodePipelineEventBridgeEvent }{ { input: "testdata/codepipeline-action-execution-stage-change-event.json", - expect: CodePipelineCloudWatchEvent{ + expect: CodePipelineEventBridgeEvent{ Version: "0", ID: "CWE-event-id", DetailType: "CodePipeline Action Execution State Change", @@ -45,7 +46,7 @@ func TestUnmarshalCodePipelineEvent(t *testing.T) { }, { input: "testdata/codepipeline-execution-stage-change-event.json", - expect: CodePipelineCloudWatchEvent{ + expect: CodePipelineEventBridgeEvent{ Version: "0", ID: "CWE-event-id", DetailType: "CodePipeline Stage Execution State Change", @@ -66,7 +67,7 @@ func TestUnmarshalCodePipelineEvent(t *testing.T) { }, { input: "testdata/codepipeline-execution-state-change-event.json", - expect: CodePipelineCloudWatchEvent{ + expect: CodePipelineEventBridgeEvent{ Version: "0", ID: "CWE-event-id", DetailType: "CodePipeline Pipeline Execution State Change", @@ -91,7 +92,7 @@ func TestUnmarshalCodePipelineEvent(t *testing.T) { data, err := ioutil.ReadFile(testcase.input) require.NoError(t, err) - var actual CodePipelineCloudWatchEvent + var actual CodePipelineEventBridgeEvent require.NoError(t, json.Unmarshal(data, &actual)) require.Equal(t, testcase.expect, actual) From de0ba7ce3a805364c593d0635d5000ddefadfcdb Mon Sep 17 00:00:00 2001 From: Mateus Marquezini Date: Sun, 17 Dec 2023 14:35:03 -0300 Subject: [PATCH 2/5] #479 CloudWatchEvent renamed to EventBridgeEvent --- events/codepipeline_cloudwatch.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/events/codepipeline_cloudwatch.go b/events/codepipeline_cloudwatch.go index 92750f46..6b6e75be 100644 --- a/events/codepipeline_cloudwatch.go +++ b/events/codepipeline_cloudwatch.go @@ -42,7 +42,7 @@ const ( ) // CodePipelineEvent is documented at: -// https://docs.aws.amazon.com/AmazonCloudWatch/latest/events/EventTypes.html#codepipeline_event_type +// https://docs.aws.amazon.com/eventbridge/latest/userguide/eb-service-event.html#codepipeline_event_type type CodePipelineEventBridgeEvent struct { // Version is the version of the event's schema. Version string `json:"version"` From ecb3965300e2c78db83dd2b43d4b62ddb9029aaa Mon Sep 17 00:00:00 2001 From: Mateus Marquezini Date: Tue, 19 Dec 2023 19:42:57 -0300 Subject: [PATCH 3/5] #479 code improvements after code review --- events/cloudwatch_events.go | 7 ++--- events/cloudwatch_events_test.go | 4 +-- events/cloudwatch_logs.go | 36 +++++++++++++------------- events/cloudwatch_logs_test.go | 16 ++++++------ events/codedeploy.go | 2 -- events/codepipeline_cloudwatch.go | 6 ++--- events/codepipeline_cloudwatch_test.go | 10 +++---- 7 files changed, 40 insertions(+), 41 deletions(-) diff --git a/events/cloudwatch_events.go b/events/cloudwatch_events.go index 8cf7ef51..4a935c5f 100644 --- a/events/cloudwatch_events.go +++ b/events/cloudwatch_events.go @@ -5,9 +5,8 @@ import ( "time" ) -// EventBridgeEvent is the outer structure of an event sent via EventBridge serverless service. -// For examples of events that come via EventBridge, see https://docs.aws.amazon.com/eventbridge/latest/userguide/eb-service-event.html -type EventBridgeEvent struct { +// CloudWatchEvent is the outer structure of an event sent via EventBridge serverless service. +type CloudWatchEvent struct { Version string `json:"version"` ID string `json:"id"` DetailType string `json:"detail-type"` @@ -18,3 +17,5 @@ type EventBridgeEvent struct { Resources []string `json:"resources"` Detail json.RawMessage `json:"detail"` } + +type EventBridge = CloudWatchEvent diff --git a/events/cloudwatch_events_test.go b/events/cloudwatch_events_test.go index 96ef4a6d..3f49caba 100644 --- a/events/cloudwatch_events_test.go +++ b/events/cloudwatch_events_test.go @@ -17,7 +17,7 @@ func TestCloudwatchScheduledEventIdempotency(t *testing.T) { "\"resources\":[\"arn:aws:events:us-east-1:123456789012:rule/SampleRule\"]," + "\"detail\":{}}") - var inputEvent EventBridgeEvent + var inputEvent CloudWatchEvent err := json.Unmarshal(inputJSON, &inputEvent) if err != nil { t.Errorf("Could not unmarshal scheduled event: %v", err) @@ -32,5 +32,5 @@ func TestCloudwatchScheduledEventIdempotency(t *testing.T) { } func TestCloudwatchScheduledEventRequestMalformedJson(t *testing.T) { - test.TestMalformedJson(t, EventBridgeEvent{}) + test.TestMalformedJson(t, CloudWatchEvent{}) } diff --git a/events/cloudwatch_logs.go b/events/cloudwatch_logs.go index 8047ee84..6b74b3b2 100644 --- a/events/cloudwatch_logs.go +++ b/events/cloudwatch_logs.go @@ -7,19 +7,19 @@ import ( "encoding/json" ) -// EventBridgeEventLogs represents raw data from an eventbridge logs event -type EventBridgeEventLogs struct { - AWSLogs EventBridgeLogsRawData `json:"awslogs"` +// CloudwatchLogsEvent represents raw data from a cloudwatch logs event +type CloudwatchLogsEvent struct { + AWSLogs CloudwatchLogsRawData `json:"awslogs"` } -// EventBridgeLogsRawData contains gzipped base64 json representing the bulk -// of an eventbridge logs event -type EventBridgeLogsRawData struct { +// CloudwatchLogsRawData contains gzipped base64 json representing the bulk +// of a cloudwatch logs event +type CloudwatchLogsRawData struct { Data string `json:"data"` } -// Parse returns a struct representing a usable EventBridgeLogs event -func (c EventBridgeLogsRawData) Parse() (d EventBridgeLogsData, err error) { +// Parse returns a struct representing a usable CloudwatchLogs event +func (c CloudwatchLogsRawData) Parse() (d CloudwatchLogsData, err error) { data, err := base64.StdEncoding.DecodeString(c.Data) if err != nil { return @@ -37,18 +37,18 @@ func (c EventBridgeLogsRawData) Parse() (d EventBridgeLogsData, err error) { return } -// EventBridgeLogsData is an unmarshal'd, ungzip'd, eventbridge logs event -type EventBridgeLogsData struct { - Owner string `json:"owner"` - LogGroup string `json:"logGroup"` - LogStream string `json:"logStream"` - SubscriptionFilters []string `json:"subscriptionFilters"` - MessageType string `json:"messageType"` - LogEvents []EventBridgeLogEvent `json:"logEvents"` +// CloudwatchLogsData is an unmarshal'd, ungzip'd, cloudwatch logs event +type CloudwatchLogsData struct { + Owner string `json:"owner"` + LogGroup string `json:"logGroup"` + LogStream string `json:"logStream"` + SubscriptionFilters []string `json:"subscriptionFilters"` + MessageType string `json:"messageType"` + LogEvents []CloudwatchLogsLogEvent `json:"logEvents"` } -// EventBridgeLogEvent represents a log entry from eventbridge logs -type EventBridgeLogEvent struct { +// CloudwatchLogsLogEvent represents a log entry from cloudwatch logs +type CloudwatchLogsLogEvent struct { ID string `json:"id"` Timestamp int64 `json:"timestamp"` Message string `json:"message"` diff --git a/events/cloudwatch_logs_test.go b/events/cloudwatch_logs_test.go index 9da65a9c..943ca3b8 100644 --- a/events/cloudwatch_logs_test.go +++ b/events/cloudwatch_logs_test.go @@ -13,13 +13,13 @@ func TestCloudwatchLogs(t *testing.T) { name string eventJSON string expectError bool - expectEventBridgeData EventBridgeEventLogs + expectEventBridgeData CloudwatchLogsEvent }{ {"Well formed cloudwatch event", "./testdata/cloudwatch-logs-event.json", false, - EventBridgeEventLogs{ - AWSLogs: EventBridgeLogsRawData{ + CloudwatchLogsEvent{ + AWSLogs: CloudwatchLogsRawData{ Data: "H4sIAAAAAAAAAHWPwQqCQBCGX0Xm7EFtK+smZBEUgXoLCdMhFtKV3akI8d0bLYmibvPPN3wz00CJxmQnTO41whwWQRIctmEcB6sQbFC3CjW3XW8kxpOpP+OC22d1Wml1qZkQGtoMsScxaczKN3plG8zlaHIta5KqWsozoTYw3/djzwhpLwivWFGHGpAFe7DL68JlBUk+l7KSN7tCOEJ4M3/qOI49vMHj+zCKdlFqLaU2ZHV2a4Ct/an0/ivdX8oYc1UVX860fQDQiMdxRQEAAA==", }, }, @@ -29,7 +29,7 @@ func TestCloudwatchLogs(t *testing.T) { t.Run(test.name, func(t *testing.T) { inputJSON := tst.ReadJSONFromFile(t, test.eventJSON) - var inputEvent EventBridgeEventLogs + var inputEvent CloudwatchLogsEvent err := json.Unmarshal(inputJSON, &inputEvent) if err != nil && !test.expectError { @@ -52,12 +52,12 @@ func TestCloudwatchLogsParse(t *testing.T) { name string eventJSON string expectError bool - expectCloudwatchLogsData EventBridgeLogsData + expectCloudwatchLogsData CloudwatchLogsData }{ {"Well formed cloudwatch event", "./testdata/cloudwatch-logs-event.json", false, - EventBridgeLogsData{ + CloudwatchLogsData{ Owner: "123456789123", LogGroup: "testLogGroup", LogStream: "testLogStream", @@ -65,7 +65,7 @@ func TestCloudwatchLogsParse(t *testing.T) { "testFilter", }, MessageType: "DATA_MESSAGE", - LogEvents: []EventBridgeLogEvent{ + LogEvents: []CloudwatchLogsLogEvent{ {ID: "eventId1", Timestamp: 1440442987000, Message: "[ERROR] First test message"}, {ID: "eventId2", Timestamp: 1440442987001, Message: "[ERROR], Second test message"}, }, @@ -76,7 +76,7 @@ func TestCloudwatchLogsParse(t *testing.T) { t.Run(test.name, func(t *testing.T) { inputJSON := tst.ReadJSONFromFile(t, test.eventJSON) - var inputEvent EventBridgeEventLogs + var inputEvent CloudwatchLogsEvent if err := json.Unmarshal(inputJSON, &inputEvent); err != nil { t.Errorf("could not unmarshal event. details: %v", err) } diff --git a/events/codedeploy.go b/events/codedeploy.go index 24734aa9..af239bbf 100644 --- a/events/codedeploy.go +++ b/events/codedeploy.go @@ -20,8 +20,6 @@ const ( CodeDeployDeploymentStateSuccess CodeDeployDeploymentState = "SUCCESS" ) -// CodeDeployEvent is documented at: -// https://docs.aws.amazon.com/eventbridge/latest/userguide/eb-service-event.html#acd_event_types type CodeDeployEvent struct { // AccountID is the id of the AWS account from which the event originated. AccountID string `json:"account"` diff --git a/events/codepipeline_cloudwatch.go b/events/codepipeline_cloudwatch.go index 6b6e75be..41340c4e 100644 --- a/events/codepipeline_cloudwatch.go +++ b/events/codepipeline_cloudwatch.go @@ -41,9 +41,7 @@ const ( CodePipelineActionStateCanceled CodePipelineActionState = "CANCELED" ) -// CodePipelineEvent is documented at: -// https://docs.aws.amazon.com/eventbridge/latest/userguide/eb-service-event.html#codepipeline_event_type -type CodePipelineEventBridgeEvent struct { +type CodePipelineCloudWatchEvent struct { // Version is the version of the event's schema. Version string `json:"version"` @@ -76,6 +74,8 @@ type CodePipelineEventBridgeEvent struct { Detail CodePipelineEventDetail `json:"detail"` } +type CodePipelineEventBridgeEvent = CodePipelineCloudWatchEvent + type CodePipelineEventDetail struct { Pipeline string `json:"pipeline"` diff --git a/events/codepipeline_cloudwatch_test.go b/events/codepipeline_cloudwatch_test.go index cf20b70c..13321980 100644 --- a/events/codepipeline_cloudwatch_test.go +++ b/events/codepipeline_cloudwatch_test.go @@ -12,11 +12,11 @@ import ( func TestUnmarshalCodePipelineEvent(t *testing.T) { tests := []struct { input string - expect CodePipelineEventBridgeEvent + expect CodePipelineCloudWatchEvent }{ { input: "testdata/codepipeline-action-execution-stage-change-event.json", - expect: CodePipelineEventBridgeEvent{ + expect: CodePipelineCloudWatchEvent{ Version: "0", ID: "CWE-event-id", DetailType: "CodePipeline Action Execution State Change", @@ -46,7 +46,7 @@ func TestUnmarshalCodePipelineEvent(t *testing.T) { }, { input: "testdata/codepipeline-execution-stage-change-event.json", - expect: CodePipelineEventBridgeEvent{ + expect: CodePipelineCloudWatchEvent{ Version: "0", ID: "CWE-event-id", DetailType: "CodePipeline Stage Execution State Change", @@ -67,7 +67,7 @@ func TestUnmarshalCodePipelineEvent(t *testing.T) { }, { input: "testdata/codepipeline-execution-state-change-event.json", - expect: CodePipelineEventBridgeEvent{ + expect: CodePipelineCloudWatchEvent{ Version: "0", ID: "CWE-event-id", DetailType: "CodePipeline Pipeline Execution State Change", @@ -92,7 +92,7 @@ func TestUnmarshalCodePipelineEvent(t *testing.T) { data, err := ioutil.ReadFile(testcase.input) require.NoError(t, err) - var actual CodePipelineEventBridgeEvent + var actual CodePipelineCloudWatchEvent require.NoError(t, json.Unmarshal(data, &actual)) require.Equal(t, testcase.expect, actual) From 911280af9c9bd7edcc17c7371d86acd5a25a718e Mon Sep 17 00:00:00 2001 From: Mateus Marquezini Date: Fri, 22 Dec 2023 13:42:58 -0300 Subject: [PATCH 4/5] #479 small fixes after code review --- ...README_CloudWatch_Events.md => README_EventBridge_Events.md} | 0 events/cloudwatch_events.go | 2 +- 2 files changed, 1 insertion(+), 1 deletion(-) rename events/{README_CloudWatch_Events.md => README_EventBridge_Events.md} (100%) diff --git a/events/README_CloudWatch_Events.md b/events/README_EventBridge_Events.md similarity index 100% rename from events/README_CloudWatch_Events.md rename to events/README_EventBridge_Events.md diff --git a/events/cloudwatch_events.go b/events/cloudwatch_events.go index 4a935c5f..0b109ba3 100644 --- a/events/cloudwatch_events.go +++ b/events/cloudwatch_events.go @@ -18,4 +18,4 @@ type CloudWatchEvent struct { Detail json.RawMessage `json:"detail"` } -type EventBridge = CloudWatchEvent +type EventBridgeEvent = CloudWatchEvent From 7d417dd780a93f572205e60590b80d4fcd36ecc6 Mon Sep 17 00:00:00 2001 From: Mateus Marquezini Date: Sat, 23 Dec 2023 18:59:47 -0300 Subject: [PATCH 5/5] #479 small fix after code review --- events/cloudwatch_logs_test.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/events/cloudwatch_logs_test.go b/events/cloudwatch_logs_test.go index 943ca3b8..ef0b93e7 100644 --- a/events/cloudwatch_logs_test.go +++ b/events/cloudwatch_logs_test.go @@ -10,10 +10,10 @@ import ( func TestCloudwatchLogs(t *testing.T) { for _, test := range []struct { - name string - eventJSON string - expectError bool - expectEventBridgeData CloudwatchLogsEvent + name string + eventJSON string + expectError bool + expectCloudwatchEventData CloudwatchLogsEvent }{ {"Well formed cloudwatch event", "./testdata/cloudwatch-logs-event.json", @@ -40,8 +40,8 @@ func TestCloudwatchLogs(t *testing.T) { t.Errorf("expected parse error") } - if !reflect.DeepEqual(test.expectEventBridgeData, inputEvent) { - t.Errorf("expected: %+v, received: %v", test.expectEventBridgeData, inputEvent) + if !reflect.DeepEqual(test.expectCloudwatchEventData, inputEvent) { + t.Errorf("expected: %+v, received: %v", test.expectCloudwatchEventData, inputEvent) } }) }