@@ -5,8 +5,10 @@ import (
55 "net/http/httptest"
66 "testing"
77
8+ broker "github.com/infraboard/mcube/bus/broker/mock"
89 "github.com/infraboard/mcube/exception"
910 "github.com/infraboard/mcube/http/context"
11+ "github.com/infraboard/mcube/http/label"
1012 "github.com/infraboard/mcube/http/mock"
1113 "github.com/infraboard/mcube/http/response"
1214 "github.com/infraboard/mcube/http/router"
@@ -40,6 +42,56 @@ func WithContextHandler(w http.ResponseWriter, r *http.Request) {
4042 return
4143}
4244
45+ func ResourceEventHandler (w http.ResponseWriter , r * http.Request ) {
46+ rctx := context .GetContext (r )
47+
48+ if rctx .Entry == nil {
49+ response .Failed (w , exception .NewBadRequest ("no entry" ))
50+ }
51+
52+ data := & mockResourceEvent {entry : rctx .Entry }
53+ response .Success (w , data )
54+ return
55+ }
56+
57+ type mockResourceEvent struct {
58+ entry * router.Entry
59+ }
60+
61+ func (mre * mockResourceEvent ) ResourceType () string {
62+ if mre .entry == nil {
63+ return ""
64+ }
65+ return mre .entry .Resource
66+ }
67+
68+ func (mre * mockResourceEvent ) ResourceAction () string {
69+ if mre .entry == nil {
70+ return ""
71+ }
72+ return mre .entry .GetLableValue (label .ActionLableKey )
73+ }
74+
75+ func (mre * mockResourceEvent ) ResourceUUID () string {
76+ return "mock-resource-event"
77+ }
78+
79+ func (mre * mockResourceEvent ) ResourceDomain () string {
80+ return "mock-domain"
81+ }
82+
83+ func (mre * mockResourceEvent ) ResourceNamespace () string {
84+ return "mock-namespace"
85+ }
86+
87+ func (mre * mockResourceEvent ) ResourceName () string {
88+ return "mock-name"
89+ }
90+
91+ func (mre * mockResourceEvent ) ResourceData () interface {} {
92+ return nil
93+ }
94+
4395func TestBase (t * testing.T ) {
4496 should := assert .New (t )
4597
@@ -166,3 +218,18 @@ func TestAPIRootOrderOK(t *testing.T) {
166218 should .Equal ("/test3" , es .Items [2 ].Path )
167219 }
168220}
221+
222+ func TestResourceEventOk (t * testing.T ) {
223+ should := assert .New (t )
224+
225+ response .SetEventReporter (broker .NewBroker ())
226+
227+ r := httprouter .New ()
228+ req , _ := http .NewRequest ("GET" , "/" , nil )
229+ w := httptest .NewRecorder ()
230+
231+ r .Handle ("GET" , "/" , ResourceEventHandler )
232+ r .ServeHTTP (w , req )
233+
234+ should .Equal (200 , w .Code )
235+ }
0 commit comments