mirror of
https://github.com/akvorado/akvorado.git
synced 2025-12-12 06:24:10 +01:00
console: turn authentication into a proper component
This commit is contained in:
@@ -10,6 +10,7 @@ import (
|
|||||||
"akvorado/common/http"
|
"akvorado/common/http"
|
||||||
"akvorado/common/reporter"
|
"akvorado/common/reporter"
|
||||||
"akvorado/console"
|
"akvorado/console"
|
||||||
|
"akvorado/console/authentication"
|
||||||
)
|
)
|
||||||
|
|
||||||
// ConsoleConfiguration represents the configuration file for the console command.
|
// ConsoleConfiguration represents the configuration file for the console command.
|
||||||
@@ -18,6 +19,7 @@ type ConsoleConfiguration struct {
|
|||||||
HTTP http.Configuration
|
HTTP http.Configuration
|
||||||
Console console.Configuration
|
Console console.Configuration
|
||||||
ClickHouse clickhousedb.Configuration
|
ClickHouse clickhousedb.Configuration
|
||||||
|
Auth authentication.Configuration
|
||||||
}
|
}
|
||||||
|
|
||||||
// DefaultConsoleConfiguration is the default configuration for the console command.
|
// DefaultConsoleConfiguration is the default configuration for the console command.
|
||||||
@@ -27,6 +29,7 @@ func DefaultConsoleConfiguration() ConsoleConfiguration {
|
|||||||
Reporting: reporter.DefaultConfiguration(),
|
Reporting: reporter.DefaultConfiguration(),
|
||||||
Console: console.DefaultConfiguration(),
|
Console: console.DefaultConfiguration(),
|
||||||
ClickHouse: clickhousedb.DefaultConfiguration(),
|
ClickHouse: clickhousedb.DefaultConfiguration(),
|
||||||
|
Auth: authentication.DefaultConfiguration(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -85,6 +88,10 @@ func consoleStart(r *reporter.Reporter, config ConsoleConfiguration, checkOnly b
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("unable to initialize ClickHouse component: %w", err)
|
return fmt.Errorf("unable to initialize ClickHouse component: %w", err)
|
||||||
}
|
}
|
||||||
|
authenticationComponent, err := authentication.New(r, config.Auth)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("unable to initialize authentication component: %w", err)
|
||||||
|
}
|
||||||
consoleComponent, err := console.New(r, config.Console, console.Dependencies{
|
consoleComponent, err := console.New(r, config.Console, console.Dependencies{
|
||||||
Daemon: daemonComponent,
|
Daemon: daemonComponent,
|
||||||
HTTP: httpComponent,
|
HTTP: httpComponent,
|
||||||
@@ -107,6 +114,7 @@ func consoleStart(r *reporter.Reporter, config ConsoleConfiguration, checkOnly b
|
|||||||
components := []interface{}{
|
components := []interface{}{
|
||||||
httpComponent,
|
httpComponent,
|
||||||
clickhouseComponent,
|
clickhouseComponent,
|
||||||
|
authenticationComponent,
|
||||||
consoleComponent,
|
consoleComponent,
|
||||||
}
|
}
|
||||||
return StartStopComponents(r, daemonComponent, components)
|
return StartStopComponents(r, daemonComponent, components)
|
||||||
|
|||||||
@@ -3,10 +3,7 @@ package console
|
|||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"akvorado/common/daemon"
|
|
||||||
"akvorado/common/helpers"
|
"akvorado/common/helpers"
|
||||||
"akvorado/common/http"
|
|
||||||
"akvorado/common/reporter"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestServeAssets(t *testing.T) {
|
func TestServeAssets(t *testing.T) {
|
||||||
@@ -19,17 +16,9 @@ func TestServeAssets(t *testing.T) {
|
|||||||
name = "embeddedfs"
|
name = "embeddedfs"
|
||||||
}
|
}
|
||||||
t.Run(name, func(t *testing.T) {
|
t.Run(name, func(t *testing.T) {
|
||||||
r := reporter.NewMock(t)
|
|
||||||
h := http.NewMock(t, r)
|
|
||||||
conf := DefaultConfiguration()
|
conf := DefaultConfiguration()
|
||||||
conf.ServeLiveFS = live
|
conf.ServeLiveFS = live
|
||||||
c, err := New(r, conf, Dependencies{
|
c, h, _, _ := NewMock(t, conf)
|
||||||
Daemon: daemon.NewMock(t),
|
|
||||||
HTTP: h,
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("New() error:\n%+v", err)
|
|
||||||
}
|
|
||||||
helpers.StartStop(t, c)
|
helpers.StartStop(t, c)
|
||||||
|
|
||||||
helpers.TestHTTPEndpoints(t, h.Address, helpers.HTTPEndpointCases{
|
helpers.TestHTTPEndpoints(t, h.Address, helpers.HTTPEndpointCases{
|
||||||
|
|||||||
19
console/authentication/tests.go
Normal file
19
console/authentication/tests.go
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
//go:build !release
|
||||||
|
|
||||||
|
package authentication
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"akvorado/common/reporter"
|
||||||
|
)
|
||||||
|
|
||||||
|
// NewMock instantiantes a new authentication component
|
||||||
|
func NewMock(t *testing.T, r *reporter.Reporter) *Component {
|
||||||
|
t.Helper()
|
||||||
|
c, err := New(r, DefaultConfiguration())
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("New() error:\n%+v", err)
|
||||||
|
}
|
||||||
|
return c
|
||||||
|
}
|
||||||
@@ -4,28 +4,13 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"akvorado/common/clickhousedb"
|
|
||||||
"akvorado/common/daemon"
|
|
||||||
"akvorado/common/helpers"
|
"akvorado/common/helpers"
|
||||||
"akvorado/common/http"
|
|
||||||
"akvorado/common/reporter"
|
|
||||||
|
|
||||||
"github.com/golang/mock/gomock"
|
"github.com/golang/mock/gomock"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestRefreshFlowsTables(t *testing.T) {
|
func TestRefreshFlowsTables(t *testing.T) {
|
||||||
r := reporter.NewMock(t)
|
c, _, mockConn, _ := NewMock(t, DefaultConfiguration())
|
||||||
ch, mockConn := clickhousedb.NewMock(t, r)
|
|
||||||
h := http.NewMock(t, r)
|
|
||||||
c, err := New(r, DefaultConfiguration(), Dependencies{
|
|
||||||
Daemon: daemon.NewMock(t),
|
|
||||||
HTTP: h,
|
|
||||||
ClickHouseDB: ch,
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("New() error:\n%+v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
mockConn.EXPECT().
|
mockConn.EXPECT().
|
||||||
Select(gomock.Any(), gomock.Any(), `
|
Select(gomock.Any(), gomock.Any(), `
|
||||||
SELECT name
|
SELECT name
|
||||||
@@ -183,17 +168,8 @@ func TestQueryFlowsTables(t *testing.T) {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
r := reporter.NewMock(t)
|
c, _, _, _ := NewMock(t, DefaultConfiguration())
|
||||||
ch, _ := clickhousedb.NewMock(t, r)
|
helpers.StartStop(t, c)
|
||||||
h := http.NewMock(t, r)
|
|
||||||
c, err := New(r, DefaultConfiguration(), Dependencies{
|
|
||||||
Daemon: daemon.NewMock(t),
|
|
||||||
HTTP: h,
|
|
||||||
ClickHouseDB: ch,
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("New() error:\n%+v", err)
|
|
||||||
}
|
|
||||||
for _, tc := range cases {
|
for _, tc := range cases {
|
||||||
t.Run(tc.Description, func(t *testing.T) {
|
t.Run(tc.Description, func(t *testing.T) {
|
||||||
c.flowsTables = tc.Tables
|
c.flowsTables = tc.Tables
|
||||||
|
|||||||
@@ -1,18 +1,12 @@
|
|||||||
package console
|
package console
|
||||||
|
|
||||||
import "akvorado/console/authentication"
|
|
||||||
|
|
||||||
// Configuration describes the configuration for the console component.
|
// Configuration describes the configuration for the console component.
|
||||||
type Configuration struct {
|
type Configuration struct {
|
||||||
// ServeLiveFS serve files from the filesystem instead of the embedded versions.
|
// ServeLiveFS serve files from the filesystem instead of the embedded versions.
|
||||||
ServeLiveFS bool
|
ServeLiveFS bool
|
||||||
// Authentication describes authentication configuration
|
|
||||||
Authentication authentication.Configuration
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// DefaultConfiguration represents the default configuration for the console component.
|
// DefaultConfiguration represents the default configuration for the console component.
|
||||||
func DefaultConfiguration() Configuration {
|
func DefaultConfiguration() Configuration {
|
||||||
return Configuration{
|
return Configuration{}
|
||||||
Authentication: authentication.DefaultConfiguration(),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,10 +7,7 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"akvorado/common/daemon"
|
|
||||||
"akvorado/common/helpers"
|
"akvorado/common/helpers"
|
||||||
"akvorado/common/http"
|
|
||||||
"akvorado/common/reporter"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestServeDocs(t *testing.T) {
|
func TestServeDocs(t *testing.T) {
|
||||||
@@ -28,17 +25,9 @@ func TestServeDocs(t *testing.T) {
|
|||||||
}
|
}
|
||||||
for _, tc := range cases {
|
for _, tc := range cases {
|
||||||
t.Run(fmt.Sprintf("%s-%s", name, tc.Path), func(t *testing.T) {
|
t.Run(fmt.Sprintf("%s-%s", name, tc.Path), func(t *testing.T) {
|
||||||
r := reporter.NewMock(t)
|
|
||||||
h := http.NewMock(t, r)
|
|
||||||
conf := DefaultConfiguration()
|
conf := DefaultConfiguration()
|
||||||
conf.ServeLiveFS = live
|
conf.ServeLiveFS = live
|
||||||
c, err := New(r, conf, Dependencies{
|
c, h, _, _ := NewMock(t, conf)
|
||||||
Daemon: daemon.NewMock(t),
|
|
||||||
HTTP: h,
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("New() error:\n%+v", err)
|
|
||||||
}
|
|
||||||
helpers.StartStop(t, c)
|
helpers.StartStop(t, c)
|
||||||
|
|
||||||
resp, err := netHTTP.Get(fmt.Sprintf("http://%s/api/v0/console/docs/%s",
|
resp, err := netHTTP.Get(fmt.Sprintf("http://%s/api/v0/console/docs/%s",
|
||||||
|
|||||||
@@ -6,25 +6,11 @@ import (
|
|||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
"github.com/golang/mock/gomock"
|
"github.com/golang/mock/gomock"
|
||||||
|
|
||||||
"akvorado/common/clickhousedb"
|
|
||||||
"akvorado/common/daemon"
|
|
||||||
"akvorado/common/helpers"
|
"akvorado/common/helpers"
|
||||||
"akvorado/common/http"
|
|
||||||
"akvorado/common/reporter"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestFilterHandlers(t *testing.T) {
|
func TestFilterHandlers(t *testing.T) {
|
||||||
r := reporter.NewMock(t)
|
c, h, mockConn, _ := NewMock(t, DefaultConfiguration())
|
||||||
ch, mockConn := clickhousedb.NewMock(t, r)
|
|
||||||
h := http.NewMock(t, r)
|
|
||||||
c, err := New(r, DefaultConfiguration(), Dependencies{
|
|
||||||
Daemon: daemon.NewMock(t),
|
|
||||||
HTTP: h,
|
|
||||||
ClickHouseDB: ch,
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("New() error:\n%+v", err)
|
|
||||||
}
|
|
||||||
helpers.StartStop(t, c)
|
helpers.StartStop(t, c)
|
||||||
|
|
||||||
mockConn.EXPECT().
|
mockConn.EXPECT().
|
||||||
|
|||||||
@@ -6,11 +6,7 @@
|
|||||||
@update:model-value="(item) => $emit('update:modelValue', item)"
|
@update:model-value="(item) => $emit('update:modelValue', item)"
|
||||||
>
|
>
|
||||||
<div class="relative">
|
<div class="relative">
|
||||||
<InputBase
|
<InputBase v-slot="{ id, childClass }" v-bind="otherAttrs" :error="error">
|
||||||
v-slot="{ id, childClass }"
|
|
||||||
v-bind="otherAttrs"
|
|
||||||
:error="error"
|
|
||||||
>
|
|
||||||
<ListboxButton :id="id" :class="childClass">
|
<ListboxButton :id="id" :class="childClass">
|
||||||
<span class="block truncate pr-10 text-left">
|
<span class="block truncate pr-10 text-left">
|
||||||
<slot name="selected"></slot>
|
<slot name="selected"></slot>
|
||||||
|
|||||||
@@ -8,11 +8,7 @@ import (
|
|||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
"github.com/golang/mock/gomock"
|
"github.com/golang/mock/gomock"
|
||||||
|
|
||||||
"akvorado/common/clickhousedb"
|
|
||||||
"akvorado/common/daemon"
|
|
||||||
"akvorado/common/helpers"
|
"akvorado/common/helpers"
|
||||||
"akvorado/common/http"
|
|
||||||
"akvorado/common/reporter"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestGraphQuerySQL(t *testing.T) {
|
func TestGraphQuerySQL(t *testing.T) {
|
||||||
@@ -144,17 +140,7 @@ ORDER BY time`,
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestGraphHandler(t *testing.T) {
|
func TestGraphHandler(t *testing.T) {
|
||||||
r := reporter.NewMock(t)
|
c, h, mockConn, _ := NewMock(t, DefaultConfiguration())
|
||||||
ch, mockConn := clickhousedb.NewMock(t, r)
|
|
||||||
h := http.NewMock(t, r)
|
|
||||||
c, err := New(r, DefaultConfiguration(), Dependencies{
|
|
||||||
Daemon: daemon.NewMock(t),
|
|
||||||
HTTP: h,
|
|
||||||
ClickHouseDB: ch,
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("New() error:\n%+v", err)
|
|
||||||
}
|
|
||||||
helpers.StartStop(t, c)
|
helpers.StartStop(t, c)
|
||||||
|
|
||||||
base := time.Date(2009, time.November, 10, 23, 0, 0, 0, time.UTC)
|
base := time.Date(2009, time.November, 10, 23, 0, 0, 0, time.UTC)
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ type Dependencies struct {
|
|||||||
HTTP *http.Component
|
HTTP *http.Component
|
||||||
ClickHouseDB *clickhousedb.Component
|
ClickHouseDB *clickhousedb.Component
|
||||||
Clock clock.Clock
|
Clock clock.Clock
|
||||||
auth *authentication.Component
|
Auth *authentication.Component
|
||||||
}
|
}
|
||||||
|
|
||||||
// New creates a new console component.
|
// New creates a new console component.
|
||||||
@@ -54,11 +54,6 @@ func New(r *reporter.Reporter, config Configuration, dependencies Dependencies)
|
|||||||
if dependencies.Clock == nil {
|
if dependencies.Clock == nil {
|
||||||
dependencies.Clock = clock.New()
|
dependencies.Clock = clock.New()
|
||||||
}
|
}
|
||||||
auth, err := authentication.New(r, config.Authentication)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
dependencies.auth = auth
|
|
||||||
c := Component{
|
c := Component{
|
||||||
r: r,
|
r: r,
|
||||||
d: &dependencies,
|
d: &dependencies,
|
||||||
@@ -82,7 +77,7 @@ func (c *Component) Start() error {
|
|||||||
c.r.Info().Msg("starting console component")
|
c.r.Info().Msg("starting console component")
|
||||||
|
|
||||||
c.d.HTTP.AddHandler("/", netHTTP.HandlerFunc(c.assetsHandlerFunc))
|
c.d.HTTP.AddHandler("/", netHTTP.HandlerFunc(c.assetsHandlerFunc))
|
||||||
endpoint := c.d.HTTP.GinRouter.Group("/api/v0/console", c.d.auth.UserAuthentication())
|
endpoint := c.d.HTTP.GinRouter.Group("/api/v0/console", c.d.Auth.UserAuthentication())
|
||||||
endpoint.GET("/docs/:name", c.docsHandlerFunc)
|
endpoint.GET("/docs/:name", c.docsHandlerFunc)
|
||||||
endpoint.GET("/widget/flow-last", c.widgetFlowLastHandlerFunc)
|
endpoint.GET("/widget/flow-last", c.widgetFlowLastHandlerFunc)
|
||||||
endpoint.GET("/widget/flow-rate", c.widgetFlowRateHandlerFunc)
|
endpoint.GET("/widget/flow-rate", c.widgetFlowRateHandlerFunc)
|
||||||
@@ -93,8 +88,8 @@ func (c *Component) Start() error {
|
|||||||
endpoint.POST("/sankey", c.sankeyHandlerFunc)
|
endpoint.POST("/sankey", c.sankeyHandlerFunc)
|
||||||
endpoint.POST("/filter/validate", c.filterValidateHandlerFunc)
|
endpoint.POST("/filter/validate", c.filterValidateHandlerFunc)
|
||||||
endpoint.POST("/filter/complete", c.filterCompleteHandlerFunc)
|
endpoint.POST("/filter/complete", c.filterCompleteHandlerFunc)
|
||||||
endpoint.GET("/user/info", c.d.auth.UserInfoHandlerFunc)
|
endpoint.GET("/user/info", c.d.Auth.UserInfoHandlerFunc)
|
||||||
endpoint.GET("/user/avatar", c.d.auth.UserAvatarHandlerFunc)
|
endpoint.GET("/user/avatar", c.d.Auth.UserAvatarHandlerFunc)
|
||||||
|
|
||||||
c.t.Go(func() error {
|
c.t.Go(func() error {
|
||||||
ticker := time.NewTicker(10 * time.Second)
|
ticker := time.NewTicker(10 * time.Second)
|
||||||
|
|||||||
@@ -8,11 +8,7 @@ import (
|
|||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
"github.com/golang/mock/gomock"
|
"github.com/golang/mock/gomock"
|
||||||
|
|
||||||
"akvorado/common/clickhousedb"
|
|
||||||
"akvorado/common/daemon"
|
|
||||||
"akvorado/common/helpers"
|
"akvorado/common/helpers"
|
||||||
"akvorado/common/http"
|
|
||||||
"akvorado/common/reporter"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestSankeyQuerySQL(t *testing.T) {
|
func TestSankeyQuerySQL(t *testing.T) {
|
||||||
@@ -122,17 +118,7 @@ ORDER BY xps DESC`,
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestSankeyHandler(t *testing.T) {
|
func TestSankeyHandler(t *testing.T) {
|
||||||
r := reporter.NewMock(t)
|
c, h, mockConn, _ := NewMock(t, DefaultConfiguration())
|
||||||
ch, mockConn := clickhousedb.NewMock(t, r)
|
|
||||||
h := http.NewMock(t, r)
|
|
||||||
c, err := New(r, DefaultConfiguration(), Dependencies{
|
|
||||||
Daemon: daemon.NewMock(t),
|
|
||||||
HTTP: h,
|
|
||||||
ClickHouseDB: ch,
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("New() error:\n%+v", err)
|
|
||||||
}
|
|
||||||
helpers.StartStop(t, c)
|
helpers.StartStop(t, c)
|
||||||
|
|
||||||
expectedSQL := []struct {
|
expectedSQL := []struct {
|
||||||
|
|||||||
36
console/tests.go
Normal file
36
console/tests.go
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
//go:build !release
|
||||||
|
|
||||||
|
package console
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/benbjohnson/clock"
|
||||||
|
|
||||||
|
"akvorado/common/clickhousedb"
|
||||||
|
"akvorado/common/clickhousedb/mocks"
|
||||||
|
"akvorado/common/daemon"
|
||||||
|
"akvorado/common/http"
|
||||||
|
"akvorado/common/reporter"
|
||||||
|
"akvorado/console/authentication"
|
||||||
|
)
|
||||||
|
|
||||||
|
// NewMock instantiantes a new authentication component
|
||||||
|
func NewMock(t *testing.T, config Configuration) (*Component, *http.Component, *mocks.MockConn, *clock.Mock) {
|
||||||
|
t.Helper()
|
||||||
|
r := reporter.NewMock(t)
|
||||||
|
h := http.NewMock(t, r)
|
||||||
|
ch, mockConn := clickhousedb.NewMock(t, r)
|
||||||
|
mockClock := clock.NewMock()
|
||||||
|
c, err := New(r, config, Dependencies{
|
||||||
|
Daemon: daemon.NewMock(t),
|
||||||
|
HTTP: h,
|
||||||
|
ClickHouseDB: ch,
|
||||||
|
Clock: mockClock,
|
||||||
|
Auth: authentication.NewMock(t, r),
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("New() error:\n%+v", err)
|
||||||
|
}
|
||||||
|
return c, h, mockConn, mockClock
|
||||||
|
}
|
||||||
@@ -7,30 +7,15 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/ClickHouse/clickhouse-go/v2/lib/driver"
|
"github.com/ClickHouse/clickhouse-go/v2/lib/driver"
|
||||||
"github.com/benbjohnson/clock"
|
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
"github.com/golang/mock/gomock"
|
"github.com/golang/mock/gomock"
|
||||||
|
|
||||||
"akvorado/common/clickhousedb"
|
|
||||||
"akvorado/common/clickhousedb/mocks"
|
"akvorado/common/clickhousedb/mocks"
|
||||||
"akvorado/common/daemon"
|
|
||||||
"akvorado/common/helpers"
|
"akvorado/common/helpers"
|
||||||
"akvorado/common/http"
|
|
||||||
"akvorado/common/reporter"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestWidgetLastFlow(t *testing.T) {
|
func TestWidgetLastFlow(t *testing.T) {
|
||||||
r := reporter.NewMock(t)
|
c, h, mockConn, _ := NewMock(t, DefaultConfiguration())
|
||||||
ch, mockConn := clickhousedb.NewMock(t, r)
|
|
||||||
h := http.NewMock(t, r)
|
|
||||||
c, err := New(r, DefaultConfiguration(), Dependencies{
|
|
||||||
Daemon: daemon.NewMock(t),
|
|
||||||
HTTP: h,
|
|
||||||
ClickHouseDB: ch,
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("New() error:\n%+v", err)
|
|
||||||
}
|
|
||||||
helpers.StartStop(t, c)
|
helpers.StartStop(t, c)
|
||||||
|
|
||||||
ctrl := gomock.NewController(t)
|
ctrl := gomock.NewController(t)
|
||||||
@@ -106,17 +91,7 @@ func TestWidgetLastFlow(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestFlowRate(t *testing.T) {
|
func TestFlowRate(t *testing.T) {
|
||||||
r := reporter.NewMock(t)
|
c, h, mockConn, _ := NewMock(t, DefaultConfiguration())
|
||||||
ch, mockConn := clickhousedb.NewMock(t, r)
|
|
||||||
h := http.NewMock(t, r)
|
|
||||||
c, err := New(r, DefaultConfiguration(), Dependencies{
|
|
||||||
Daemon: daemon.NewMock(t),
|
|
||||||
HTTP: h,
|
|
||||||
ClickHouseDB: ch,
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("New() error:\n%+v", err)
|
|
||||||
}
|
|
||||||
helpers.StartStop(t, c)
|
helpers.StartStop(t, c)
|
||||||
|
|
||||||
ctrl := gomock.NewController(t)
|
ctrl := gomock.NewController(t)
|
||||||
@@ -140,17 +115,7 @@ func TestFlowRate(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestWidgetExporters(t *testing.T) {
|
func TestWidgetExporters(t *testing.T) {
|
||||||
r := reporter.NewMock(t)
|
c, h, mockConn, _ := NewMock(t, DefaultConfiguration())
|
||||||
ch, mockConn := clickhousedb.NewMock(t, r)
|
|
||||||
h := http.NewMock(t, r)
|
|
||||||
c, err := New(r, DefaultConfiguration(), Dependencies{
|
|
||||||
Daemon: daemon.NewMock(t),
|
|
||||||
HTTP: h,
|
|
||||||
ClickHouseDB: ch,
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("New() error:\n%+v", err)
|
|
||||||
}
|
|
||||||
helpers.StartStop(t, c)
|
helpers.StartStop(t, c)
|
||||||
|
|
||||||
expected := []struct {
|
expected := []struct {
|
||||||
@@ -181,17 +146,7 @@ func TestWidgetExporters(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestWidgetTop(t *testing.T) {
|
func TestWidgetTop(t *testing.T) {
|
||||||
r := reporter.NewMock(t)
|
c, h, mockConn, _ := NewMock(t, DefaultConfiguration())
|
||||||
ch, mockConn := clickhousedb.NewMock(t, r)
|
|
||||||
h := http.NewMock(t, r)
|
|
||||||
c, err := New(r, DefaultConfiguration(), Dependencies{
|
|
||||||
Daemon: daemon.NewMock(t),
|
|
||||||
HTTP: h,
|
|
||||||
ClickHouseDB: ch,
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("New() error:\n%+v", err)
|
|
||||||
}
|
|
||||||
helpers.StartStop(t, c)
|
helpers.StartStop(t, c)
|
||||||
|
|
||||||
gomock.InOrder(
|
gomock.InOrder(
|
||||||
@@ -230,48 +185,36 @@ func TestWidgetTop(t *testing.T) {
|
|||||||
URL: "/api/v0/console/widget/top/src-port",
|
URL: "/api/v0/console/widget/top/src-port",
|
||||||
JSONOutput: gin.H{
|
JSONOutput: gin.H{
|
||||||
"top": []gin.H{
|
"top": []gin.H{
|
||||||
gin.H{"name": "TCP/443", "percent": 51},
|
{"name": "TCP/443", "percent": 51},
|
||||||
gin.H{"name": "UDP/443", "percent": 20},
|
{"name": "UDP/443", "percent": 20},
|
||||||
gin.H{"name": "TCP/80", "percent": 18}}},
|
{"name": "TCP/80", "percent": 18}}},
|
||||||
}, {
|
}, {
|
||||||
URL: "/api/v0/console/widget/top/protocol",
|
URL: "/api/v0/console/widget/top/protocol",
|
||||||
JSONOutput: gin.H{
|
JSONOutput: gin.H{
|
||||||
"top": []gin.H{
|
"top": []gin.H{
|
||||||
gin.H{"name": "TCP", "percent": 75},
|
{"name": "TCP", "percent": 75},
|
||||||
gin.H{"name": "UDP", "percent": 24},
|
{"name": "UDP", "percent": 24},
|
||||||
gin.H{"name": "ESP", "percent": 1}}},
|
{"name": "ESP", "percent": 1}}},
|
||||||
}, {
|
}, {
|
||||||
URL: "/api/v0/console/widget/top/exporter",
|
URL: "/api/v0/console/widget/top/exporter",
|
||||||
JSONOutput: gin.H{
|
JSONOutput: gin.H{
|
||||||
"top": []gin.H{
|
"top": []gin.H{
|
||||||
gin.H{"name": "exporter1", "percent": 20},
|
{"name": "exporter1", "percent": 20},
|
||||||
gin.H{"name": "exporter3", "percent": 10},
|
{"name": "exporter3", "percent": 10},
|
||||||
gin.H{"name": "exporter5", "percent": 3}}},
|
{"name": "exporter5", "percent": 3}}},
|
||||||
}, {
|
}, {
|
||||||
URL: "/api/v0/console/widget/top/src-as",
|
URL: "/api/v0/console/widget/top/src-as",
|
||||||
JSONOutput: gin.H{
|
JSONOutput: gin.H{
|
||||||
"top": []gin.H{
|
"top": []gin.H{
|
||||||
gin.H{"name": "2906: Netflix", "percent": 12},
|
{"name": "2906: Netflix", "percent": 12},
|
||||||
gin.H{"name": "36040: Youtube", "percent": 10},
|
{"name": "36040: Youtube", "percent": 10},
|
||||||
gin.H{"name": "20940: Akamai", "percent": 9}}},
|
{"name": "20940: Akamai", "percent": 9}}},
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestWidgetGraph(t *testing.T) {
|
func TestWidgetGraph(t *testing.T) {
|
||||||
r := reporter.NewMock(t)
|
c, h, mockConn, mockClock := NewMock(t, DefaultConfiguration())
|
||||||
ch, mockConn := clickhousedb.NewMock(t, r)
|
|
||||||
h := http.NewMock(t, r)
|
|
||||||
mockClock := clock.NewMock()
|
|
||||||
c, err := New(r, DefaultConfiguration(), Dependencies{
|
|
||||||
Daemon: daemon.NewMock(t),
|
|
||||||
HTTP: h,
|
|
||||||
ClickHouseDB: ch,
|
|
||||||
Clock: mockClock,
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("New() error:\n%+v", err)
|
|
||||||
}
|
|
||||||
helpers.StartStop(t, c)
|
helpers.StartStop(t, c)
|
||||||
|
|
||||||
base := time.Date(2009, time.November, 10, 23, 0, 0, 0, time.UTC)
|
base := time.Date(2009, time.November, 10, 23, 0, 0, 0, time.UTC)
|
||||||
@@ -307,12 +250,12 @@ ORDER BY Time`).
|
|||||||
URL: "/api/v0/console/widget/graph?points=100",
|
URL: "/api/v0/console/widget/graph?points=100",
|
||||||
JSONOutput: gin.H{
|
JSONOutput: gin.H{
|
||||||
"data": []gin.H{
|
"data": []gin.H{
|
||||||
gin.H{"t": "2009-11-10T23:00:00Z", "gbps": 25.3},
|
{"t": "2009-11-10T23:00:00Z", "gbps": 25.3},
|
||||||
gin.H{"t": "2009-11-10T23:01:00Z", "gbps": 27.8},
|
{"t": "2009-11-10T23:01:00Z", "gbps": 27.8},
|
||||||
gin.H{"t": "2009-11-10T23:02:00Z", "gbps": 26.4},
|
{"t": "2009-11-10T23:02:00Z", "gbps": 26.4},
|
||||||
gin.H{"t": "2009-11-10T23:03:00Z", "gbps": 29.2},
|
{"t": "2009-11-10T23:03:00Z", "gbps": 29.2},
|
||||||
gin.H{"t": "2009-11-10T23:04:00Z", "gbps": 21.3},
|
{"t": "2009-11-10T23:04:00Z", "gbps": 21.3},
|
||||||
gin.H{"t": "2009-11-10T23:05:00Z", "gbps": 24.7}},
|
{"t": "2009-11-10T23:05:00Z", "gbps": 24.7}},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user