From 91c8befef3fa513ec56b9e6e9a8fb1c18329004e Mon Sep 17 00:00:00 2001 From: Rohan Raj <96484809+Rohanraj123@users.noreply.github.com> Date: Sun, 1 Dec 2024 00:07:38 +0530 Subject: [PATCH] test: Add test for kafka/auth/options.go file (#6281) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Which problem is this PR solving? - Test for options.go ## Description of the changes - Add test for options.go file. ## How was this change tested? - ## Checklist - [X] I have read https://github.com/jaegertracing/jaeger/blob/master/CONTRIBUTING_GUIDELINES.md - [X] I have signed all commits - [X] I have added unit tests for the new functionality - [X] I have run lint and test steps successfully - for `jaeger`: `make lint test` - for `jaeger-ui`: `yarn lint` and `yarn test` --------- Signed-off-by: Rohanraj123 --- pkg/kafka/auth/options_test.go | 50 ++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 pkg/kafka/auth/options_test.go diff --git a/pkg/kafka/auth/options_test.go b/pkg/kafka/auth/options_test.go new file mode 100644 index 00000000000..7ee60f86cc8 --- /dev/null +++ b/pkg/kafka/auth/options_test.go @@ -0,0 +1,50 @@ +// Copyright (c) 2024 The Jaeger Authors. +// SPDX-License-Identifier: Apache-2.0 + +package auth + +import ( + "flag" + "testing" + + "github.com/stretchr/testify/assert" +) + +func TestAddFlags(t *testing.T) { + tests := []struct { + name string + configPrefix string + expectedFlags map[string]string + }{ + { + name: "Default configuration with testprefix", + configPrefix: "testprefix", + expectedFlags: map[string]string{ + "testprefix" + suffixAuthentication: none, + "testprefix" + kerberosPrefix + suffixKerberosServiceName: defaultKerberosServiceName, + "testprefix" + kerberosPrefix + suffixKerberosRealm: defaultKerberosRealm, + "testprefix" + kerberosPrefix + suffixKerberosUsername: defaultKerberosUsername, + "testprefix" + kerberosPrefix + suffixKerberosPassword: defaultKerberosPassword, + "testprefix" + kerberosPrefix + suffixKerberosConfig: defaultKerberosConfig, + "testprefix" + kerberosPrefix + suffixKerberosUseKeyTab: "false", + "testprefix" + plainTextPrefix + suffixPlainTextUsername: defaultPlainTextUsername, + "testprefix" + plainTextPrefix + suffixPlainTextPassword: defaultPlainTextPassword, + "testprefix" + plainTextPrefix + suffixPlainTextMechanism: defaultPlainTextMechanism, + }, + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + flagSet := flag.NewFlagSet("test", flag.ContinueOnError) + + AddFlags(tt.configPrefix, flagSet) + + for flagName, expectedValue := range tt.expectedFlags { + flag := flagSet.Lookup(flagName) + assert.NotNil(t, flag, "Expected flag %q to be registered", flagName) + assert.Equal(t, expectedValue, flag.DefValue, "Default value of flag %q", flagName) + } + }) + } +}