Fix protobuf ImageType change

This commit is contained in:
Samuel Hawksby-Robinson 2020-10-26 13:01:46 +00:00 committed by Andrea Maria Piana
parent e8d883edb6
commit 5a4e23a0ea
4 changed files with 15 additions and 15 deletions

View File

@ -27,7 +27,7 @@ func TestPrepareContentImage(t *testing.T) {
message.ContentType = protobuf.ChatMessage_IMAGE
image := protobuf.ImageMessage{
Payload: payload,
Type: protobuf.ImageMessage_JPEG,
Type: protobuf.ImageType_JPEG,
}
message.Payload = &protobuf.ChatMessage_Image{Image: &image}
@ -36,27 +36,27 @@ func TestPrepareContentImage(t *testing.T) {
}
func TestGetImageMessageMIME(t *testing.T) {
jpeg := &protobuf.ImageMessage{Type: protobuf.ImageMessage_JPEG}
jpeg := &protobuf.ImageMessage{Type: protobuf.ImageType_JPEG}
mime, err := getImageMessageMIME(jpeg)
require.NoError(t, err)
require.Equal(t, "jpeg", mime)
png := &protobuf.ImageMessage{Type: protobuf.ImageMessage_PNG}
png := &protobuf.ImageMessage{Type: protobuf.ImageType_PNG}
mime, err = getImageMessageMIME(png)
require.NoError(t, err)
require.Equal(t, "png", mime)
webp := &protobuf.ImageMessage{Type: protobuf.ImageMessage_WEBP}
webp := &protobuf.ImageMessage{Type: protobuf.ImageType_WEBP}
mime, err = getImageMessageMIME(webp)
require.NoError(t, err)
require.Equal(t, "webp", mime)
gif := &protobuf.ImageMessage{Type: protobuf.ImageMessage_GIF}
gif := &protobuf.ImageMessage{Type: protobuf.ImageType_GIF}
mime, err = getImageMessageMIME(gif)
require.NoError(t, err)
require.Equal(t, "gif", mime)
unknown := &protobuf.ImageMessage{Type: protobuf.ImageMessage_UNKNOWN_IMAGE_TYPE}
unknown := &protobuf.ImageMessage{Type: protobuf.ImageType_UNKNOWN_IMAGE_TYPE}
_, err = getImageMessageMIME(unknown)
require.Error(t, err)
}
@ -92,7 +92,7 @@ func TestGetAudioMessageMIME(t *testing.T) {
require.NoError(t, err)
require.Equal(t, "amr", mime)
unknown := &protobuf.ImageMessage{Type: protobuf.ImageMessage_UNKNOWN_IMAGE_TYPE}
unknown := &protobuf.ImageMessage{Type: protobuf.ImageType_UNKNOWN_IMAGE_TYPE}
_, err = getImageMessageMIME(unknown)
require.Error(t, err)
}

View File

@ -5,17 +5,17 @@ import (
"github.com/status-im/status-go/protocol/protobuf"
)
func ImageType(buf []byte) protobuf.ImageMessage_ImageType {
func ImageType(buf []byte) protobuf.ImageType {
switch images.GetFileType(buf){
case images.JPEG:
return protobuf.ImageMessage_JPEG
return protobuf.ImageType_JPEG
case images.PNG:
return protobuf.ImageMessage_PNG
return protobuf.ImageType_PNG
case images.GIF:
return protobuf.ImageMessage_GIF
return protobuf.ImageType_GIF
case images.WEBP:
return protobuf.ImageMessage_WEBP
return protobuf.ImageType_WEBP
default:
return protobuf.ImageMessage_UNKNOWN_IMAGE_TYPE
return protobuf.ImageType_UNKNOWN_IMAGE_TYPE
}
}

View File

@ -208,7 +208,7 @@ func ValidateReceivedChatMessage(message *protobuf.ChatMessage, whisperTimestamp
if len(image.Payload) == 0 {
return errors.New("image payload empty")
}
if image.Type == protobuf.ImageMessage_UNKNOWN_IMAGE_TYPE {
if image.Type == protobuf.ImageType_UNKNOWN_IMAGE_TYPE {
return errors.New("image type unknown")
}
}

View File

@ -390,7 +390,7 @@ func (s *MessageValidatorSuite) TestValidatePlainTextMessage() {
EnsName: "",
Payload: &protobuf.ChatMessage_Image{
Image: &protobuf.ImageMessage{
Type: protobuf.ImageMessage_UNKNOWN_IMAGE_TYPE,
Type: protobuf.ImageType_UNKNOWN_IMAGE_TYPE,
Payload: []byte("some-payload"),
},
},