khenaidoo | bf6e7bb | 2018-08-14 22:27:29 -0400 | [diff] [blame] | 1 | /* |
| 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 | */ |
khenaidoo | abad44c | 2018-08-03 16:58:35 -0400 | [diff] [blame] | 16 | package kafka |
| 17 | |
| 18 | import ( |
| 19 | "github.com/stretchr/testify/assert" |
| 20 | "testing" |
| 21 | ) |
| 22 | |
khenaidoo | abad44c | 2018-08-03 16:58:35 -0400 | [diff] [blame] | 23 | func TestDefaultKafkaProxy(t *testing.T) { |
khenaidoo | 43c8212 | 2018-11-22 18:38:28 -0500 | [diff] [blame] | 24 | actualResult, error := NewInterContainerProxy() |
khenaidoo | abad44c | 2018-08-03 16:58:35 -0400 | [diff] [blame] | 25 | assert.Equal(t, error, nil) |
khenaidoo | 43c8212 | 2018-11-22 18:38:28 -0500 | [diff] [blame] | 26 | assert.Equal(t, actualResult.kafkaHost, DefaultKafkaHost) |
| 27 | assert.Equal(t, actualResult.kafkaPort, DefaultKafkaPort) |
| 28 | assert.Equal(t, actualResult.defaultRequestHandlerInterface, interface{}(nil)) |
khenaidoo | abad44c | 2018-08-03 16:58:35 -0400 | [diff] [blame] | 29 | } |
| 30 | |
| 31 | func TestKafkaProxyOptionHost(t *testing.T) { |
khenaidoo | 43c8212 | 2018-11-22 18:38:28 -0500 | [diff] [blame] | 32 | actualResult, error := NewInterContainerProxy(InterContainerHost("10.20.30.40")) |
khenaidoo | abad44c | 2018-08-03 16:58:35 -0400 | [diff] [blame] | 33 | assert.Equal(t, error, nil) |
khenaidoo | 43c8212 | 2018-11-22 18:38:28 -0500 | [diff] [blame] | 34 | assert.Equal(t, actualResult.kafkaHost, "10.20.30.40") |
| 35 | assert.Equal(t, actualResult.kafkaPort, DefaultKafkaPort) |
| 36 | assert.Equal(t, actualResult.defaultRequestHandlerInterface, interface{}(nil)) |
khenaidoo | abad44c | 2018-08-03 16:58:35 -0400 | [diff] [blame] | 37 | } |
| 38 | |
| 39 | func TestKafkaProxyOptionPort(t *testing.T) { |
khenaidoo | 43c8212 | 2018-11-22 18:38:28 -0500 | [diff] [blame] | 40 | actualResult, error := NewInterContainerProxy(InterContainerPort(1020)) |
khenaidoo | abad44c | 2018-08-03 16:58:35 -0400 | [diff] [blame] | 41 | assert.Equal(t, error, nil) |
khenaidoo | 43c8212 | 2018-11-22 18:38:28 -0500 | [diff] [blame] | 42 | assert.Equal(t, actualResult.kafkaHost, DefaultKafkaHost) |
| 43 | assert.Equal(t, actualResult.kafkaPort, 1020) |
| 44 | assert.Equal(t, actualResult.defaultRequestHandlerInterface, interface{}(nil)) |
khenaidoo | abad44c | 2018-08-03 16:58:35 -0400 | [diff] [blame] | 45 | } |
| 46 | |
| 47 | func TestKafkaProxyOptionTopic(t *testing.T) { |
khenaidoo | 43c8212 | 2018-11-22 18:38:28 -0500 | [diff] [blame] | 48 | actualResult, error := NewInterContainerProxy(DefaultTopic(&Topic{Name: "Adapter"})) |
khenaidoo | abad44c | 2018-08-03 16:58:35 -0400 | [diff] [blame] | 49 | assert.Equal(t, error, nil) |
khenaidoo | 43c8212 | 2018-11-22 18:38:28 -0500 | [diff] [blame] | 50 | assert.Equal(t, actualResult.kafkaHost, DefaultKafkaHost) |
| 51 | assert.Equal(t, actualResult.kafkaPort, DefaultKafkaPort) |
| 52 | assert.Equal(t, actualResult.defaultRequestHandlerInterface, interface{}(nil)) |
khenaidoo | abad44c | 2018-08-03 16:58:35 -0400 | [diff] [blame] | 53 | assert.Equal(t, actualResult.DefaultTopic.Name, "Adapter") |
| 54 | } |
| 55 | |
| 56 | type myInterface struct { |
| 57 | } |
| 58 | |
| 59 | func (m *myInterface) doSomething() { |
| 60 | } |
| 61 | |
| 62 | func TestKafkaProxyOptionTargetInterface(t *testing.T) { |
| 63 | var m *myInterface |
khenaidoo | 43c8212 | 2018-11-22 18:38:28 -0500 | [diff] [blame] | 64 | actualResult, error := NewInterContainerProxy(RequestHandlerInterface(m)) |
khenaidoo | abad44c | 2018-08-03 16:58:35 -0400 | [diff] [blame] | 65 | assert.Equal(t, error, nil) |
khenaidoo | 43c8212 | 2018-11-22 18:38:28 -0500 | [diff] [blame] | 66 | assert.Equal(t, actualResult.kafkaHost, DefaultKafkaHost) |
| 67 | assert.Equal(t, actualResult.kafkaPort, DefaultKafkaPort) |
| 68 | assert.Equal(t, actualResult.defaultRequestHandlerInterface, m) |
khenaidoo | abad44c | 2018-08-03 16:58:35 -0400 | [diff] [blame] | 69 | } |
| 70 | |
| 71 | func TestKafkaProxyChangeAllOptions(t *testing.T) { |
| 72 | var m *myInterface |
khenaidoo | 43c8212 | 2018-11-22 18:38:28 -0500 | [diff] [blame] | 73 | actualResult, error := NewInterContainerProxy( |
| 74 | InterContainerHost("10.20.30.40"), |
| 75 | InterContainerPort(1020), |
khenaidoo | abad44c | 2018-08-03 16:58:35 -0400 | [diff] [blame] | 76 | DefaultTopic(&Topic{Name: "Adapter"}), |
khenaidoo | 43c8212 | 2018-11-22 18:38:28 -0500 | [diff] [blame] | 77 | RequestHandlerInterface(m)) |
khenaidoo | abad44c | 2018-08-03 16:58:35 -0400 | [diff] [blame] | 78 | assert.Equal(t, error, nil) |
khenaidoo | 43c8212 | 2018-11-22 18:38:28 -0500 | [diff] [blame] | 79 | assert.Equal(t, actualResult.kafkaHost, "10.20.30.40") |
| 80 | assert.Equal(t, actualResult.kafkaPort, 1020) |
| 81 | assert.Equal(t, actualResult.defaultRequestHandlerInterface, m) |
khenaidoo | abad44c | 2018-08-03 16:58:35 -0400 | [diff] [blame] | 82 | assert.Equal(t, actualResult.DefaultTopic.Name, "Adapter") |
| 83 | } |