Skip to content

Commit

Permalink
Merge pull request #146 from xmidt-org/message-type-update
Browse files Browse the repository at this point in the history
updated getMessageType return to LastMessageType
  • Loading branch information
denopink authored Nov 16, 2023
2 parents c62c675 + 21be3d5 commit f8fe56b
Show file tree
Hide file tree
Showing 10 changed files with 29 additions and 29 deletions.
4 changes: 2 additions & 2 deletions messages_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -469,15 +469,15 @@ func TestIsQOSAckPart(t *testing.T) {
},
{
description: "lastMessageType no ack",
msg: Message{Type: lastMessageType, QualityOfService: QOSCriticalValue},
msg: Message{Type: LastMessageType, QualityOfService: QOSCriticalValue},
},
{
description: "Nonexistent negative MessageType no ack",
msg: Message{Type: -10, QualityOfService: QOSCriticalValue},
},
{
description: "Nonexistent positive MessageType no ack",
msg: Message{Type: lastMessageType + 1, QualityOfService: QOSCriticalValue},
msg: Message{Type: LastMessageType + 1, QualityOfService: QOSCriticalValue},
},
}

Expand Down
10 changes: 5 additions & 5 deletions messagetype.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const (
ServiceRegistrationMessageType
ServiceAliveMessageType
UnknownMessageType
lastMessageType
LastMessageType
)

// RequiresTransaction tests if messages of this type are allowed to participate in transactions.
Expand Down Expand Up @@ -69,16 +69,16 @@ var (
)

