-
Notifications
You must be signed in to change notification settings - Fork 0
/
universe_test.go
73 lines (67 loc) · 2.44 KB
/
universe_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
package kafkauniverse
import (
"context"
"errors"
"testing"
"github.com/cloudtrust/kafka-client/mock"
"github.com/stretchr/testify/assert"
"go.uber.org/mock/gomock"
)
func TestKafkaUniverse(t *testing.T) {
var mockCtrl = gomock.NewController(t)
defer mockCtrl.Finish()
var logger = mock.NewLogger(mockCtrl)
var ctx = context.TODO()
var anError = errors.New("any error")
logger.EXPECT().Error(gomock.Any(), gomock.Any()).AnyTimes()
var createDefaultUniverse = func(target any) error {
var conf = target.(*[]KafkaClusterRepresentation)
*conf = append(*conf, createValidKafkaClusterRepresentation())
return nil
}
t.Run("Empty universe", func(t *testing.T) {
var _, err = NewKafkaUniverse(ctx, logger, "CT_KAFKA_CLIENT_SECRET_", func(target any) error {
return anError
})
assert.Equal(t, anError, err)
})
t.Run("Empty universe", func(t *testing.T) {
var universe, err = NewKafkaUniverse(ctx, logger, "CT_KAFKA_CLIENT_SECRET_", func(target any) error {
return nil
})
assert.NotNil(t, err)
assert.Nil(t, universe)
})
t.Run("Invalid configuration", func(t *testing.T) {
var universe, err = NewKafkaUniverse(ctx, logger, "CT_KAFKA_CLIENT_SECRET_", func(target any) error {
var conf = target.(*[]KafkaClusterRepresentation)
*conf = append(*conf, KafkaClusterRepresentation{})
return nil
})
assert.NotNil(t, err)
assert.Nil(t, universe)
})
t.Run("Valid configuration", func(t *testing.T) {
var universe, err = NewKafkaUniverse(ctx, logger, "CT_KAFKA_CLIENT_SECRET_", createDefaultUniverse)
assert.Nil(t, err)
assert.NotNil(t, universe)
})
t.Run("Initialize unknown producer", func(t *testing.T) {
var universe, _ = NewKafkaUniverse(ctx, logger, "CT_KAFKA_CLIENT_SECRET_", createDefaultUniverse)
var err = universe.InitializeProducers("unknown")
assert.NotNil(t, err)
})
t.Run("Initialize unknown consumer", func(t *testing.T) {
var universe, _ = NewKafkaUniverse(ctx, logger, "CT_KAFKA_CLIENT_SECRET_", createDefaultUniverse)
var err = universe.InitializeConsumers("unknown")
assert.NotNil(t, err)
})
t.Run("Get unknown producer", func(t *testing.T) {
var universe, _ = NewKafkaUniverse(ctx, logger, "CT_KAFKA_CLIENT_SECRET_", createDefaultUniverse)
assert.Nil(t, universe.GetProducer("unknown"))
})
t.Run("Get unknown consumer", func(t *testing.T) {
var universe, _ = NewKafkaUniverse(ctx, logger, "CT_KAFKA_CLIENT_SECRET_", createDefaultUniverse)
assert.Nil(t, universe.GetConsumer("unknown"))
})
}