forked from twitchscience/kinsumer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig_test.go
75 lines (60 loc) · 2.17 KB
/
config_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
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
// Copyright (c) 2016 Twitch Interactive
package kinsumer
import (
"testing"
"time"
"github.com/stretchr/testify/require"
)
func TestConfigDefault(t *testing.T) {
config := NewConfig()
err := validateConfig(&config)
require.NoError(t, err)
}
func TestConfigErrors(t *testing.T) {
var (
config Config
err error
)
config = NewConfig().WithBufferSize(0)
err = validateConfig(&config)
require.EqualError(t, err, ErrConfigInvalidBufferSize.Error())
config = NewConfig().WithThrottleDelay(0)
err = validateConfig(&config)
require.EqualError(t, err, ErrConfigInvalidThrottleDelay.Error())
config = NewConfig().WithCommitFrequency(0)
err = validateConfig(&config)
require.EqualError(t, err, ErrConfigInvalidCommitFrequency.Error())
config = NewConfig().WithShardCheckFrequency(0)
err = validateConfig(&config)
require.EqualError(t, err, ErrConfigInvalidShardCheckFrequency.Error())
config = NewConfig().WithLeaderActionFrequency(0)
err = validateConfig(&config)
require.EqualError(t, err, ErrConfigInvalidLeaderActionFrequency.Error())
config = NewConfig().WithLeaderActionFrequency(time.Second).WithShardCheckFrequency(time.Minute)
err = validateConfig(&config)
require.EqualError(t, err, ErrConfigInvalidLeaderActionFrequency.Error())
config = NewConfig().WithBufferSize(0)
err = validateConfig(&config)
require.EqualError(t, err, ErrConfigInvalidBufferSize.Error())
config = NewConfig().WithStats(nil)
err = validateConfig(&config)
require.EqualError(t, err, ErrConfigInvalidStats.Error())
}
func TestConfigWithMethods(t *testing.T) {
stats := &NoopStatReceiver{}
config := NewConfig().
WithBufferSize(1).
WithCommitFrequency(1 * time.Second).
WithShardCheckFrequency(1 * time.Second).
WithLeaderActionFrequency(1 * time.Second).
WithThrottleDelay(1 * time.Second).
WithStats(stats)
err := validateConfig(&config)
require.NoError(t, err)
require.Equal(t, 1, config.bufferSize)
require.Equal(t, 1*time.Second, config.throttleDelay)
require.Equal(t, 1*time.Second, config.commitFrequency)
require.Equal(t, 1*time.Second, config.shardCheckFrequency)
require.Equal(t, 1*time.Second, config.leaderActionFrequency)
require.Equal(t, stats, config.stats)
}