Skip to content

Commit

Permalink
Added EvenetDataType string (#28)
Browse files Browse the repository at this point in the history
Signed-off-by: Aneesh Puttur <[email protected]>
  • Loading branch information
aneeshkp authored Jun 30, 2021
1 parent f6b1a08 commit 4072da5
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 4 deletions.
29 changes: 28 additions & 1 deletion pkg/channel/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,32 @@ const (

// String represent of Type enum
func (t Type) String() string {
return [...]string{"LISTENER", "SENDER", "EVENT" ,"STATUS"}[t]
return [...]string{"LISTENER", "SENDER", "EVENT", "STATUS"}[t]
}

// EventDataType types passed to cloud events
type EventDataType string

const (
// PTPEvent event type is ptp
PTPEvent EventDataType = "PTP_EVENT"
// PTPStatus event type is ptp status
PTPStatus = "PTP_STATUS"
// HWEvent event type is hw
HWEvent = "HW_EVENT"
// Event event type is generic event
Event = "EVENT"
)

// String return string eventType
func (e EventDataType) String() string {
EventType := [...]string{"PTP_EVENT", "PTP_STATUS", "HW_EVENT", "EVENT"}

x := string(e)
for _, v := range EventType {
if v == x {
return x
}
}
return "EVENT"
}
3 changes: 2 additions & 1 deletion pkg/hwevent/event_marshal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package hwevent_test

import (
"encoding/json"
"github.com/redhat-cne/sdk-go/pkg/channel"
"testing"
"time"

Expand Down Expand Up @@ -43,7 +44,7 @@ func TestMarshal(t *testing.T) {
}{
"struct Data v1": {
event: func() hwevent.Event {
e := hwevent.Event{Type: "Event"}
e := hwevent.Event{Type: channel.Event}
e.SetDataContentType(event.ApplicationJSON)
_ = e.SetDataSchema(schemaURL)
e.Time = &now
Expand Down
2 changes: 1 addition & 1 deletion v1/event/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func PublishCloudEventToLog(e cloudevents.Event) {

// CloudNativeEvent gets Cloud Native Event object
func CloudNativeEvent() event.Event {
return event.Event{Type: "Event"}
return event.Event{Type: channel.Event}
}

// CloudNativeData gets Cloud Native Event object
Expand Down
2 changes: 1 addition & 1 deletion v1/hwevent/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func PublishCloudEventToLog(e cloudevents.Event) {
// CloudNativeEvent gets Cloud Native Event object
func CloudNativeEvent() hwevent.Event {
// TODO: change type like "HwEvent" into Enum
return hwevent.Event{Type: "HwEvent"}
return hwevent.Event{Type: channel.HWEvent}
}

// CloudNativeData gets Cloud Native Event object
Expand Down

0 comments on commit 4072da5

Please sign in to comment.