replace global vault handlers with newVaultHandlers() (#27515)

This commit is contained in:
Thy Ton
2024-06-18 22:17:40 +07:00
committed by GitHub
parent ff8442dff7
commit 28c2e94382
9 changed files with 111 additions and 82 deletions

View File

@@ -12,34 +12,35 @@ import (
"github.com/stretchr/testify/require"
)
// Test_extendAddonCommands tests extendAddonCommands() extends physical and logical backends with
// those generated by newFullAddonCommands()
func Test_extendAddonCommands(t *testing.T) {
expMinPhysicalBackends := maps.Clone(physicalBackends)
expMinLoginHandlers := maps.Clone(loginHandlers)
// Test_extendAddonHandlers tests extendAddonHandlers() extends the minimal Vault handlers with handlers
// generated by newFullAddonHandlers()
func Test_extendAddonHandlers(t *testing.T) {
handlers := newMinimalVaultHandlers()
expMinPhysicalBackends := maps.Clone(handlers.physicalBackends)
expMinLoginHandlers := maps.Clone(handlers.loginHandlers)
expAddonPhysicalBackends, expAddonLoginHandlers := newFullAddonCommands()
expAddonPhysicalBackends, expAddonLoginHandlers := newFullAddonHandlers()
extendAddonCommands()
extendAddonHandlers(handlers)
require.Equal(t, len(expMinPhysicalBackends)+len(expAddonPhysicalBackends), len(physicalBackends),
require.Equal(t, len(expMinPhysicalBackends)+len(expAddonPhysicalBackends), len(handlers.physicalBackends),
"extended total physical backends mismatch total of minimal and full addon physical backends")
require.Equal(t, len(expMinLoginHandlers)+len(expAddonLoginHandlers), len(loginHandlers),
require.Equal(t, len(expMinLoginHandlers)+len(expAddonLoginHandlers), len(handlers.loginHandlers),
"extended total login handlers mismatch total of minimal and full addon login handlers")
for k := range expMinPhysicalBackends {
require.Contains(t, physicalBackends, k, "expected to contain minimal physical backend")
require.Contains(t, handlers.physicalBackends, k, "expected to contain minimal physical backend")
}
for k := range expAddonPhysicalBackends {
require.Contains(t, physicalBackends, k, "expected to contain full addon physical backend")
require.Contains(t, handlers.physicalBackends, k, "expected to contain full addon physical backend")
}
for k := range expMinLoginHandlers {
require.Contains(t, loginHandlers, k, "expected to contain minimal login handler")
require.Contains(t, handlers.loginHandlers, k, "expected to contain minimal login handler")
}
for k := range expAddonLoginHandlers {
require.Contains(t, loginHandlers, k, "expected to contain full addon login handler")
require.Contains(t, handlers.loginHandlers, k, "expected to contain full addon login handler")
}
}