-
Notifications
You must be signed in to change notification settings - Fork 47
Expand file tree
/
Copy pathxml_errors_test.go
More file actions
77 lines (61 loc) · 1.98 KB
/
xml_errors_test.go
File metadata and controls
77 lines (61 loc) · 1.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
// Copyright 2023-2024 Princess Beef Heavy Industries, LLC / Dave Shanley
// https://pb33f.io
package errors
import (
"testing"
"github.com/pb33f/libopenapi"
"github.com/pb33f/libopenapi-validator/helpers"
"github.com/pb33f/libopenapi/datamodel/high/base"
"github.com/stretchr/testify/assert"
)
func getTestSchema() *base.Schema {
spec := `openapi: 3.0.0
paths:
/pet:
get:
responses:
'200':
content:
application/xml:
schema:
type: object
properties:
age:
type: integer
xml:
name: Cat`
doc, _ := libopenapi.NewDocument([]byte(spec))
v3Doc, _ := doc.BuildV3Model()
return v3Doc.Model.Paths.PathItems.GetOrZero("/pet").Get.Responses.Codes.GetOrZero("200").
Content.GetOrZero("application/xml").Schema.Schema()
}
func TestMissingPrefixError(t *testing.T) {
schema := getTestSchema()
err := MissingPrefix(schema, "prx")
assert.NotNil(t, *err)
assert.Equal(t, helpers.XmlValidationPrefix, (*err).ValidationSubType)
}
func TestMissingNamespaceError(t *testing.T) {
schema := getTestSchema()
err := MissingNamespace(schema, "http://ex.c")
assert.NotNil(t, *err)
assert.Equal(t, helpers.XmlValidationNamespace, (*err).ValidationSubType)
}
func TestInvalidPrefixError(t *testing.T) {
schema := getTestSchema()
err := InvalidPrefix(schema, "prx")
assert.NotNil(t, *err)
assert.Equal(t, helpers.XmlValidationPrefix, (*err).ValidationSubType)
}
func TestInvalidNamespaceError(t *testing.T) {
schema := getTestSchema()
err := InvalidNamespace(schema, "other", "http://ex.c", "prx")
assert.NotNil(t, *err)
assert.Equal(t, helpers.XmlValidationNamespace, (*err).ValidationSubType)
}
func TestInvalidParsing(t *testing.T) {
err := InvalidXmlParsing("no data sent", "invalid-xml")
assert.NotNil(t, (*err))
assert.Equal(t, (*err).SchemaValidationErrors[0].Location, "xml parsing")
assert.Equal(t, helpers.Schema, (*err).ValidationSubType)
}