blob: 790425e946b9ac9dcfdf6f179351d895fef41697 [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) {
khenaidoo43c82122018-11-22 18:38:28 -050024 actualResult, error := NewInterContainerProxy()
khenaidooabad44c2018-08-03 16:58:35 -040025 assert.Equal(t, error, nil)
khenaidoo43c82122018-11-22 18:38:28 -050026 assert.Equal(t, actualResult.kafkaHost, DefaultKafkaHost)
27 assert.Equal(t, actualResult.kafkaPort, DefaultKafkaPort)
28 assert.Equal(t, actualResult.defaultRequestHandlerInterface, interface{}(nil))
khenaidooabad44c2018-08-03 16:58:35 -040029}
30
31func TestKafkaProxyOptionHost(t *testing.T) {
khenaidoo43c82122018-11-22 18:38:28 -050032 actualResult, error := NewInterContainerProxy(InterContainerHost("10.20.30.40"))
khenaidooabad44c2018-08-03 16:58:35 -040033 assert.Equal(t, error, nil)
khenaidoo43c82122018-11-22 18:38:28 -050034 assert.Equal(t, actualResult.kafkaHost, "10.20.30.40")
35 assert.Equal(t, actualResult.kafkaPort, DefaultKafkaPort)
36 assert.Equal(t, actualResult.defaultRequestHandlerInterface, interface{}(nil))
khenaidooabad44c2018-08-03 16:58:35 -040037}
38
39func TestKafkaProxyOptionPort(t *testing.T) {
khenaidoo43c82122018-11-22 18:38:28 -050040 actualResult, error := NewInterContainerProxy(InterContainerPort(1020))
khenaidooabad44c2018-08-03 16:58:35 -040041 assert.Equal(t, error, nil)
khenaidoo43c82122018-11-22 18:38:28 -050042 assert.Equal(t, actualResult.kafkaHost, DefaultKafkaHost)
43 assert.Equal(t, actualResult.kafkaPort, 1020)
44 assert.Equal(t, actualResult.defaultRequestHandlerInterface, interface{}(nil))
khenaidooabad44c2018-08-03 16:58:35 -040045}
46
47func TestKafkaProxyOptionTopic(t *testing.T) {
khenaidoo43c82122018-11-22 18:38:28 -050048 actualResult, error := NewInterContainerProxy(DefaultTopic(&Topic{Name: "Adapter"}))
khenaidooabad44c2018-08-03 16:58:35 -040049 assert.Equal(t, error, nil)
khenaidoo43c82122018-11-22 18:38:28 -050050 assert.Equal(t, actualResult.kafkaHost, DefaultKafkaHost)
51 assert.Equal(t, actualResult.kafkaPort, DefaultKafkaPort)
52 assert.Equal(t, actualResult.defaultRequestHandlerInterface, interface{}(nil))
khenaidooabad44c2018-08-03 16:58:35 -040053 assert.Equal(t, actualResult.DefaultTopic.Name, "Adapter")
54}
55
56type myInterface struct {
57}
58
59func (m *myInterface) doSomething() {
60}
61
62func TestKafkaProxyOptionTargetInterface(t *testing.T) {
63 var m *myInterface
khenaidoo43c82122018-11-22 18:38:28 -050064 actualResult, error := NewInterContainerProxy(RequestHandlerInterface(m))
khenaidooabad44c2018-08-03 16:58:35 -040065 assert.Equal(t, error, nil)
khenaidoo43c82122018-11-22 18:38:28 -050066 assert.Equal(t, actualResult.kafkaHost, DefaultKafkaHost)
67 assert.Equal(t, actualResult.kafkaPort, DefaultKafkaPort)
68 assert.Equal(t, actualResult.defaultRequestHandlerInterface, m)
khenaidooabad44c2018-08-03 16:58:35 -040069}
70
71func TestKafkaProxyChangeAllOptions(t *testing.T) {
72 var m *myInterface
khenaidoo43c82122018-11-22 18:38:28 -050073 actualResult, error := NewInterContainerProxy(
74 InterContainerHost("10.20.30.40"),
75 InterContainerPort(1020),
khenaidooabad44c2018-08-03 16:58:35 -040076 DefaultTopic(&Topic{Name: "Adapter"}),
khenaidoo43c82122018-11-22 18:38:28 -050077 RequestHandlerInterface(m))
khenaidooabad44c2018-08-03 16:58:35 -040078 assert.Equal(t, error, nil)
khenaidoo43c82122018-11-22 18:38:28 -050079 assert.Equal(t, actualResult.kafkaHost, "10.20.30.40")
80 assert.Equal(t, actualResult.kafkaPort, 1020)
81 assert.Equal(t, actualResult.defaultRequestHandlerInterface, m)
khenaidooabad44c2018-08-03 16:58:35 -040082 assert.Equal(t, actualResult.DefaultTopic.Name, "Adapter")
83}