Skip to content

Commit

Permalink
Bring back tests for allowed empty selections.
Browse files Browse the repository at this point in the history
  • Loading branch information
srebhan committed Jun 1, 2022
1 parent a1e3496 commit 03fe320
Showing 1 changed file with 72 additions and 0 deletions.
72 changes: 72 additions & 0 deletions plugins/parsers/xpath/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1174,6 +1174,78 @@ func TestEmptySelection(t *testing.T) {
}
}

func TestEmptySelectionAllowed(t *testing.T) {
var tests = []struct {
name string
input string
configs []Config
}{
{
name: "empty path",
input: multipleNodesXML,
configs: []Config{
{
Selection: "/Device/NonExisting",
Fields: map[string]string{"value": "number(Value)"},
FieldsInt: map[string]string{"mode": "Value/@mode"},
Tags: map[string]string{},
},
},
},
{
name: "empty pattern",
input: multipleNodesXML,
configs: []Config{
{
Selection: "//NonExisting",
Fields: map[string]string{"value": "number(Value)"},
FieldsInt: map[string]string{"mode": "Value/@mode"},
Tags: map[string]string{},
},
},
},
{
name: "empty axis",
input: multipleNodesXML,
configs: []Config{
{
Selection: "/Device/child::NonExisting",
Fields: map[string]string{"value": "number(Value)"},
FieldsInt: map[string]string{"mode": "Value/@mode"},
Tags: map[string]string{},
},
},
},
{
name: "empty predicate",
input: multipleNodesXML,
configs: []Config{
{
Selection: "/Device[@NonExisting=true]",
Fields: map[string]string{"value": "number(Value)"},
FieldsInt: map[string]string{"mode": "Value/@mode"},
Tags: map[string]string{},
},
},
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
parser := &Parser{
Configs: tt.configs,
AllowEmptySelection: true,
DefaultTags: map[string]string{},
Log: testutil.Logger{Name: "parsers.xml"},
}
require.NoError(t, parser.Init())

_, err := parser.Parse([]byte(tt.input))
require.NoError(t, err)
})
}
}

func TestTestCases(t *testing.T) {
var tests = []struct {
name string
Expand Down

0 comments on commit 03fe320

Please sign in to comment.