From 3fdc2abd2728e5e353e332765362c0bebf0d88d8 Mon Sep 17 00:00:00 2001 From: Raphael 'kena' Poss Date: Mon, 28 Aug 2023 14:55:17 +0200 Subject: [PATCH] serverutils: move an assertion to a better place Prior to this patch, the assertion on the value of DefaultTestTenant was inside `ShouldStartDefaultTestTenant()`. However, this function is only ever called from `StartServer`; it is not called from `NewServer()`. This means that tests that call `NewServer` directly do not get the benefit of the validity check. This patch moves the assertion to the better place. Release note: None --- pkg/testutils/serverutils/test_server_shim.go | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/pkg/testutils/serverutils/test_server_shim.go b/pkg/testutils/serverutils/test_server_shim.go index 6931e7408d1d..a42cd45e5fe9 100644 --- a/pkg/testutils/serverutils/test_server_shim.go +++ b/pkg/testutils/serverutils/test_server_shim.go @@ -75,12 +75,6 @@ var PreventStartTenantError = errors.New("attempting to manually start a virtual func ShouldStartDefaultTestTenant( t TestLogger, baseArg base.DefaultTestTenantOptions, ) (retval base.DefaultTestTenantOptions) { - defer func() { - if !(retval.TestTenantAlwaysEnabled() || retval.TestTenantAlwaysDisabled()) { - panic(errors.AssertionFailedf("programming error: no decision was actually taken")) - } - }() - // Explicit cases for enabling or disabling the default test tenant. if baseArg.TestTenantAlwaysEnabled() { return baseArg @@ -243,6 +237,10 @@ func NewServer(params base.TestServerArgs) (TestServerInterface, error) { return nil, errors.AssertionFailedf("TestServerFactory not initialized. One needs to be injected " + "from the package's TestMain()") } + tcfg := params.DefaultTestTenant + if !(tcfg.TestTenantAlwaysEnabled() || tcfg.TestTenantAlwaysDisabled()) { + return nil, errors.AssertionFailedf("programming error: DefaultTestTenant does not contain a decision\n(maybe call ShouldStartDefaultTestTennat?)") + } srv, err := srvFactoryImpl.New(params) if err != nil {