36 lines
780 B
Go
36 lines
780 B
Go
|
|
package model
|
||
|
|
|
||
|
|
import (
|
||
|
|
"testing"
|
||
|
|
|
||
|
|
"github.com/stretchr/testify/assert"
|
||
|
|
"github.com/stretchr/testify/require"
|
||
|
|
)
|
||
|
|
|
||
|
|
func TestGenerateMeasureIdentifierSupportsJSONNumbers(t *testing.T) {
|
||
|
|
identifier, err := GenerateMeasureIdentifier(map[string]any{
|
||
|
|
"type": float64(2),
|
||
|
|
"io_address": map[string]any{
|
||
|
|
"station": "Station000",
|
||
|
|
"packet": float64(10),
|
||
|
|
"offset": float64(35),
|
||
|
|
},
|
||
|
|
})
|
||
|
|
|
||
|
|
require.NoError(t, err)
|
||
|
|
assert.Equal(t, "station000:104:10:35", identifier)
|
||
|
|
}
|
||
|
|
|
||
|
|
func TestGenerateMeasureIdentifierRejectsFractionalJSONNumbers(t *testing.T) {
|
||
|
|
_, err := GenerateMeasureIdentifier(map[string]any{
|
||
|
|
"type": float64(2),
|
||
|
|
"io_address": map[string]any{
|
||
|
|
"station": "station000",
|
||
|
|
"packet": float64(10.5),
|
||
|
|
"offset": float64(35),
|
||
|
|
},
|
||
|
|
})
|
||
|
|
|
||
|
|
require.Error(t, err)
|
||
|
|
}
|