-
Notifications
You must be signed in to change notification settings - Fork 0
/
action_names_test.go
95 lines (85 loc) · 3.87 KB
/
action_names_test.go
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
package logjam
import (
"testing"
. "github.com/smartystreets/goconvey/convey"
)
func TestLegacyActionNameExtractor(t *testing.T) {
Convey("LegacyActionNameExtractor", t, func() {
Convey("extracting action names", func() {
So(legacyActionNameFrom("GET", "/"), ShouldEqual,
"Unknown#unknown")
So(legacyActionNameFrom("GET", "/something"), ShouldEqual,
"Unknown#something")
So(legacyActionNameFrom("GET", "/swagger/index.html"), ShouldEqual,
"Swagger#index.html")
// URLs starting with _system will be ignored.
So(legacyActionNameFrom("GET", "/_system/alive"), ShouldEqual,
"_system#alive")
v1 := "/rest/app/vendor/v1/"
So(legacyActionNameFrom("GET", v1+"industries"), ShouldEqual,
"Rest::App::Vendor::V1::GET#industries")
So(legacyActionNameFrom("GET", v1+"users/1234_foobar"), ShouldEqual,
"Rest::App::Vendor::V1::GET::Users#by_id")
So(legacyActionNameFrom("GET", v1+"users"), ShouldEqual,
"Rest::App::Vendor::V1::GET#users")
So(legacyActionNameFrom("GET", v1+"countries"), ShouldEqual,
"Rest::App::Vendor::V1::GET#countries")
So(legacyActionNameFrom("GET", v1+"disciplines"), ShouldEqual,
"Rest::App::Vendor::V1::GET#disciplines")
So(legacyActionNameFrom("GET", v1+"facets/4567"), ShouldEqual,
"Rest::App::Vendor::V1::GET::Facets#by_id")
So(legacyActionNameFrom("GET", v1+"employment-statuses"), ShouldEqual,
"Rest::App::Vendor::V1::GET#employment_statuses")
So(legacyActionNameFrom("DELETE", v1+"chats/123_fo"), ShouldEqual,
"Rest::App::Vendor::V1::DELETE::Chats#by_id")
So(legacyActionNameFrom("GET", v1+"chats/456_bar"), ShouldEqual,
"Rest::App::Vendor::V1::GET::Chats#by_id")
So(legacyActionNameFrom("GET", v1+"chats"), ShouldEqual,
"Rest::App::Vendor::V1::GET#chats")
So(legacyActionNameFrom("POST", v1+"chats"), ShouldEqual,
"Rest::App::Vendor::V1::POST#chats")
So(legacyActionNameFrom("PATCH", v1+"chats/123_baz"), ShouldEqual,
"Rest::App::Vendor::V1::PATCH::Chats#by_id")
})
})
}
func TestDefaultActionNameExtractor(t *testing.T) {
Convey("DefaultActionNameExtractor", t, func() {
Convey("extracting action names", func() {
So(defaultActionNameFrom("GET", "/"), ShouldEqual,
"Unknown#get")
So(defaultActionNameFrom("GET", "/something"), ShouldEqual,
"Something#get")
So(defaultActionNameFrom("GET", "/swagger/index.html"), ShouldEqual,
"Swagger::Index.Html#get")
// URLs starting with _system will be ignored.
So(defaultActionNameFrom("GET", "/_system/alive"), ShouldEqual,
"System::Alive#get")
v1 := "/rest/app/vendor/v1/"
So(defaultActionNameFrom("GET", v1+"industries"), ShouldEqual,
"Rest::App::Vendor::V1::Industries#get")
So(defaultActionNameFrom("GET", v1+"users/1234_foobar"), ShouldEqual,
"Rest::App::Vendor::V1::Users::Id#get")
So(defaultActionNameFrom("GET", v1+"users"), ShouldEqual,
"Rest::App::Vendor::V1::Users#get")
So(defaultActionNameFrom("GET", v1+"countries"), ShouldEqual,
"Rest::App::Vendor::V1::Countries#get")
So(defaultActionNameFrom("GET", v1+"disciplines"), ShouldEqual,
"Rest::App::Vendor::V1::Disciplines#get")
So(defaultActionNameFrom("GET", v1+"facets/4567"), ShouldEqual,
"Rest::App::Vendor::V1::Facets::Id#get")
So(defaultActionNameFrom("GET", v1+"employment-statuses"), ShouldEqual,
"Rest::App::Vendor::V1::EmploymentStatuses#get")
So(defaultActionNameFrom("DELETE", v1+"chats/123_fo"), ShouldEqual,
"Rest::App::Vendor::V1::Chats::Id#delete")
So(defaultActionNameFrom("GET", v1+"chats/456_bar"), ShouldEqual,
"Rest::App::Vendor::V1::Chats::Id#get")
So(defaultActionNameFrom("GET", v1+"chats"), ShouldEqual,
"Rest::App::Vendor::V1::Chats#get")
So(defaultActionNameFrom("POST", v1+"chats"), ShouldEqual,
"Rest::App::Vendor::V1::Chats#post")
So(defaultActionNameFrom("PATCH", v1+"chats/123_baz"), ShouldEqual,
"Rest::App::Vendor::V1::Chats::Id#patch")
})
})
}