-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrouter_method_test.go
More file actions
93 lines (74 loc) · 2.05 KB
/
router_method_test.go
File metadata and controls
93 lines (74 loc) · 2.05 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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
package forge_test
import (
"net/http"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/xraph/forge"
)
func TestWithMethod_Export(t *testing.T) {
container := forge.NewContainer()
router := forge.NewRouter(forge.WithContainer(container))
// Test that WithMethod is exported and works
err := router.SSE("/events",
func(ctx forge.Context) error {
return ctx.WriteSSE("test", "data")
},
forge.WithMethod(http.MethodPost),
)
require.NoError(t, err)
// Verify route was registered with POST method
routes := router.Routes()
found := false
for _, route := range routes {
if route.Path == "/events" {
found = true
assert.Equal(t, "POST", route.Method)
}
}
assert.True(t, found)
}
func TestWithMethod_DefaultGET(t *testing.T) {
container := forge.NewContainer()
router := forge.NewRouter(forge.WithContainer(container))
// Test default behavior without WithMethod
err := router.SSE("/events",
func(ctx forge.Context) error {
return ctx.WriteSSE("test", "data")
},
)
require.NoError(t, err)
// Verify route defaults to GET
routes := router.Routes()
for _, route := range routes {
if route.Path == "/events" {
assert.Equal(t, "GET", route.Method)
}
}
}
func TestWithMethod_CombineWithOtherOptions(t *testing.T) {
container := forge.NewContainer()
router := forge.NewRouter(forge.WithContainer(container))
// Test combining WithMethod with other options
err := router.SSE("/events",
func(ctx forge.Context) error {
return nil
},
forge.WithMethod(http.MethodPost),
forge.WithName("post-sse"),
forge.WithTags("streaming", "events"),
forge.WithSummary("POST SSE endpoint"),
)
require.NoError(t, err)
// Verify all options are applied
routes := router.Routes()
for _, route := range routes {
if route.Path == "/events" {
assert.Equal(t, "POST", route.Method)
assert.Equal(t, "post-sse", route.Name)
assert.Contains(t, route.Tags, "streaming")
assert.Contains(t, route.Tags, "events")
assert.Equal(t, "POST SSE endpoint", route.Summary)
}
}
}