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
|
package service
import (
"context"
"testing"
"time"
"github.com/sirupsen/logrus"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/authelia/authelia/v4/internal/configuration/schema"
"github.com/authelia/authelia/v4/internal/logging"
"github.com/authelia/authelia/v4/internal/metrics"
"github.com/authelia/authelia/v4/internal/middlewares"
"github.com/authelia/authelia/v4/internal/templates"
)
func TestNewMainServer(t *testing.T) {
tx, err := templates.New(templates.Config{})
require.NoError(t, err)
address, err := schema.NewAddress("tcp://:9091")
require.NoError(t, err)
config := &schema.Configuration{
Server: schema.Server{
Address: &schema.AddressTCP{Address: *address},
},
}
ctx := &testCtx{
Context: context.Background(),
Configuration: config,
Providers: middlewares.Providers{
Templates: tx,
},
Logger: logrus.NewEntry(logging.Logger()),
}
server, err := ProvisionServer(ctx)
assert.NoError(t, err)
assert.NotNil(t, server)
go func() {
require.NoError(t, server.Run())
}()
// Give the service a moment to start.
time.Sleep(100 * time.Millisecond)
assert.Equal(t, "main", server.ServiceName())
assert.Equal(t, "server", server.ServiceType())
assert.NotNil(t, server.Log())
server.Shutdown()
}
func TestNewMetricsServer(t *testing.T) {
tx, err := templates.New(templates.Config{})
require.NoError(t, err)
address, err := schema.NewAddress("tcp://:9891/metrics")
require.NoError(t, err)
config := &schema.Configuration{
Telemetry: schema.Telemetry{
Metrics: schema.TelemetryMetrics{
Enabled: true,
Address: &schema.AddressTCP{Address: *address},
},
},
}
ctx := &testCtx{
Context: context.Background(),
Configuration: config,
Providers: middlewares.Providers{
Templates: tx,
Metrics: metrics.NewPrometheus(),
},
Logger: logrus.NewEntry(logging.Logger()),
}
server, err := ProvisionServerMetrics(ctx)
assert.NoError(t, err)
assert.NotNil(t, server)
go func() {
require.NoError(t, server.Run())
}()
// Give the service a moment to start.
time.Sleep(100 * time.Millisecond)
assert.Equal(t, "metrics", server.ServiceName())
assert.Equal(t, "server", server.ServiceType())
assert.NotNil(t, server.Log())
server.Shutdown()
}
type testCtx struct {
Configuration *schema.Configuration
Providers middlewares.Providers
Logger *logrus.Entry
context.Context
}
func (c *testCtx) GetConfiguration() *schema.Configuration {
return c.Configuration
}
func (c *testCtx) GetProviders() middlewares.Providers {
return c.Providers
}
func (c *testCtx) GetLogger() *logrus.Entry {
return c.Logger
}
|