@@ -66,11 +66,26 @@ def no_trusted_config(tmp_path, monkeypatch):
6666 monkeypatch .setattr (cli_config .ConfigReader , "config_searchpath" , [str (empty )])
6767
6868
69- def test_load_returns_builtins_when_no_config (tmp_path , no_trusted_config ):
70- """With no config file present, the built-in table is used."""
71- assert load_default_domains (config_path = tmp_path / "absent.ini" ) == list (
72- BUILTIN_DOMAINS
73- )
69+ @pytest .mark .parametrize (
70+ "body" ,
71+ [
72+ None ,
73+ "[default]\n api_host = https://api.cloudsmith.io\n " ,
74+ "this is not valid ini [[[" ,
75+ ],
76+ ids = ["absent" , "no-domains-section" , "malformed" ],
77+ )
78+ def test_a_config_declaring_no_table_falls_back_to_builtins (
79+ tmp_path , no_trusted_config , body
80+ ):
81+ """Only a readable [domains] section replaces the built-in table."""
82+ config = tmp_path / "config.ini"
83+ if body is None :
84+ config = tmp_path / "absent.ini"
85+ else :
86+ config .write_text (body , encoding = "utf-8" )
87+
88+ assert load_default_domains (config_path = config ) == list (BUILTIN_DOMAINS )
7489
7590
7691def test_explicit_config_without_a_table_falls_back_to_a_trusted_one (
@@ -116,7 +131,6 @@ def test_config_section_replaces_builtins_wholesale(tmp_path, no_trusted_config)
116131 indexed = _by_host (domains )
117132 assert indexed ["packages.internal.example.com" ].backend_kind == (BackendKind .PYTHON )
118133 assert indexed ["packages.internal.example.com" ].format_label == "python"
119- # An empty value means "no single format".
120134 assert indexed ["cdn.internal.example.com" ].backend_kind is None
121135 assert indexed ["cdn.internal.example.com" ].format_label is None
122136 assert indexed ["cdn.internal.example.com" ].domain_type is DomainType .DOWNLOAD
@@ -172,26 +186,6 @@ def test_config_label_without_backend_kind_is_formatless(tmp_path, no_trusted_co
172186 assert domain .domain_type is DomainType .DOWNLOAD
173187
174188
175- def test_config_without_domains_section_falls_back_to_builtins (
176- tmp_path , no_trusted_config
177- ):
178- """A config file that has no [domains] section changes nothing."""
179- config = tmp_path / "config.ini"
180- config .write_text (
181- "[default]\n api_host = https://api.cloudsmith.io\n " , encoding = "utf-8"
182- )
183-
184- assert load_default_domains (config_path = config ) == list (BUILTIN_DOMAINS )
185-
186-
187- def test_unreadable_config_falls_back_to_builtins (tmp_path , no_trusted_config ):
188- """A malformed config must not break the command."""
189- config = tmp_path / "config.ini"
190- config .write_text ("this is not valid ini [[[" , encoding = "utf-8" )
191-
192- assert load_default_domains (config_path = config ) == list (BUILTIN_DOMAINS )
193-
194-
195189def test_trusted_lookup_skips_a_config_without_a_domains_section (tmp_path , monkeypatch ):
196190 """The table comes from the first trusted config that declares one.
197191
@@ -340,8 +334,6 @@ def test_untrusted_cwd_config_is_not_honoured(tmp_path, monkeypatch):
340334 a Cloudsmith host and harvest a token.
341335 """
342336 monkeypatch .chdir (tmp_path )
343- # Pin the trusted lookup to "nothing found" so the developer's real
344- # config.ini cannot influence what this test observes.
345337 monkeypatch .setattr (
346338 "cloudsmith_cli.credential_helpers.default_domains._trusted_domains" ,
347339 lambda : None ,
@@ -467,14 +459,13 @@ def test_builtin_domains_with_a_backend_kind_are_native_api():
467459 assert domain .domain_type is DomainType .NATIVE_API , domain .host
468460
469461
470- def test_builtin_host_for_type_resolves_download_and_upload ():
471- """The download/upload hosts are looked up by type, not by constant."""
462+ def test_builtin_host_for_type_resolves_the_format_less_hosts ():
463+ """The download and upload hosts are looked up by type, not by constant.
464+
465+ NATIVE_API covers many hosts, so there is no single one to return.
466+ """
472467 assert builtin_host_for_type (DomainType .DOWNLOAD ) == "dl.cloudsmith.io"
473468 assert builtin_host_for_type (DomainType .UPLOAD ) == "upload.cloudsmith.io"
474-
475-
476- def test_builtin_host_for_type_rejects_ambiguous_native_api ():
477- """NATIVE_API covers many hosts, so there is no single one to return."""
478469 with pytest .raises (ValueError ):
479470 builtin_host_for_type (DomainType .NATIVE_API )
480471
@@ -483,25 +474,20 @@ def test_builtin_host_for_type_rejects_ambiguous_native_api():
483474 "backend_kind,expected" ,
484475 [
485476 (BackendKind .MAVEN , DomainType .NATIVE_API ),
486- # DEB is 0 and therefore falsy: a truthiness check here would
487- # misclassify it as a download host.
488477 (BackendKind .DEB , DomainType .NATIVE_API ),
489478 (None , DomainType .DOWNLOAD ),
490479 ],
480+ ids = ["maven" , "deb-is-zero-so-falsy" , "no-kind" ],
491481)
492482def test_domain_type_for_backend_kind (backend_kind , expected ):
493483 """A kind implies native API; its absence implies a download host."""
494484 assert domain_type_for_backend_kind (backend_kind ) is expected
495485
496486
497- def test_builtin_host_resolves_backend_kind ():
498- """builtin_host maps a backend kind to its built-in service host."""
487+ def test_builtin_host_resolves_a_backend_kind_to_its_own_host ():
488+ """Formats served only via the CDN have no dedicated built-in host."""
499489 assert builtin_host (BackendKind .MAVEN ) == "maven.cloudsmith.io"
500490 assert builtin_host (BackendKind .PYTHON ) == "python.cloudsmith.io"
501-
502-
503- def test_builtin_host_rejects_kind_without_dedicated_host ():
504- """Formats served only via the CDN have no dedicated built-in host."""
505491 with pytest .raises (ValueError ):
506492 builtin_host (BackendKind .DEB )
507493
0 commit comments