MCPcopy Create free account
hub / github.com/go-dev-frame/sponge / TestHTTPServer

Function TestHTTPServer

internal/server/http_test.go:21–63  ·  view source on GitHub ↗

need real database to test

(t *testing.T)

Source from the content-addressed store, hash-verified

19
20// need real database to test
21func TestHTTPServer(t *testing.T) {
22 err := config.Init(configs.Path("serverNameExample.yml"))
23 if err != nil {
24 t.Fatal(err)
25 }
26 config.Get().App.EnableMetrics = true
27 config.Get().App.EnableTrace = true
28 config.Get().App.EnableHTTPProfile = true
29 config.Get().App.EnableLimit = true
30 config.Get().App.EnableCircuitBreaker = true
31
32 port, _ := utils.GetAvailablePort()
33 addr := fmt.Sprintf(":%d", port)
34 gin.SetMode(gin.ReleaseMode)
35
36 utils.SafeRunWithTimeout(time.Second*2, func(cancel context.CancelFunc) {
37 server := NewHTTPServer(addr,
38 WithHTTPIsProd(true),
39 WithHTTPRegistry(&iRegistry{}, &registry.ServiceInstance{}),
40 )
41 assert.NotNil(t, server)
42 cancel()
43 })
44 utils.SafeRunWithTimeout(time.Second, func(cancel context.CancelFunc) {
45 server := NewHTTPServer(addr)
46 assert.NotNil(t, server)
47 cancel()
48 })
49
50 utils.SafeRunWithTimeout(time.Second*2, func(cancel context.CancelFunc) {
51 server := NewHTTPServer_pbExample(addr,
52 WithHTTPIsProd(true),
53 WithHTTPRegistry(&iRegistry{}, &registry.ServiceInstance{}),
54 )
55 assert.NotNil(t, server)
56 cancel()
57 })
58 utils.SafeRunWithTimeout(time.Second, func(cancel context.CancelFunc) {
59 server := NewHTTPServer_pbExample(addr)
60 assert.NotNil(t, server)
61 cancel()
62 })
63}
64
65func TestHTTPServerMock(t *testing.T) {
66 err := config.Init(configs.Path("serverNameExample.yml"))

Callers

nothing calls this directly

Calls 10

InitFunction · 0.92
PathFunction · 0.92
GetFunction · 0.92
GetAvailablePortFunction · 0.92
SafeRunWithTimeoutFunction · 0.92
NewHTTPServerFunction · 0.85
WithHTTPIsProdFunction · 0.85
WithHTTPRegistryFunction · 0.85
NewHTTPServer_pbExampleFunction · 0.85
FatalMethod · 0.45

Tested by

no test coverage detected