1
0
mirror of https://github.com/mainflux/mainflux.git synced 2025-04-29 13:49:28 +08:00
Aleksandar Novaković 3125f0bbc2 MF-722 - Change UUID lib (#746)
* Update uuid package and update things serivce

Signed-off-by: Aleksandar Novakovic <anovakovic01@gmail.com>

* Update bootstrap service tests

Signed-off-by: Aleksandar Novakovic <anovakovic01@gmail.com>

* Update existing postgres writer tests

Signed-off-by: Aleksandar Novakovic <anovakovic01@gmail.com>
2019-05-16 13:35:13 +02:00

65 lines
1.4 KiB
Go

//
// Copyright (c) 2019
// Mainflux
//
// SPDX-License-Identifier: Apache-2.0
//
package postgres_test
import (
"fmt"
"testing"
"time"
"github.com/mainflux/mainflux"
"github.com/mainflux/mainflux/writers/postgres"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/gofrs/uuid"
)
var (
msg = mainflux.Message{}
msgsNum = 42
valueFields = 6
)
func TestMessageSave(t *testing.T) {
messageRepo := postgres.New(db)
chid, err := uuid.NewV4()
require.Nil(t, err, fmt.Sprintf("got unexpected error: %s", err))
msg.Channel = chid.String()
pubid, err := uuid.NewV4()
require.Nil(t, err, fmt.Sprintf("got unexpected error: %s", err))
msg.Publisher = pubid.String()
now := time.Now().Unix()
for i := 0; i < msgsNum; i++ {
// Mix possible values as well as value sum.
count := i % valueFields
switch count {
case 0:
msg.Value = &mainflux.Message_FloatValue{FloatValue: 5}
case 1:
msg.Value = &mainflux.Message_BoolValue{BoolValue: false}
case 2:
msg.Value = &mainflux.Message_StringValue{StringValue: "value"}
case 3:
msg.Value = &mainflux.Message_DataValue{DataValue: "base64data"}
case 4:
msg.ValueSum = nil
case 5:
msg.ValueSum = &mainflux.SumValue{Value: 45}
}
msg.Time = float64(now + int64(i))
err := messageRepo.Save(msg)
assert.Nil(t, err, fmt.Sprintf("expected no error got %s\n", err))
}
}