Skip to content

Commit 971290a

Browse files
AdmiringWormgep13
authored andcommitted
(chocolatey#2462) Deprecate remote args for list command
This commit updates the list command to deprecate the argument `--local-only` and arguments only valid for remote sources when running the list command, with a message that list will be made local only by default in v2.0.0. The same message mentions to use search or find instead for remote searches. There are additionally several messages other places to ensure that it will be difficult to miss the deprecation of remote sources when calling the list command.
1 parent 0c4025b commit 971290a

File tree

2 files changed

+388
-19
lines changed

2 files changed

+388
-19
lines changed

src/chocolatey.tests/infrastructure.app/commands/ChocolateyListCommandSpecs.cs

+317
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,142 @@ public void should_implement_search()
6262
{
6363
results.ShouldContain("search");
6464
}
65+
66+
[Fact]
67+
public void should_implement_find()
68+
{
69+
results.ShouldContain("find");
70+
}
6571
}
6672

73+
public class when_configurating_the_argument_parser_for_list_command : ChocolateyListCommandSpecsBase
74+
{
75+
private OptionSet optionSet;
76+
77+
public override void Context()
78+
{
79+
base.Context();
80+
optionSet = new OptionSet();
81+
configuration.CommandName = "list";
82+
}
83+
84+
public override void Because()
85+
{
86+
command.configure_argument_parser(optionSet, configuration);
87+
}
88+
89+
[Fact]
90+
public void should_add_source_to_the_option_set()
91+
{
92+
optionSet.Contains("source").ShouldBeTrue();
93+
}
94+
95+
[Fact]
96+
public void should_add_short_version_of_source_to_the_option_set()
97+
{
98+
optionSet.Contains("s").ShouldBeTrue();
99+
}
100+
101+
[Fact, Obsolete("Local Only will be removed in v2.0.0 for the list command")]
102+
public void should_add_localonly_to_the_option_set()
103+
{
104+
optionSet.Contains("localonly").ShouldBeTrue();
105+
}
106+
107+
[Fact, Obsolete("Local Only will be removed in v2.0.0 for the list command")]
108+
public void should_add_short_version_of_localonly_to_the_option_set()
109+
{
110+
optionSet.Contains("l").ShouldBeTrue();
111+
}
112+
113+
[NUnit.Framework.Theory]
114+
[NUnit.Framework.TestCase("localonly")]
115+
[NUnit.Framework.TestCase("source")]
116+
[NUnit.Framework.TestCase("user")]
117+
[NUnit.Framework.TestCase("password")]
118+
[NUnit.Framework.TestCase("cert")]
119+
[NUnit.Framework.TestCase("certpassword")]
120+
[NUnit.Framework.TestCase("approved-only")]
121+
[NUnit.Framework.TestCase("download-cache-only")]
122+
[NUnit.Framework.TestCase("disable-package-repository-optimizations")]
123+
[Obsolete("Will be removed in v2.0.0 for the list command")]
124+
public void should_add_deprecation_notice_to_option(string argument)
125+
{
126+
optionSet[argument].Description.ShouldContain("DEPRECATION NOTICE");
127+
}
128+
129+
[Fact]
130+
public void should_add_prerelease_to_the_option_set()
131+
{
132+
optionSet.Contains("prerelease").ShouldBeTrue();
133+
}
134+
135+
[Fact]
136+
public void should_add_short_version_of_prerelease_to_the_option_set()
137+
{
138+
optionSet.Contains("pre").ShouldBeTrue();
139+
}
140+
141+
[Fact]
142+
public void should_add_includeprograms_to_the_option_set()
143+
{
144+
optionSet.Contains("includeprograms").ShouldBeTrue();
145+
}
146+
147+
[Fact]
148+
public void should_add_short_version_of_includeprograms_to_the_option_set()
149+
{
150+
optionSet.Contains("i").ShouldBeTrue();
151+
}
152+
153+
[Fact]
154+
public void should_add_allversions_to_the_option_set()
155+
{
156+
optionSet.Contains("allversions").ShouldBeTrue();
157+
}
158+
159+
[Fact]
160+
public void should_add_short_version_of_allversions_to_the_option_set()
161+
{
162+
optionSet.Contains("a").ShouldBeTrue();
163+
}
164+
165+
[Fact, Obsolete("Will be removed in v2.0.0")]
166+
public void should_add_user_to_the_option_set()
167+
{
168+
optionSet.Contains("user").ShouldBeTrue();
169+
}
170+
171+
[Fact, Obsolete("Will be removed in v2.0.0")]
172+
public void should_add_short_version_of_user_to_the_option_set()
173+
{
174+
optionSet.Contains("u").ShouldBeTrue();
175+
}
176+
177+
[Fact, Obsolete("Will be removed in v2.0.0")]
178+
public void should_add_password_to_the_option_set()
179+
{
180+
optionSet.Contains("password").ShouldBeTrue();
181+
}
182+
183+
[Fact, Obsolete("Will be removed in v2.0.0")]
184+
public void should_add_short_version_of_password_to_the_option_set()
185+
{
186+
optionSet.Contains("p").ShouldBeTrue();
187+
}
188+
}
189+
190+
[NUnit.Framework.TestFixture("search")]
191+
[NUnit.Framework.TestFixture("find")]
67192
public class when_configurating_the_argument_parser : ChocolateyListCommandSpecsBase
68193
{
69194
private OptionSet optionSet;
70195

196+
public when_configurating_the_argument_parser(string commandName)
197+
{
198+
configuration.CommandName = commandName;
199+
}
200+
71201
public override void Context()
72202
{
73203
base.Context();
@@ -162,6 +292,21 @@ public void should_add_short_version_of_password_to_the_option_set()
162292
{
163293
optionSet.Contains("p").ShouldBeTrue();
164294
}
295+
296+
[NUnit.Framework.Theory]
297+
[NUnit.Framework.TestCase("localonly")]
298+
[NUnit.Framework.TestCase("source")]
299+
[NUnit.Framework.TestCase("user")]
300+
[NUnit.Framework.TestCase("password")]
301+
[NUnit.Framework.TestCase("cert")]
302+
[NUnit.Framework.TestCase("certpassword")]
303+
[NUnit.Framework.TestCase("approved-only")]
304+
[NUnit.Framework.TestCase("download-cache-only")]
305+
[NUnit.Framework.TestCase("disable-package-repository-optimizations")]
306+
public void should_add_deprecation_notice_to_option(string argument)
307+
{
308+
optionSet[argument].Description.ShouldNotContain("DEPRECATION NOTICE");
309+
}
165310
}
166311

167312
public class when_handling_additional_argument_parsing : ChocolateyListCommandSpecsBase
@@ -199,6 +344,61 @@ public void should_leave_source_as_set()
199344
}
200345
}
201346

