Skip to content

tests: check SonicDBConfig exception types - #1237

Open
dlanov wants to merge 1 commit into
sonic-net:masterfrom
dlanov:fix-857-exception-type-tests
Open

dlanov wants to merge 1 commit into
sonic-net:masterfrom
dlanov:fix-857-exception-type-tests

Conversation

@dlanov

@dlanov dlanov commented Aug 10, 2026

Copy link
Copy Markdown

What

Replace exception-message string comparisons in tests/main.cpp with EXPECT_THROW assertions using the expected exception types.

Fixes #857.

Why

The existing tests depend on exact exception text, which makes them fragile when error messages change. The manual try/catch blocks also do not fail if the expected call stops throwing altogether.

How

  • Check missing database config with std::runtime_error.
  • Check access before global database config initialization with std::runtime_error.
  • Check an invalid namespace/key with std::out_of_range.
  • Remove the obsolete exception-message comparisons.

Testing

Built the unit-test binary with:

./autogen.sh
./configure --enable-debug --disable-yangmodules 'CXXFLAGS=-O0 -g'
make common/cfg_schema.h
GCC_COLORS=1 make -j16 tests/tests

Ran:

./tests/tests --gtest_filter='STRINGUTILITY.*'

Result:

[PASSED] 7 tests.

The global SwsscommonEnvironment::SetUp() executed all three updated exception checks successfully.

Signed-off-by: Dennis Lanov <dennis.lanov@gmail.com>
@mssonicbld

Copy link
Copy Markdown
Collaborator

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
There may be pipelines that require an authorized user to comment /azp run to run.

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).

@mssonicbld

Copy link
Copy Markdown
Collaborator

Hi, there are workflow run(s) waiting for approval, you may be first-time contributor. I will notify maintainers to help approve once PR is approved. Thanks!

---Powered by SONiC BuildBot

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

String Equality tests in tests/main.cpp

2 participants