blob: 6a3bb374eef7a19fd966f9fc63fc2adb1333c8ee [file] [log] [blame]
khenaidoobf6e7bb2018-08-14 22:27:29 -04001/*
2 * Copyright 2018-present Open Networking Foundation
3
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7
8 * http://www.apache.org/licenses/LICENSE-2.0
9
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
khenaidooabad44c2018-08-03 16:58:35 -040016package kafka
17
18import (
19 "github.com/stretchr/testify/assert"
20 "testing"
21)
22
khenaidooabad44c2018-08-03 16:58:35 -040023func TestDefaultKafkaProxy(t *testing.T) {
24 actualResult, error := NewKafkaMessagingProxy()
25 assert.Equal(t, error, nil)
26 assert.Equal(t, actualResult.KafkaHost, DefaultKafkaHost)
27 assert.Equal(t, actualResult.KafkaPort, DefaultKafkaPort)
28 assert.Equal(t, actualResult.TargetInterface, interface{}(nil))
29 assert.Equal(t, actualResult.DefaultTopic.Name, "Core")
30}
31
32func TestKafkaProxyOptionHost(t *testing.T) {
33 actualResult, error := NewKafkaMessagingProxy(KafkaHost("10.20.30.40"))
34 assert.Equal(t, error, nil)
35 assert.Equal(t, actualResult.KafkaHost, "10.20.30.40")
36 assert.Equal(t, actualResult.KafkaPort, DefaultKafkaPort)
37 assert.Equal(t, actualResult.TargetInterface, interface{}(nil))
38 assert.Equal(t, actualResult.DefaultTopic.Name, "Core")
39}
40
41func TestKafkaProxyOptionPort(t *testing.T) {
42 actualResult, error := NewKafkaMessagingProxy(KafkaPort(1020))
43 assert.Equal(t, error, nil)
44 assert.Equal(t, actualResult.KafkaHost, DefaultKafkaHost)
45 assert.Equal(t, actualResult.KafkaPort, 1020)
46 assert.Equal(t, actualResult.TargetInterface, interface{}(nil))
47 assert.Equal(t, actualResult.DefaultTopic.Name, "Core")
48}
49
50func TestKafkaProxyOptionTopic(t *testing.T) {
51 actualResult, error := NewKafkaMessagingProxy(DefaultTopic(&Topic{Name: "Adapter"}))
52 assert.Equal(t, error, nil)
53 assert.Equal(t, actualResult.KafkaHost, DefaultKafkaHost)
54 assert.Equal(t, actualResult.KafkaPort, DefaultKafkaPort)
55 assert.Equal(t, actualResult.TargetInterface, interface{}(nil))
56 assert.Equal(t, actualResult.DefaultTopic.Name, "Adapter")
57}
58
59type myInterface struct {
60}
61
62func (m *myInterface) doSomething() {
63}
64
65func TestKafkaProxyOptionTargetInterface(t *testing.T) {
66 var m *myInterface
67 actualResult, error := NewKafkaMessagingProxy(TargetInterface(m))
68 assert.Equal(t, error, nil)
69 assert.Equal(t, actualResult.KafkaHost, DefaultKafkaHost)
70 assert.Equal(t, actualResult.KafkaPort, DefaultKafkaPort)
71 assert.Equal(t, actualResult.TargetInterface, m)
72 assert.Equal(t, actualResult.DefaultTopic.Name, "Core")
73}
74
75func TestKafkaProxyChangeAllOptions(t *testing.T) {
76 var m *myInterface
77 actualResult, error := NewKafkaMessagingProxy(
78 KafkaHost("10.20.30.40"),
79 KafkaPort(1020),
80 DefaultTopic(&Topic{Name: "Adapter"}),
81 TargetInterface(m))
82 assert.Equal(t, error, nil)
83 assert.Equal(t, actualResult.KafkaHost, "10.20.30.40")
84 assert.Equal(t, actualResult.KafkaPort, 1020)
85 assert.Equal(t, actualResult.TargetInterface, m)
86 assert.Equal(t, actualResult.DefaultTopic.Name, "Adapter")
87}