package model import ( "strings" "testing" "modelRT/orm" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) func TestMeasurementTypeFromDataSource(t *testing.T) { for _, measurementType := range []string{"TM", "TS", "TC", "TA", "SP"} { t.Run(measurementType, func(t *testing.T) { actual, err := MeasurementTypeFromDataSource(orm.JSONMap{ "type": float64(1), "io_address": map[string]any{ "channel": strings.ToLower(measurementType) + "1_test", }, }) require.NoError(t, err) assert.Equal(t, measurementType, actual) }) } } func TestMeasurementTypeFromDataSourceRejectsInvalidValues(t *testing.T) { tests := []orm.JSONMap{ {"type": float64(2), "io_address": map[string]any{"channel": "tm1"}}, {"type": float64(1), "io_address": map[string]any{"channel": "xx1"}}, {"type": float64(1), "io_address": map[string]any{"channel": "t"}}, {"type": "1", "io_address": map[string]any{"channel": "tm1"}}, } for _, dataSource := range tests { _, err := MeasurementTypeFromDataSource(dataSource) require.Error(t, err) } }