2023-08-29 05:41:59 +00:00
|
|
|
package netmap
|
|
|
|
|
|
|
|
import (
|
|
|
|
"strings"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
2024-05-02 14:13:08 +00:00
|
|
|
var validPlacementPolicy = []string{
|
|
|
|
`REP 2
|
2023-09-08 13:57:41 +00:00
|
|
|
CBF 2
|
|
|
|
SELECT 2 FROM *`,
|
2024-05-02 14:13:08 +00:00
|
|
|
`REP 1 IN X
|
2023-08-29 05:41:59 +00:00
|
|
|
CBF 1
|
|
|
|
SELECT 2 IN SAME Location FROM * AS X`,
|
|
|
|
|
2024-05-02 14:13:08 +00:00
|
|
|
`REP 1 IN X
|
2023-08-29 05:41:59 +00:00
|
|
|
REP 2 IN Y
|
|
|
|
CBF 1
|
|
|
|
SELECT 2 FROM * AS X
|
|
|
|
SELECT 3 FROM * AS Y`,
|
|
|
|
|
2024-05-02 14:13:08 +00:00
|
|
|
`REP 1 IN X
|
2023-08-29 05:41:59 +00:00
|
|
|
SELECT 2 IN City FROM Good AS X
|
|
|
|
FILTER Country EQ RU AS FromRU
|
|
|
|
FILTER Country EQ EN AS FromEN
|
|
|
|
FILTER @FromRU AND @FromEN AND Rating GT 7 AS Good`,
|
|
|
|
|
2024-05-02 14:13:08 +00:00
|
|
|
`REP 7 IN SPB
|
2023-08-29 05:41:59 +00:00
|
|
|
SELECT 1 IN City FROM SPBSSD AS SPB
|
|
|
|
FILTER City EQ SPB AND SSD EQ true OR City EQ SPB AND Rating GE 5 AS SPBSSD`,
|
|
|
|
|
2024-05-02 14:13:08 +00:00
|
|
|
`REP 7 IN SPB
|
2023-08-29 05:41:59 +00:00
|
|
|
SELECT 1 IN City FROM SPBSSD AS SPB
|
|
|
|
FILTER NOT (NOT (City EQ SPB) AND SSD EQ true OR City EQ SPB AND Rating GE 5) AS SPBSSD`,
|
|
|
|
|
2024-05-02 14:13:08 +00:00
|
|
|
`REP 1 IN FNODE
|
2024-03-01 14:30:10 +00:00
|
|
|
CBF 1
|
|
|
|
SELECT 1 FROM F AS FNODE
|
|
|
|
FILTER Node EQ '10.78.8.11' AS F`,
|
|
|
|
|
2024-05-02 14:13:08 +00:00
|
|
|
`UNIQUE
|
2023-08-29 05:41:59 +00:00
|
|
|
REP 1
|
|
|
|
REP 1`,
|
2024-05-02 14:13:08 +00:00
|
|
|
`EC 1.2 IN X
|
2024-02-22 19:29:25 +00:00
|
|
|
SELECT 3 IN City FROM * AS X`,
|
2024-05-02 14:13:08 +00:00
|
|
|
}
|
2023-08-29 05:41:59 +00:00
|
|
|
|
2024-05-02 14:13:08 +00:00
|
|
|
func TestDecodeString(t *testing.T) {
|
2023-08-29 05:41:59 +00:00
|
|
|
var p PlacementPolicy
|
|
|
|
|
2024-05-02 14:13:08 +00:00
|
|
|
for _, testCase := range validPlacementPolicy {
|
2023-08-29 05:41:59 +00:00
|
|
|
require.NoError(t, p.DecodeString(testCase), "unable parse %s", testCase)
|
|
|
|
var b strings.Builder
|
|
|
|
require.NoError(t, p.WriteStringTo(&b))
|
|
|
|
require.Equal(t, testCase, b.String())
|
|
|
|
}
|
|
|
|
|
|
|
|
invalidTestCases := map[string]error{
|
2023-09-08 13:57:41 +00:00
|
|
|
`?REP 1`: errSyntaxError,
|
|
|
|
`REP 1 trailing garbage`: errSyntaxError,
|
|
|
|
`REP 1 REP 1 SELECT 4 FROM *`: errUnnamedSelector,
|
|
|
|
`REP 1 SELECT 4 FROM * SELECT 1 FROM *`: errUnnamedSelector,
|
|
|
|
`REP 1 IN X SELECT 4 FROM *`: errUnknownSelector,
|
2023-08-29 05:41:59 +00:00
|
|
|
`REP 1 IN X REP 2 SELECT 4 FROM * AS X FILTER 'UN-LOCODE' EQ 'RU LED' AS F`: errRedundantFilter,
|
|
|
|
}
|
|
|
|
|
|
|
|
for i := range invalidTestCases {
|
|
|
|
require.ErrorIs(t, p.DecodeString(i), invalidTestCases[i], "#%s", i)
|
|
|
|
}
|
|
|
|
}
|