-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathconstructor_test.go
48 lines (36 loc) · 1.01 KB
/
constructor_test.go
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
/*
* Copyright (c) New Cloud Technologies, Ltd. 2013-2022.
* Author: Vitaly Isaev <[email protected]>
* License: https://github.com/newcloudtechnologies/memlimiter/blob/master/LICENSE
*/
package memlimiter
import (
"testing"
"time"
"github.com/go-logr/logr/testr"
"github.com/newcloudtechnologies/memlimiter/stats"
"github.com/stretchr/testify/require"
)
func TestConstructor(t *testing.T) {
t.Run("stub", func(t *testing.T) {
logger := testr.New(t)
const delay = 10 * time.Millisecond
subscription := stats.NewSubscriptionDefault(logger, delay)
defer subscription.Quit()
service, err := NewServiceFromConfig(
logger,
nil, // use stub instead of real service
WithServiceStatsSubscription(subscription),
)
require.NoError(t, err)
defer service.Quit()
ss, err := service.GetStats()
require.NoError(t, err)
require.Nil(t, ss)
time.Sleep(2 * delay)
ss, err = service.GetStats()
require.NoError(t, err)
require.NotNil(t, ss)
require.Nil(t, service.Middleware())
})
}