-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathoperator_test.go
112 lines (99 loc) · 2.55 KB
/
operator_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
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
package helper
import (
"testing"
"github.com/observiq/stanza/operator"
"github.com/observiq/stanza/testutil"
"github.com/stretchr/testify/require"
"go.uber.org/zap"
)
func TestBasicConfigID(t *testing.T) {
config := BasicConfig{
OperatorID: "test-id",
OperatorType: "test-type",
}
require.Equal(t, "test-id", config.ID())
}
func TestBasicConfigType(t *testing.T) {
config := BasicConfig{
OperatorID: "test-id",
OperatorType: "test-type",
}
require.Equal(t, "test-type", config.Type())
}
func TestBasicConfigBuildWithoutID(t *testing.T) {
config := BasicConfig{
OperatorType: "test-type",
}
context := testutil.NewBuildContext(t)
_, err := config.Build(context)
require.NoError(t, err)
}
func TestBasicConfigBuildWithoutType(t *testing.T) {
config := BasicConfig{
OperatorID: "test-id",
}
context := operator.BuildContext{}
_, err := config.Build(context)
require.Error(t, err)
require.Contains(t, err.Error(), "missing required `type` field.")
}
func TestBasicConfigBuildMissingLogger(t *testing.T) {
config := BasicConfig{
OperatorID: "test-id",
OperatorType: "test-type",
}
context := operator.BuildContext{}
_, err := config.Build(context)
require.Error(t, err)
require.Contains(t, err.Error(), "operator build context is missing a logger.")
}
func TestBasicConfigBuildValid(t *testing.T) {
config := BasicConfig{
OperatorID: "test-id",
OperatorType: "test-type",
}
context := testutil.NewBuildContext(t)
operator, err := config.Build(context)
require.NoError(t, err)
require.Equal(t, "test-id", operator.OperatorID)
require.Equal(t, "test-type", operator.OperatorType)
}
func TestBasicOperatorID(t *testing.T) {
operator := BasicOperator{
OperatorID: "test-id",
OperatorType: "test-type",
}
require.Equal(t, "test-id", operator.ID())
}
func TestBasicOperatorType(t *testing.T) {
operator := BasicOperator{
OperatorID: "test-id",
OperatorType: "test-type",
}
require.Equal(t, "test-type", operator.Type())
}
func TestBasicOperatorLogger(t *testing.T) {
logger := &zap.SugaredLogger{}
operator := BasicOperator{
OperatorID: "test-id",
OperatorType: "test-type",
SugaredLogger: logger,
}
require.Equal(t, logger, operator.Logger())
}
func TestBasicOperatorStart(t *testing.T) {
operator := BasicOperator{
OperatorID: "test-id",
OperatorType: "test-type",
}
err := operator.Start()
require.NoError(t, err)
}
func TestBasicOperatorStop(t *testing.T) {
operator := BasicOperator{
OperatorID: "test-id",
OperatorType: "test-type",
}
err := operator.Stop()
require.NoError(t, err)
}