func init() {
stringToMessageType = make(map[string]MessageType, lastMessageType-1)
friendlyNames = make(map[MessageType]string, lastMessageType-1)
stringToMessageType = make(map[string]MessageType, LastMessageType-1)
friendlyNames = make(map[MessageType]string, LastMessageType-1)
suffixLength := len("MessageType")

// for each MessageType, allow the following string representations:
//
// The integral value of the constant
// The String() value
// The String() value minus the MessageType suffix
for v := SimpleRequestResponseMessageType; v < lastMessageType; v++ {
for v := SimpleRequestResponseMessageType; v < LastMessageType; v++ {
stringToMessageType[strconv.Itoa(int(v))] = v

vs := v.String()
Expand All @@ -99,7 +99,7 @@ func init() {
func StringToMessageType(value string) MessageType {
mt, ok := stringToMessageType[value]
if !ok {
return UnknownMessageType
return LastMessageType
}

return mt
Expand Down
2 changes: 1 addition & 1 deletion messagetype_string.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions messagetype_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ func TestMessageTypeSupportsTransaction(t *testing.T) {
ServiceRegistrationMessageType: false,
ServiceAliveMessageType: false,
UnknownMessageType: false,
lastMessageType: false,
lastMessageType + 1: false,
LastMessageType: false,
LastMessageType + 1: false,
}
)

Expand All @@ -85,8 +85,8 @@ func TestMessageTypeSupportsQOSAck(t *testing.T) {
ServiceRegistrationMessageType: false,
ServiceAliveMessageType: false,
UnknownMessageType: false,
lastMessageType: false,
lastMessageType + 1: false,
LastMessageType: false,
LastMessageType + 1: false,
}
)

Expand Down Expand Up @@ -115,12 +115,12 @@ func testStringToMessageTypeInvalid(t *testing.T, invalid string) {
assert := assert.New(t)

actual := StringToMessageType(invalid)
assert.Equal(UnknownMessageType, actual)
assert.Equal(LastMessageType, actual)
}

func TestStringToMessageType(t *testing.T) {
t.Run("Valid", func(t *testing.T) {
for v := SimpleRequestResponseMessageType; v < lastMessageType; v++ {
for v := SimpleRequestResponseMessageType; v < LastMessageType; v++ {
testStringToMessageTypeValid(t, v)
}
})
Expand Down
12 changes: 6 additions & 6 deletions simpleMessageTypes_validator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ func TestSimpleEventValidators(t *testing.T) {
{
description: "Invaild simple event message error, nonexistent MessageType",
msg: Message{
Type: lastMessageType + 1,
Type: LastMessageType + 1,
Source: "dns:external.com",
Destination: "MAC:11:22:33:44:55:66",
},
Expand Down Expand Up @@ -219,7 +219,7 @@ func TestSimpleResponseRequestValidators(t *testing.T) {
{
description: "Invaild simple request response message error, nonexistent MessageType",
msg: Message{
Type: lastMessageType + 1,
Type: LastMessageType + 1,
Source: "dns:external.com",
Destination: "MAC:11:22:33:44:55:66",
},
Expand Down Expand Up @@ -456,7 +456,7 @@ func testSimpleEventTypeValidator(t *testing.T) {
},
{
description: "lastMessageType error",
msg: Message{Type: lastMessageType},
msg: Message{Type: LastMessageType},
expectedErr: ErrorNotSimpleEventType,
},
{
Expand All @@ -466,7 +466,7 @@ func testSimpleEventTypeValidator(t *testing.T) {
},
{
description: "Nonexistent positive MessageType error",
msg: Message{Type: lastMessageType + 1},
msg: Message{Type: LastMessageType + 1},
expectedErr: ErrorNotSimpleEventType,
},
}
Expand Down Expand Up @@ -562,7 +562,7 @@ func testSimpleResponseRequestTypeValidator(t *testing.T) {
},
{
description: "lastMessageType error",
msg: Message{Type: lastMessageType},
msg: Message{Type: LastMessageType},
expectedErr: ErrorNotSimpleResponseRequestType,
},
{
Expand All @@ -572,7 +572,7 @@ func testSimpleResponseRequestTypeValidator(t *testing.T) {
},
{
description: "Nonexistent positive MessageType error",
msg: Message{Type: lastMessageType + 1},
msg: Message{Type: LastMessageType + 1},
expectedErr: ErrorNotSimpleResponseRequestType,
},
}
Expand Down
4 changes: 2 additions & 2 deletions spec_validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,12 @@ func UTF8Validator(m Message) error {

// MessageTypeValidator takes messages and validates their Type.
func MessageTypeValidator(m Message) error {
if m.Type < Invalid0MessageType || m.Type > lastMessageType {
if m.Type < Invalid0MessageType || m.Type > LastMessageType {
return ErrorInvalidMessageType
}

switch m.Type {
case Invalid0MessageType, Invalid1MessageType, lastMessageType:
case Invalid0MessageType, Invalid1MessageType, LastMessageType:
return ErrorInvalidMessageType
}

Expand Down
6 changes: 3 additions & 3 deletions spec_validator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ func TestSpecValidators(t *testing.T) {
{
description: "Invaild spec error, nonexistent MessageType",
msg: Message{
Type: lastMessageType + 1,
Type: LastMessageType + 1,
Source: "dns:external.com",
Destination: "MAC:11:22:33:44:55:66",
},
Expand Down Expand Up @@ -331,7 +331,7 @@ func testMessageTypeValidator(t *testing.T) {
},
{
description: "lastMessageType error",
msg: Message{Type: lastMessageType},
msg: Message{Type: LastMessageType},
expectedErr: ErrorInvalidMessageType,
},
{
Expand All @@ -341,7 +341,7 @@ func testMessageTypeValidator(t *testing.T) {
},
{
description: "Nonexistent positive MessageType error",
msg: Message{Type: lastMessageType + 1},
msg: Message{Type: LastMessageType + 1},
expectedErr: ErrorInvalidMessageType,
},
}
Expand Down
4 changes: 2 additions & 2 deletions validator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,7 @@ func testAlwaysValid(t *testing.T) {
{
description: "Bad message type success",
msg: Message{
Type: lastMessageType + 1,
Type: LastMessageType + 1,
Source: "dns:external.com",
Destination: "MAC:11:22:33:44:55:66",
},
Expand Down Expand Up @@ -491,7 +491,7 @@ func testAlwaysInvalid(t *testing.T) {
{
description: "Bad message type error",
msg: Message{
Type: lastMessageType + 1,
Type: LastMessageType + 1,
Source: "dns:external.com",
Destination: "MAC:11:22:33:44:55:66",
},
Expand Down
2 changes: 1 addition & 1 deletion wrphttp/decoders_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ func testDecodeRequestHeadersInvalid(t *testing.T) {

request.Header.Set(MessageTypeHeader, "askdjfa;skdjfasdf")
entity, err := DecodeRequestHeaders(context.Background(), request)
assert.Equal(wrp.UnknownMessageType, entity.Message.Type)
assert.Equal(wrp.LastMessageType, entity.Message.Type)
assert.NoError(err)
}

Expand Down
2 changes: 1 addition & 1 deletion wrphttp/headers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ func testNewMessageFromHeadersBadMessageType(t *testing.T) {
assert.Error(err)

message, err = NewMessageFromHeaders(http.Header{MessageTypeHeader: []string{"this could not possibly be a valid message type"}}, nil)
assert.Equal(wrp.UnknownMessageType, message.MessageType())
assert.Equal(wrp.LastMessageType, message.MessageType())
assert.NoError(err)
}

Expand Down

0 comments on commit f8fe56b

Please sign in to comment.