forked from zalando/zally
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ExtractBasePathRuleTest.kt
123 lines (106 loc) · 3.79 KB
/
ExtractBasePathRuleTest.kt
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
package de.zalando.zally.rule.zally
import de.zalando.zally.getOpenApiContextFromContent
import de.zalando.zally.getSwaggerContextFromContent
import de.zalando.zally.rule.ZallyAssertions
import org.intellij.lang.annotations.Language
import org.junit.Test
class ExtractBasePathRuleTest {
private val rule = ExtractBasePathRule()
@Test
fun `validate swagger with no paths returns no violations`() {
@Language("YAML")
val context = getSwaggerContextFromContent("""
swagger: 2.0
""".trimIndent())
ZallyAssertions
.assertThat(rule.validate(context))
.isEmpty()
}
@Test
fun `validate swagger with no common first segments returns no violations`() {
@Language("YAML")
val context = getSwaggerContextFromContent("""
swagger: 2.0
paths:
/orders/{order_id}: {}
/orders/{updates}: {}
/merchants: {}
""".trimIndent())
ZallyAssertions
.assertThat(rule.validate(context))
.isEmpty()
}
@Test
fun `validate swagger with single path returns no violations`() {
@Language("YAML")
val context = getSwaggerContextFromContent("""
swagger: 2.0
paths:
/orders/{order_id}: {}
""".trimIndent())
ZallyAssertions
.assertThat(rule.validate(context))
.isEmpty()
}
@Test
fun `validate swagger with common first segment returns violation`() {
@Language("YAML")
val context = getSwaggerContextFromContent("""
swagger: 2.0
paths:
/shipment/{shipment_id}: {}
/shipment/{shipment_id}/status: {}
/shipment/{shipment_id}/details: {}
""".trimIndent())
ZallyAssertions
.assertThat(rule.validate(context))
.descriptionsEqualTo("All paths start with prefix '/shipment' which could be part of basePath.")
.pointersEqualTo("/paths")
}
@Test
fun `validate swagger with multiple common first segments returns violation`() {
@Language("YAML")
val context = getSwaggerContextFromContent("""
swagger: 2.0
paths:
/queue/models/configs/{config-id}: {}
/queue/models/: {}
/queue/models/{model-id}: {}
/queue/models/summaries: {}
""".trimIndent())
ZallyAssertions
.assertThat(rule.validate(context))
.descriptionsEqualTo("All paths start with prefix '/queue/models' which could be part of basePath.")
.pointersEqualTo("/paths")
}
@Test
fun `validate swagger with common prefix but no common first segments returns no violations`() {
@Language("YAML")
val context = getSwaggerContextFromContent("""
swagger: 2.0
paths:
/api/{api_id}/deployments: {}
/api/{api_id}/: {}
/applications/{app_id}: {}
/applications/: {}
""".trimIndent())
ZallyAssertions
.assertThat(rule.validate(context))
.isEmpty()
}
@Test
fun `validate openapi with common first segment returns violation`() {
@Language("YAML")
val context = getOpenApiContextFromContent("""
openapi: 3.0.1
paths:
/shipment/{shipment_id}: {}
/shipment/{shipment_id}/status: {}
/shipment/{shipment_id}/details: {}
""".trimIndent())
ZallyAssertions
.assertThat(rule.validate(context))
.descriptionsEqualTo("All paths start with prefix '/shipment' which could be part of servers' urls.")
.pointersEqualTo("/paths")
}
}