MCPcopy Create free account
hub / github.com/auth0/auth0-cli / TestBuildNestedMap

Function TestBuildNestedMap

internal/cli/quickstart_detect_test.go:1786–1830  ·  view source on GitHub ↗

-- buildNestedMap --.

(t *testing.T)

Source from the content-addressed store, hash-verified

1784// -- buildNestedMap --.
1785
1786func TestBuildNestedMap(t *testing.T) {
1787 t.Run("dot-delimited keys produce nested structure", func(t *testing.T) {
1788 flat := map[string]string{
1789 "okta.oauth2.issuer": "https://example.auth0.com/",
1790 "okta.oauth2.client-id": "abc",
1791 "okta.oauth2.client-secret": "secret",
1792 }
1793 got := buildNestedMap(flat)
1794
1795 okta, ok := got["okta"].(map[string]interface{})
1796 require.True(t, ok, "expected 'okta' to be a map")
1797 oauth2, ok := okta["oauth2"].(map[string]interface{})
1798 require.True(t, ok, "expected 'oauth2' to be a map")
1799 assert.Equal(t, "https://example.auth0.com/", oauth2["issuer"])
1800 assert.Equal(t, "abc", oauth2["client-id"])
1801 assert.Equal(t, "secret", oauth2["client-secret"])
1802 })
1803
1804 t.Run("non-dot keys remain top-level", func(t *testing.T) {
1805 flat := map[string]string{"Domain": "example.com", "ClientId": "abc"}
1806 got := buildNestedMap(flat)
1807 assert.Equal(t, "example.com", got["Domain"])
1808 assert.Equal(t, "abc", got["ClientId"])
1809 })
1810
1811 t.Run("empty map returns empty result", func(t *testing.T) {
1812 got := buildNestedMap(map[string]string{})
1813 assert.Empty(t, got)
1814 })
1815
1816 t.Run("leaf key and nested key under same prefix do not panic", func(t *testing.T) {
1817 // "a" is a leaf (string) but "a.b" tries to descend into "a". The guarded
1818 // type assertion must recover and create a new nested map rather than panic.
1819 flat := map[string]string{
1820 "a": "leaf-value",
1821 "a.b": "nested-value",
1822 }
1823 // Must not panic; result should at minimum contain the nested key.
1824 got := buildNestedMap(flat)
1825 require.NotNil(t, got)
1826 aVal, ok := got["a"].(map[string]interface{})
1827 require.True(t, ok, "expected 'a' to be promoted to a nested map")
1828 assert.Equal(t, "nested-value", aVal["b"])
1829 })
1830}
1831
1832// -- sortedKeys --.
1833

Callers

nothing calls this directly

Calls 1

buildNestedMapFunction · 0.85

Tested by

no test coverage detected