Skip to content

Commit

Permalink
UT for CheckConnectionToKafka with multiple broker addresses
Browse files Browse the repository at this point in the history
  • Loading branch information
epapbak committed Feb 19, 2024
1 parent acff00b commit ae9776f
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
31 changes: 30 additions & 1 deletion ccx_notification_writer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,36 @@ func TestConvertLogLevel(t *testing.T) {
for _, td := range testData {
// perform conversion
output := main.ConvertLogLevel(td.Input)
// check if converted value is eqaual to expected one
// check if converted value is equal to expected one
assert.Equal(t, output, td.Output)
}
}

// TestDoSelectedOperationCheckConnectionToKafka checks the function
// CheckConnectionToKafka called via doSelectedOperation function
func TestDoSelectedOperationCheckConnectionToKafka(t *testing.T) {
// fill in configuration structure
configuration := main.ConfigStruct{}
configuration.Broker = main.BrokerConfiguration{
Addresses: "broker_address:9092, broker_address:9093",
Topic: "broker_topic",
}
cliFlags := main.CliFlags{
CheckConnectionToKafka: true,
}

// try to call the tested function and capture its output
output, err := capture.ErrorOutput(func() {
log.Logger = log.Output(zerolog.New(os.Stderr))
code, err := main.DoSelectedOperation(&configuration, cliFlags)
assert.Equal(t, code, main.ExitStatusKafkaError)
assert.NoError(t, err)
})

// check the captured text
checkCapture(t, err)

// expected content printed by tested function
assert.Contains(t, output, main.ConnectionToBrokerMessage)
assert.Contains(t, output, main.AllBrokerConnectionAttemptsMessage)
}
3 changes: 3 additions & 0 deletions export_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ var (
ShowConfiguration = showConfiguration
DoSelectedOperation = doSelectedOperation

ConnectionToBrokerMessage = connectionToBrokerMessage
AllBrokerConnectionAttemptsMessage = allBrokerConnectionAttemptsMessage

// functions from consumer.go source file
ParseMessage = parseMessage
ShrinkMessage = shrinkMessage
Expand Down

0 comments on commit ae9776f

Please sign in to comment.