93 lines
2.4 KiB
Go
93 lines
2.4 KiB
Go
package cli
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/go-flucky/flucky/pkg/config"
|
|
"github.com/go-flucky/flucky/pkg/types"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
type testCase struct {
|
|
goldenConfig *config.Configuration
|
|
goldenMeasuredValues []*types.MeasuredValue
|
|
expectedSensors map[string]*types.Sensor
|
|
expectedError error
|
|
}
|
|
|
|
var (
|
|
goldenSensors = []*types.Sensor{
|
|
&types.Sensor{
|
|
ID: "5b7c08c8-ee2a-4f88-b796-83658caae09d",
|
|
},
|
|
}
|
|
|
|
goldenSensorMap = map[string]*types.Sensor{
|
|
"5b7c08c8-ee2a-4f88-b796-83658caae09d": goldenSensors[0],
|
|
}
|
|
|
|
goldenConfig = &config.Configuration{
|
|
Sensors: goldenSensors,
|
|
}
|
|
|
|
goldenMeasuredValues = []*types.MeasuredValue{
|
|
&types.MeasuredValue{
|
|
ID: "4887b7cc-6b40-4293-bcc1-db1b5035a711",
|
|
SensorID: "5b7c08c8-ee2a-4f88-b796-83658caae09d",
|
|
},
|
|
}
|
|
|
|
measuredValuesWrongID = []*types.MeasuredValue{
|
|
&types.MeasuredValue{
|
|
ID: "b2784dfb-c1a4-428d-8897-e09a18e7d94d",
|
|
SensorID: "5b7c08c8-ee2a-4f88-b796-83658caae09d",
|
|
},
|
|
&types.MeasuredValue{
|
|
ID: "81ca1a60-dfea-42f3-a7",
|
|
SensorID: "5b7c08c8-ee2a-4f88-b796-83658caae09d",
|
|
},
|
|
}
|
|
|
|
measuredValuesWrongSensorID = []*types.MeasuredValue{
|
|
&types.MeasuredValue{
|
|
ID: "b2784dfb-c1a4-428d-8897-e09a18e7d94d",
|
|
SensorID: "5b7c08c8-ee2a-4f88-b796-83658caae09d",
|
|
},
|
|
&types.MeasuredValue{
|
|
ID: "b2784dfb-c1a4-428d-8897-e09a18e7d94d",
|
|
SensorID: "5b7c08c8-ee2a-4f88-b79",
|
|
},
|
|
}
|
|
)
|
|
|
|
func TestGetSensorIDsByMeasuredValues(t *testing.T) {
|
|
require := require.New(t)
|
|
|
|
testCases := []*testCase{
|
|
&testCase{
|
|
goldenConfig: goldenConfig,
|
|
goldenMeasuredValues: goldenMeasuredValues,
|
|
expectedSensors: goldenSensorMap,
|
|
expectedError: nil,
|
|
},
|
|
&testCase{
|
|
goldenConfig: goldenConfig,
|
|
goldenMeasuredValues: measuredValuesWrongID,
|
|
expectedSensors: nil,
|
|
expectedError: errorMeasuredValueIDNotValid,
|
|
},
|
|
&testCase{
|
|
goldenConfig: goldenConfig,
|
|
goldenMeasuredValues: measuredValuesWrongSensorID,
|
|
expectedSensors: nil,
|
|
expectedError: errorSensorIDNotValid,
|
|
},
|
|
}
|
|
|
|
for _, testCase := range testCases {
|
|
actualSensors, err := GetSensorIDsByMeasuredValues(testCase.goldenMeasuredValues, testCase.goldenConfig)
|
|
require.EqualValues(testCase.expectedError, err, "Not the expected error")
|
|
require.EqualValues(testCase.expectedSensors, actualSensors, "Returned sensor list not expected")
|
|
}
|
|
}
|