mirror of
https://github.com/akvorado/akvorado.git
synced 2025-12-11 22:14:02 +01:00
console: fix test about reverse filter direction
This commit is contained in:
@@ -44,7 +44,7 @@ type graphHandlerOutput struct {
|
||||
|
||||
// reverseDirection reverts the direction of a provided input
|
||||
func (input graphHandlerInput) reverseDirection() graphHandlerInput {
|
||||
input.Filter.filter = input.Filter.reverseFilter
|
||||
input.Filter.Filter, input.Filter.ReverseFilter = input.Filter.ReverseFilter, input.Filter.Filter
|
||||
dimensions := input.Dimensions
|
||||
input.Dimensions = make([]queryColumn, len(dimensions))
|
||||
for i := range dimensions {
|
||||
@@ -58,7 +58,7 @@ func (input graphHandlerInput) toSQL1(axis int, skipWith bool) string {
|
||||
slot := fmt.Sprintf(`{resolution->%d}`, interval)
|
||||
|
||||
// Filter
|
||||
where := input.Filter.filter
|
||||
where := input.Filter.Filter
|
||||
if where == "" {
|
||||
where = "{timefilter}"
|
||||
} else {
|
||||
@@ -150,7 +150,7 @@ func (c *Component) graphHandlerFunc(gc *gin.Context) {
|
||||
if resolution < time.Second {
|
||||
resolution = time.Second
|
||||
}
|
||||
sqlQuery = c.queryFlowsTable(sqlQuery, input.Filter.mainTableRequired,
|
||||
sqlQuery = c.queryFlowsTable(sqlQuery, input.Filter.MainTableRequired,
|
||||
input.Start, input.End, resolution)
|
||||
gc.Header("X-SQL-Query", strings.ReplaceAll(sqlQuery, "\n", " "))
|
||||
|
||||
|
||||
@@ -25,8 +25,8 @@ func TestGraphInputReverseDirection(t *testing.T) {
|
||||
queryColumnInIfProvider,
|
||||
},
|
||||
Filter: queryFilter{
|
||||
filter: "DstCountry = 'FR' AND SrcCountry = 'US'",
|
||||
reverseFilter: "SrcCountry = 'FR' AND DstCountry = 'US'",
|
||||
Filter: "DstCountry = 'FR' AND SrcCountry = 'US'",
|
||||
ReverseFilter: "SrcCountry = 'FR' AND DstCountry = 'US'",
|
||||
},
|
||||
Units: "l3bps",
|
||||
}
|
||||
@@ -40,8 +40,8 @@ func TestGraphInputReverseDirection(t *testing.T) {
|
||||
queryColumnOutIfProvider,
|
||||
},
|
||||
Filter: queryFilter{
|
||||
reverseFilter: "DstCountry = 'FR' AND SrcCountry = 'US'",
|
||||
filter: "SrcCountry = 'FR' ANd DstCountry = 'US'",
|
||||
Filter: "SrcCountry = 'FR' AND DstCountry = 'US'",
|
||||
ReverseFilter: "DstCountry = 'FR' AND SrcCountry = 'US'",
|
||||
},
|
||||
Units: "l3bps",
|
||||
}
|
||||
@@ -137,7 +137,7 @@ ORDER BY time WITH FILL
|
||||
End: time.Date(2022, 04, 11, 15, 45, 10, 0, time.UTC),
|
||||
Points: 100,
|
||||
Dimensions: []queryColumn{},
|
||||
Filter: queryFilter{filter: "DstCountry = 'FR' AND SrcCountry = 'US'"},
|
||||
Filter: queryFilter{Filter: "DstCountry = 'FR' AND SrcCountry = 'US'"},
|
||||
Units: "l3bps",
|
||||
},
|
||||
Expected: `
|
||||
@@ -161,8 +161,8 @@ ORDER BY time WITH FILL
|
||||
Points: 100,
|
||||
Dimensions: []queryColumn{},
|
||||
Filter: queryFilter{
|
||||
filter: "DstCountry = 'FR' AND SrcCountry = 'US'",
|
||||
reverseFilter: "SrcCountry = 'FR' AND DstCountry = 'US'",
|
||||
Filter: "DstCountry = 'FR' AND SrcCountry = 'US'",
|
||||
ReverseFilter: "SrcCountry = 'FR' AND DstCountry = 'US'",
|
||||
},
|
||||
Units: "l3bps",
|
||||
Bidirectional: true,
|
||||
|
||||
@@ -35,16 +35,16 @@ func (gc *queryColumn) UnmarshalText(input []byte) error {
|
||||
}
|
||||
|
||||
type queryFilter struct {
|
||||
filter string
|
||||
reverseFilter string
|
||||
mainTableRequired bool
|
||||
Filter string
|
||||
ReverseFilter string
|
||||
MainTableRequired bool
|
||||
}
|
||||
|
||||
func (gf queryFilter) String() string {
|
||||
return gf.filter
|
||||
return gf.Filter
|
||||
}
|
||||
func (gf queryFilter) MarshalText() ([]byte, error) {
|
||||
return []byte(gf.filter), nil
|
||||
return []byte(gf.Filter), nil
|
||||
}
|
||||
func (gf *queryFilter) UnmarshalText(input []byte) error {
|
||||
if strings.TrimSpace(string(input)) == "" {
|
||||
@@ -59,9 +59,9 @@ func (gf *queryFilter) UnmarshalText(input []byte) error {
|
||||
meta = &filter.Meta{ReverseDirection: true}
|
||||
reverse, err := filter.Parse("", input, filter.GlobalStore("meta", meta))
|
||||
*gf = queryFilter{
|
||||
filter: direct.(string),
|
||||
reverseFilter: reverse.(string),
|
||||
mainTableRequired: meta.MainTableRequired,
|
||||
Filter: direct.(string),
|
||||
ReverseFilter: reverse.(string),
|
||||
MainTableRequired: meta.MainTableRequired,
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -63,7 +63,7 @@ func TestUnmarshalFilter(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatalf("UnmarshalText(%q) error:\n%+v", tc.Input, err)
|
||||
}
|
||||
if diff := helpers.Diff(qf.filter, tc.Expected); diff != "" {
|
||||
if diff := helpers.Diff(qf.Filter, tc.Expected); diff != "" {
|
||||
t.Fatalf("UnmarshalText(%q) (-got, +want):\n%s", tc.Input, diff)
|
||||
}
|
||||
})
|
||||
|
||||
@@ -43,7 +43,7 @@ type sankeyLink struct {
|
||||
// sankeyHandlerInputToSQL converts a sankey query to an SQL request
|
||||
func (input sankeyHandlerInput) toSQL() (string, error) {
|
||||
// Filter
|
||||
where := input.Filter.filter
|
||||
where := input.Filter.Filter
|
||||
if where == "" {
|
||||
where = "{timefilter}"
|
||||
} else {
|
||||
@@ -115,7 +115,7 @@ func (c *Component) sankeyHandlerFunc(gc *gin.Context) {
|
||||
}
|
||||
|
||||
// Prepare and execute query
|
||||
sqlQuery = c.queryFlowsTable(sqlQuery, input.Filter.mainTableRequired,
|
||||
sqlQuery = c.queryFlowsTable(sqlQuery, input.Filter.MainTableRequired,
|
||||
input.Start, input.End, resolution)
|
||||
gc.Header("X-SQL-Query", strings.ReplaceAll(sqlQuery, "\n", " "))
|
||||
results := []struct {
|
||||
|
||||
@@ -93,7 +93,7 @@ ORDER BY xps DESC`,
|
||||
End: time.Date(2022, 04, 11, 15, 45, 10, 0, time.UTC),
|
||||
Dimensions: []queryColumn{queryColumnSrcAS, queryColumnExporterName},
|
||||
Limit: 10,
|
||||
Filter: queryFilter{filter: "DstCountry = 'FR'"},
|
||||
Filter: queryFilter{Filter: "DstCountry = 'FR'"},
|
||||
Units: "l3bps",
|
||||
},
|
||||
Expected: `
|
||||
|
||||
Reference in New Issue
Block a user