Skip to content
This repository has been archived by the owner on Dec 21, 2023. It is now read-only.

Commit

Permalink
fix: Time property is not lost between Keptn and CloudEvent conversion (
Browse files Browse the repository at this point in the history
  • Loading branch information
thisthat committed Jul 6, 2022
1 parent 61b52e5 commit 3ef0a10
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
1 change: 1 addition & 0 deletions pkg/lib/v0_2_0/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,7 @@ func ToCloudEvent(keptnEvent models.KeptnContextExtendedCE) cloudevents.Event {
event := cloudevents.NewEvent()
event.SetType(*keptnEvent.Type)
event.SetID(keptnEvent.ID)
event.SetTime(keptnEvent.Time)
event.SetSource(*keptnEvent.Source)
event.SetDataContentType(keptnEvent.Contenttype)
event.SetSpecVersion(keptnEvent.Specversion)
Expand Down
8 changes: 7 additions & 1 deletion pkg/lib/v0_2_0/events_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -319,10 +319,13 @@ func TestToCloudEvent(t *testing.T) {
Content string `json:"content"`
}

time := time.Now().UTC()

expected := cloudevents.NewEvent()
expected.SetType("sh.keptn.event.dev.delivery.triggered")
expected.SetID("my-id")
expected.SetSource("source")
expected.SetTime(time)
expected.SetData(cloudevents.ApplicationJSON, TestData{Content: "testdata"})
expected.SetDataContentType(cloudevents.ApplicationJSON)
expected.SetSpecVersion(defaultSpecVersion)
Expand All @@ -342,6 +345,7 @@ func TestToCloudEvent(t *testing.T) {
Triggeredid: "my-triggered-id",
GitCommitID: "git-commit-id",
Type: strutils.Stringp("sh.keptn.event.dev.delivery.triggered"),
Time: time,
}
cloudevent := ToCloudEvent(keptnEvent)
assert.Equal(t, expected, cloudevent)
Expand All @@ -354,6 +358,7 @@ func TestToKeptnEvent(t *testing.T) {
Content string `json:"content"`
}

time := time.Now().UTC()
expected := models.KeptnContextExtendedCE{
Contenttype: "application/json",
Data: map[string]interface{}{"content": "testdata"},
Expand All @@ -362,7 +367,7 @@ func TestToKeptnEvent(t *testing.T) {
Shkeptnspecversion: config.GetKeptnGoUtilsConfig().ShKeptnSpecVersion,
Source: strutils.Stringp("my-source"),
Specversion: defaultSpecVersion,
Time: time.Time{},
Time: time,
Triggeredid: "my-triggered-id",
GitCommitID: "my-commit-id",
Type: strutils.Stringp("sh.keptn.event.dev.delivery.triggered"),
Expand All @@ -372,6 +377,7 @@ func TestToKeptnEvent(t *testing.T) {
ce.SetType("sh.keptn.event.dev.delivery.triggered")
ce.SetID("my-id")
ce.SetSource("my-source")
ce.SetTime(time)
ce.SetDataContentType(cloudevents.ApplicationJSON)
ce.SetSpecVersion(defaultSpecVersion)
ce.SetData(cloudevents.ApplicationJSON, TestData{Content: "testdata"})
Expand Down

0 comments on commit 3ef0a10

Please sign in to comment.