-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow disabling Kafka integration (#178)
* Allow disabling producing to Kafka in configuration * Fix passing kafka.Writer containing a lock by value * Change DisableKafka to EnableKafka * Add missing License and copyright info
- Loading branch information
1 parent
3fa04ea
commit 59f771e
Showing
5 changed files
with
157 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
// SPDX-FileCopyrightText: 2023 Open Networking Foundation <info@opennetworking.org> | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package metrics | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/omec-project/metricfunc/pkg/metricinfo" | ||
"github.com/omec-project/smf/factory" | ||
) | ||
|
||
var my_false bool = false | ||
|
||
func TestInitializeKafkaStreamWithKafkaDisabled(t *testing.T) { | ||
config := factory.Configuration{ | ||
KafkaInfo: factory.KafkaInfo{ | ||
EnableKafka: &my_false, | ||
}, | ||
} | ||
|
||
result := InitialiseKafkaStream(&config) | ||
|
||
if result != nil { | ||
t.Errorf("Expected return value to be nil, got %v", result) | ||
} | ||
if StatWriter.kafkaWriter != nil { | ||
t.Errorf("Expected kafkaWrite to be nil, got %v", StatWriter.kafkaWriter) | ||
} | ||
} | ||
|
||
func TestSendMessageWithKafkaDisabled(t *testing.T) { | ||
configuration := factory.Configuration{ | ||
KafkaInfo: factory.KafkaInfo{ | ||
EnableKafka: &my_false, | ||
}, | ||
} | ||
config := factory.Config{ | ||
Configuration: &configuration, | ||
} | ||
factory.SmfConfig = config | ||
|
||
InitialiseKafkaStream(&configuration) | ||
|
||
writer := GetWriter() | ||
|
||
// If the kafkaWriter is called, this will panic and fail the test | ||
result := writer.SendMessage([]byte{0xFF}) | ||
|
||
if result != nil { | ||
t.Errorf("Expected return value to be nil, got %v", result) | ||
} | ||
} | ||
|
||
func TestPublishPduSessEventWithKafkaDisabled(t *testing.T) { | ||
configuration := factory.Configuration{ | ||
KafkaInfo: factory.KafkaInfo{ | ||
EnableKafka: &my_false, | ||
}, | ||
} | ||
config := factory.Config{ | ||
Configuration: &configuration, | ||
} | ||
factory.SmfConfig = config | ||
|
||
InitialiseKafkaStream(&configuration) | ||
|
||
writer := GetWriter() | ||
|
||
// If the kafkaWriter is called, this will panic and fail the test | ||
result := writer.PublishPduSessEvent(metricinfo.CoreSubscriber{}, 0) | ||
|
||
if result != nil { | ||
t.Errorf("Expected return value to be nil, got %v", result) | ||
} | ||
} | ||
|
||
func TestPublishMsgEventWithKafkaDisabled(t *testing.T) { | ||
configuration := factory.Configuration{ | ||
KafkaInfo: factory.KafkaInfo{ | ||
EnableKafka: &my_false, | ||
}, | ||
} | ||
config := factory.Config{ | ||
Configuration: &configuration, | ||
} | ||
factory.SmfConfig = config | ||
|
||
InitialiseKafkaStream(&configuration) | ||
|
||
// If the kafkaWriter is called, this will panic and fail the test | ||
result := PublishMsgEvent(0) | ||
|
||
if result != nil { | ||
t.Errorf("Expected return value to be nil, got %v", result) | ||
} | ||
} | ||
|
||
func TestPublishNfStatusWithKafkaDisabled(t *testing.T) { | ||
configuration := factory.Configuration{ | ||
KafkaInfo: factory.KafkaInfo{ | ||
EnableKafka: &my_false, | ||
}, | ||
} | ||
config := factory.Config{ | ||
Configuration: &configuration, | ||
} | ||
factory.SmfConfig = config | ||
|
||
InitialiseKafkaStream(&configuration) | ||
|
||
writer := GetWriter() | ||
|
||
// If the kafkaWriter is called, this will panic and fail the test | ||
result := writer.PublishNfStatusEvent(metricinfo.MetricEvent{}) | ||
|
||
if result != nil { | ||
t.Errorf("Expected return value to be nil, got %v", result) | ||
} | ||
} |