110 lines
2.4 KiB
Go
110 lines
2.4 KiB
Go
package model
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"modelRT/constants"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestClassifyDataObjectToken(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
token string
|
|
expected constants.DataObjectType
|
|
wantErr string
|
|
}{
|
|
{
|
|
name: "seven-part measurement",
|
|
token: "grid.zone.station.nspath.component.bay.measurement",
|
|
expected: constants.DataObjectTypeMeasurement,
|
|
},
|
|
{
|
|
name: "four-part measurement",
|
|
token: "nspath.component.bay.measurement",
|
|
expected: constants.DataObjectTypeMeasurement,
|
|
},
|
|
{
|
|
name: "two-part measurement",
|
|
token: "nspath.measurement",
|
|
expected: constants.DataObjectTypeMeasurement,
|
|
},
|
|
{
|
|
name: "seven-part parameter",
|
|
token: "grid.zone.station.nspath.component.rated.voltage",
|
|
expected: constants.DataObjectTypeParameter,
|
|
},
|
|
{
|
|
name: "four-part parameter",
|
|
token: "nspath.component.base_extend.description",
|
|
expected: constants.DataObjectTypeParameter,
|
|
},
|
|
{
|
|
name: "component group",
|
|
token: "nspath.component.component.name",
|
|
expected: constants.DataObjectTypeParameter,
|
|
},
|
|
{
|
|
name: "unknown group",
|
|
token: "nspath.component.unknown.name",
|
|
wantErr: "unsupported token6",
|
|
},
|
|
{
|
|
name: "invalid segment count",
|
|
token: "grid.zone.station",
|
|
wantErr: "expected 2, 4, or 7 segments",
|
|
},
|
|
{
|
|
name: "empty segment",
|
|
token: "nspath..bay.measurement",
|
|
wantErr: "token segment cannot be empty",
|
|
},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
actual, err := ClassifyDataObjectToken(tt.token)
|
|
if tt.wantErr != "" {
|
|
require.Error(t, err)
|
|
assert.Contains(t, err.Error(), tt.wantErr)
|
|
assert.Empty(t, actual)
|
|
return
|
|
}
|
|
|
|
require.NoError(t, err)
|
|
assert.Equal(t, tt.expected, actual)
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestClassifyDataObjectTokenParameterGroups(t *testing.T) {
|
|
groups := []string{
|
|
"component",
|
|
"base_extend",
|
|
"rated",
|
|
"setup",
|
|
"model",
|
|
"stable",
|
|
"craft",
|
|
"integrity",
|
|
"behavior",
|
|
}
|
|
|
|
for _, group := range groups {
|
|
t.Run(group, func(t *testing.T) {
|
|
tokens := []string{
|
|
"nspath.component." + group + ".attribute",
|
|
"grid.zone.station.nspath.component." + group + ".attribute",
|
|
}
|
|
|
|
for _, token := range tokens {
|
|
actual, err := ClassifyDataObjectToken(token)
|
|
require.NoError(t, err)
|
|
assert.Equal(t, constants.DataObjectTypeParameter, actual)
|
|
}
|
|
})
|
|
}
|
|
}
|