347+
public class when_noop_is_called_with_list_command : ChocolateyListCommandSpecsBase
348+
{
349+
public override void Context()
350+
{
351+
base.Context();
352+
configuration.CommandName = "list";
353+
}
354+
355+
public override void Because()
356+
{
357+
command.noop(configuration);
358+
}
359+
360+
[Fact]
361+
public void should_call_service_list_noop()
362+
{
363+
packageService.Verify(c => c.list_noop(configuration), Times.Once);
364+
}
365+
366+
[Fact]
367+
public void should_report_deprecation_of_remote_sources()
368+
{
369+
MockLogger.Messages.Keys.ShouldContain("Warn");
370+
MockLogger.Messages["Warn"].ShouldContain(@"Using list with remote sources is deprecated and will be made local only in v2.0.0,
371+
use the commands search or find instead for remote sources.");
372+
}
373+
}
374+
375+
public class when_noop_is_called_with_list_command_and_local_only : ChocolateyListCommandSpecsBase
376+
{
377+
public override void Context()
378+
{
379+
base.Context();
380+
configuration.CommandName = "list";
381+
configuration.ListCommand.LocalOnly = true;
382+
}
383+
384+
public override void Because()
385+
{
386+
command.noop(configuration);
387+
}
388+
389+
[Fact]
390+
public void should_call_service_list_noop()
391+
{
392+
packageService.Verify(c => c.list_noop(configuration), Times.Once);
393+
}
394+
395+
[Fact]
396+
public void should_not_report_any_warning_messages()
397+
{
398+
MockLogger.Messages.Keys.ShouldNotContain("Warn");
399+
}
400+
}
401+
202402
public class when_noop_is_called : ChocolateyListCommandSpecsBase
203403
{
204404
public override void Because()
@@ -211,6 +411,67 @@ public void should_call_service_list_noop()
211411
{
212412
packageService.Verify(c => c.list_noop(configuration), Times.Once);
213413
}
414+
415+
[Fact]
416+
public void should_not_report_any_warning_messages()
417+
{
418+
MockLogger.Messages.Keys.ShouldNotContain("Warn");
419+
}
420+
}
421+
422+
public class when_run_is_called_with_list_command : ChocolateyListCommandSpecsBase
423+
{
424+
public override void Context()
425+
{
426+
base.Context();
427+
configuration.CommandName = "list";
428+
}
429+
430+
public override void Because()
431+
{
432+
command.run(configuration);
433+
}
434+
435+
[Fact]
436+
public void should_call_service_list_run()
437+
{
438+
packageService.Verify(c => c.list_run(configuration), Times.Once);
439+
}
440+
441+
[Fact]
442+
public void should_not_report_any_warning_messages()
443+
{
444+
MockLogger.Messages.Keys.ShouldContain("Warn");
445+
MockLogger.Messages["Warn"].ShouldContain(@"Using list with remote sources is deprecated and will be made local only in v2.0.0,
446+
use the commands search or find instead for remote sources.");
447+
}
448+
}
449+
450+
public class when_run_is_called_with_list_command_and_local_only : ChocolateyListCommandSpecsBase
451+
{
452+
public override void Context()
453+
{
454+
base.Context();
455+
configuration.CommandName = "list";
456+
configuration.ListCommand.LocalOnly = true;
457+
}
458+
459+
public override void Because()
460+
{
461+
command.run(configuration);
462+
}
463+
464+
[Fact]
465+
public void should_call_service_list_run()
466+
{
467+
packageService.Verify(c => c.list_run(configuration), Times.Once);
468+
}
469+
470+
[Fact]
471+
public void should_not_report_any_warning_messages()
472+
{
473+
MockLogger.Messages.Keys.ShouldNotContain("Warn");
474+
}
214475
}
215476

216477
public class when_run_is_called : ChocolateyListCommandSpecsBase
@@ -225,6 +486,62 @@ public void should_call_service_list_run()
225486
{
226487
packageService.Verify(c => c.list_run(configuration), Times.Once);
227488
}
489+
490+
[Fact]
491+
public void should_not_report_any_warning_messages()
492+
{
493+
MockLogger.Messages.Keys.ShouldNotContain("Warn");
494+
}
495+
}
496+
497+
public class when_outputting_help_message_for_list_command : ChocolateyListCommandSpecsBase
498+
{
499+
public override void Context()
500+
{
501+
base.Context();
502+
configuration.CommandName = "list";
503+
}
504+
505+
public override void Because()
506+
{
507+
command.help_message(configuration);
508+
}
509+
510+
[Fact, Obsolete("Will be removed in v2.0.0")]
511+
public void should_output_deprecation_notice_header()
512+
{
513+
MockLogger.Messages.Keys.ShouldContain("Warn");
514+
MockLogger.Messages["Warn"].ShouldContain("DEPRECATION NOTICE");
515+
}
516+
517+
[Fact]
518+
public void should_ouput_removal_in_v2_0_0()
519+
{
520+
MockLogger.Messages.Keys.ShouldContain("Warn");
521+
MockLogger.Messages["Warn"].ShouldContain(@"
522+
Will be removed for the list command in v2.0.0.");
523+
}
524+
}
525+
526+
[NUnit.Framework.TestFixture("search")]
527+
[NUnit.Framework.TestFixture("find")]
528+
public class when_outputting_help_message : ChocolateyListCommandSpecsBase
529+
{
530+
public when_outputting_help_message(string commandName)
531+
{
532+
configuration.CommandName = commandName;
533+
}
534+
535+
public override void Because()
536+
{
537+
command.help_message(configuration);
538+
}
539+
540+
[Fact]
541+
public void should_not_output_warnings()
542+
{
543+
MockLogger.Messages.Keys.ShouldNotContain("Warn");
544+
}
228545
}
229546
}
230547
}

0 commit comments

Comments
 (0)