-
Notifications
You must be signed in to change notification settings - Fork 748
Expand file tree
/
Copy pathPushCommandTest.cs
More file actions
1246 lines (1058 loc) · 59.2 KB
/
PushCommandTest.cs
File metadata and controls
1246 lines (1058 loc) · 59.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
#nullable disable
using System;
using System.Collections.Generic;
using System.IO;
using System.Net;
using System.Threading;
using Microsoft.Internal.NuGet.Testing.SignedPackages.ChildProcess;
using NuGet.CommandLine.Test;
using NuGet.Configuration;
using NuGet.Test.Utility;
using Test.Utility;
using Xunit;
namespace NuGet.CommandLine.FuncTest.Commands
{
public class PushCommandTest
{
private const string MESSAGE_EXISTING_PACKAGE = "already exists at feed"; //Derived from resx: AddPackage_PackageAlreadyExists
private const string MESSAGE_RESPONSE_NO_SUCCESS = "Response status code does not indicate success";
private const string MESSAGE_PACKAGE_PUSHED = "Your package was pushed.";
private const string TEST_PACKAGE_SHOULD_NOT_PUSH = "The package should not have been pushed";
private const string TEST_PACKAGE_SHOULD_PUSH = "The package should have been pushed";
private const string ADVERTISE_SKIPDUPLICATE_OPTION = "To skip already published packages, use the option -SkipDuplicate"; //PushCommandSkipDuplicateAdvertiseNuGetExe
private const string WITHOUT_FILENAME_MESSAGE_FILE_DOES_NOT_EXIST = "File does not exist";
private const string MESSAGE_FILE_DOES_NOT_EXIST = WITHOUT_FILENAME_MESSAGE_FILE_DOES_NOT_EXIST + " ({0})";
private readonly ITestOutputHelper _testOutputHelper;
public PushCommandTest(ITestOutputHelper testOutputHelper)
{
_testOutputHelper = testOutputHelper;
}
/// <summary>
/// 100 seconds is significant because that is the default timeout on <see cref="HttpClient"/>.
/// Related to https://github.com/NuGet/Home/issues/2785.
/// </summary>
[Fact(Skip = "https://github.com/NuGet/Home/issues/13843")]
public void PushCommand_AllowsTimeoutToBeSpecifiedHigherThan100Seconds()
{
// Arrange
using (SimpleTestPathContext pathContext = new SimpleTestPathContext())
{
var nuget = Util.GetNuGetExePath();
var sourcePath = Util.CreateTestPackage("PackageA", "1.1.0", pathContext.WorkingDirectory);
var outputPath = Path.Combine(pathContext.WorkingDirectory, "pushed.nupkg");
CommandRunnerResult result = null;
using (var server = new MockServer())
{
server.Put.Add("/push", r =>
{
Thread.Sleep(TimeSpan.FromSeconds(101));
byte[] buffer = MockServer.GetPushedPackage(r);
using (var outputStream = new FileStream(outputPath, FileMode.Create))
{
outputStream.Write(buffer, 0, buffer.Length);
}
return HttpStatusCode.Created;
});
pathContext.Settings.AddSource("http-feed", $"{server.Uri}push", "true");
server.Start();
// Act
result = CommandRunner.Run(
nuget,
pathContext.WorkingDirectory,
$"push {sourcePath} -Source {server.Uri}push -Timeout 110",
timeOutInMilliseconds: 120 * 1000,
logLine: _testOutputHelper.WriteLine); // 120 seconds
}
// Assert
Assert.True(result.Success, $"{result.Output} {result.Errors}");
Assert.Contains(MESSAGE_PACKAGE_PUSHED, result.Output);
Assert.True(File.Exists(outputPath), TEST_PACKAGE_SHOULD_PUSH);
Assert.Equal(File.ReadAllBytes(sourcePath), File.ReadAllBytes(outputPath));
}
}
[Fact(Skip = "https://github.com/NuGet/Home/issues/13843")]
public void PushCommand_AllowsTimeoutToBeSpecifiedLowerThan100Seconds()
{
// Arrange
using (SimpleTestPathContext pathContext = new SimpleTestPathContext())
{
var nuget = Util.GetNuGetExePath();
var sourcePath = Util.CreateTestPackage("PackageA", "1.1.0", pathContext.WorkingDirectory);
var outputPath = Path.Combine(pathContext.WorkingDirectory, "pushed.nupkg");
CommandRunnerResult result = null;
using (var server = new MockServer())
{
server.Put.Add("/push", r =>
{
Thread.Sleep(TimeSpan.FromSeconds(5));
byte[] buffer = MockServer.GetPushedPackage(r);
using (var outputStream = new FileStream(outputPath, FileMode.Create))
{
outputStream.Write(buffer, 0, buffer.Length);
}
return HttpStatusCode.Created;
});
pathContext.Settings.AddSource("http-feed", $"{server.Uri}push", "true");
server.Start();
// Act
result = CommandRunner.Run(
nuget,
pathContext.WorkingDirectory,
$"push {sourcePath} -Source {server.Uri}push -Timeout 1",
timeOutInMilliseconds: 20 * 1000,
logLine: _testOutputHelper.WriteLine); // 20 seconds
}
// Assert
Assert.False(result.Success, $"{result.Output} {result.Errors}");
Assert.DoesNotContain(MESSAGE_PACKAGE_PUSHED, result.Output);
Assert.False(File.Exists(outputPath), TEST_PACKAGE_SHOULD_NOT_PUSH);
}
}
[Fact]
public void PushCommand_Server_SkipDuplicate_NotSpecified_PushHalts()
{
// Arrange
using (SimpleTestPathContext pathContext = new SimpleTestPathContext())
{
var nuget = Util.GetNuGetExePath();
var sourcePath = Util.CreateTestPackage("PackageA", "1.1.0", pathContext.WorkingDirectory);
var outputPath = Path.Combine(pathContext.WorkingDirectory, "pushed.nupkg");
var sourcePath2 = Util.CreateTestPackage("PackageB", "1.1.0", pathContext.WorkingDirectory);
var outputPath2 = Path.Combine(pathContext.WorkingDirectory, "pushed2.nupkg");
CommandRunnerResult result = null;
CommandRunnerResult result2 = null;
CommandRunnerResult result3 = null;
using (var server = new MockServer())
{
SetupMockServerForSkipDuplicate(server,
FuncOutputPath_SwitchesOnThirdPush(outputPath, outputPath2),
FuncStatusDuplicate_OccursOnSecondPush());
server.Start();
pathContext.Settings.AddSource("http-feed", $"{server.Uri}push", "true");
// Act
result = CommandRunner.Run(
nuget,
pathContext.WorkingDirectory,
$"push {sourcePath} -Source {server.Uri}push -Timeout 110",
timeOutInMilliseconds: 120 * 1000,
logLine: _testOutputHelper.WriteLine); // 120 seconds
//Run again so that it will be a duplicate push.
result2 = CommandRunner.Run(
nuget,
pathContext.WorkingDirectory,
$"push {sourcePath} -Source {server.Uri}push -Timeout 110",
timeOutInMilliseconds: 120 * 1000,
logLine: _testOutputHelper.WriteLine); // 120 seconds
result3 = CommandRunner.Run(
nuget,
pathContext.WorkingDirectory,
$"push {sourcePath2} -Source {server.Uri}push -Timeout 110",
timeOutInMilliseconds: 120 * 1000,
logLine: _testOutputHelper.WriteLine); // 120 seconds
}
// Assert
Assert.True(result.Success, $"{result.Output} {result.Errors}");
Assert.Contains(MESSAGE_PACKAGE_PUSHED, result.Output);
Assert.True(File.Exists(outputPath), TEST_PACKAGE_SHOULD_PUSH);
Assert.DoesNotContain(MESSAGE_RESPONSE_NO_SUCCESS, result.AllOutput);
Assert.DoesNotContain(MESSAGE_EXISTING_PACKAGE, result.AllOutput);
Assert.Equal(File.ReadAllBytes(sourcePath), File.ReadAllBytes(outputPath));
// Second run of command is the duplicate.
Assert.False(result2.Success, result2.AllOutput);
Assert.Contains(MESSAGE_RESPONSE_NO_SUCCESS, result2.AllOutput);
Assert.DoesNotContain(MESSAGE_EXISTING_PACKAGE, result2.AllOutput);
Assert.Contains(ADVERTISE_SKIPDUPLICATE_OPTION, result2.AllOutput);
Assert.Equal(File.ReadAllBytes(sourcePath), File.ReadAllBytes(outputPath));
}
}
[Fact]
public void PushCommand_Server_SkipDuplicate_IsSpecified_PushProceeds()
{
// Arrange
using (SimpleTestPathContext pathContext = new SimpleTestPathContext())
{
var nuget = Util.GetNuGetExePath();
var sourcePath = Util.CreateTestPackage("PackageA", "1.1.0", pathContext.WorkingDirectory);
var outputPath = Path.Combine(pathContext.WorkingDirectory, "pushed.nupkg");
var sourcePath2 = Util.CreateTestPackage("PackageB", "1.1.0", pathContext.WorkingDirectory);
var outputPath2 = Path.Combine(pathContext.WorkingDirectory, "pushed2.nupkg");
CommandRunnerResult result = null;
CommandRunnerResult result2 = null;
CommandRunnerResult result3 = null;
using (var server = new MockServer())
{
SetupMockServerForSkipDuplicate(server,
FuncOutputPath_SwitchesOnThirdPush(outputPath, outputPath2),
FuncStatusDuplicate_OccursOnSecondPush());
pathContext.Settings.AddSource("http-feed", $"{server.Uri}push", "true");
server.Start();
// Act
result = CommandRunner.Run(
nuget,
pathContext.WorkingDirectory,
$"push {sourcePath} -Source {server.Uri}push -Timeout 110 -SkipDuplicate",
timeOutInMilliseconds: 120 * 1000,
logLine: _testOutputHelper.WriteLine); // 120 seconds
//Run again so that it will be a duplicate push but use the option to skip duplicate packages.
result2 = CommandRunner.Run(
nuget,
pathContext.WorkingDirectory,
$"push {sourcePath} -Source {server.Uri}push -Timeout 110 -SkipDuplicate",
timeOutInMilliseconds: 120 * 1000,
logLine: _testOutputHelper.WriteLine); // 120 seconds
//Third run with a different package.
result3 = CommandRunner.Run(
nuget,
pathContext.WorkingDirectory,
$"push {sourcePath2} -Source {server.Uri}push -Timeout 110 -SkipDuplicate",
timeOutInMilliseconds: 120 * 1000,
logLine: _testOutputHelper.WriteLine); // 120 seconds
}
// Assert
Assert.True(result.Success, $"{result.Output} {result.Errors}");
Assert.Contains(MESSAGE_PACKAGE_PUSHED, result.AllOutput);
Assert.True(File.Exists(outputPath), TEST_PACKAGE_SHOULD_PUSH);
Assert.DoesNotContain(MESSAGE_RESPONSE_NO_SUCCESS, result.AllOutput);
Assert.Equal(File.ReadAllBytes(sourcePath), File.ReadAllBytes(outputPath));
// Second run of command is the duplicate.
Assert.True(result2.Success, result2.AllOutput);
Assert.DoesNotContain(MESSAGE_PACKAGE_PUSHED, result2.AllOutput);
Assert.Contains(MESSAGE_EXISTING_PACKAGE, result2.AllOutput);
Assert.DoesNotContain(MESSAGE_RESPONSE_NO_SUCCESS, result2.AllOutput);
// Third run after a duplicate should be successful with the SkipDuplicate flag.
Assert.True(result3.Success, $"{result3.Output} {result3.Errors}");
Assert.Contains(MESSAGE_PACKAGE_PUSHED, result3.AllOutput);
Assert.True(File.Exists(outputPath2), TEST_PACKAGE_SHOULD_PUSH);
Assert.Equal(File.ReadAllBytes(sourcePath2), File.ReadAllBytes(outputPath2));
}
}
/// <summary>
/// When pushing a snupkg filename that doesn't exist, show a File Not Found error.
/// </summary>
[Fact]
public void PushCommand_Server_Snupkg_ByFilename_DoesNotExist_FileNotFoundError()
{
// Arrange
using (SimpleTestPathContext pathContext = new SimpleTestPathContext())
{
var nuget = Util.GetNuGetExePath();
string snupkgToPush = "nonExistingPackage.snupkg";
CommandRunnerResult result = null;
using (var server = CreateAndStartMockV3Server(pathContext.WorkingDirectory, out string sourceName))
{
pathContext.Settings.AddSource(sourceName, sourceName, "true");
// Act
result = CommandRunner.Run(
nuget,
pathContext.WorkingDirectory,
$"push {snupkgToPush} -Source {sourceName} -Timeout 110",
timeOutInMilliseconds: 120000,
logLine: _testOutputHelper.WriteLine); // 120 seconds
}
// Assert
string expectedFileNotFoundErrorMessage = string.Format(MESSAGE_FILE_DOES_NOT_EXIST, snupkgToPush);
Assert.False(result.Success, "File did not exist and should fail.");
Assert.DoesNotContain(MESSAGE_PACKAGE_PUSHED, result.Output);
Assert.Contains(expectedFileNotFoundErrorMessage, result.Errors);
}
}
/// <summary>
/// When pushing a snupkg wildcard where no matching files exist, show a File Not Found error.
/// </summary>
[Fact]
public void PushCommand_Server_Snupkg_ByWildcard_FindsNothing_FileNotFoundError()
{
// Arrange
using (SimpleTestPathContext pathContext = new SimpleTestPathContext())
{
var nuget = Util.GetNuGetExePath();
string snupkgToPush = "*.snupkg";
CommandRunnerResult result = null;
using (var server = CreateAndStartMockV3Server(pathContext.WorkingDirectory, out string sourceName))
{
pathContext.Settings.AddSource(sourceName, sourceName, "true");
// Act
result = CommandRunner.Run(
nuget,
pathContext.WorkingDirectory,
$"push {snupkgToPush} -Source {sourceName} -Timeout 110",
timeOutInMilliseconds: 120000,
logLine: _testOutputHelper.WriteLine); // 120 seconds
}
//Assert
string expectedFileNotFoundErrorMessage = string.Format(MESSAGE_FILE_DOES_NOT_EXIST, snupkgToPush);
Assert.False(result.Success, "File did not exist and should fail.");
Assert.DoesNotContain(MESSAGE_PACKAGE_PUSHED, result.Output);
Assert.Contains(expectedFileNotFoundErrorMessage, result.Errors);
}
}
/// <summary>
/// When pushing a nupkg by filename where no matching files exist, show a File Not Found error.
/// </summary>
[Fact]
public void PushCommand_Server_Nupkg_ByFilename_FindsNothing_FileNotFoundError()
{
// Arrange
using (SimpleTestPathContext pathContext = new SimpleTestPathContext())
{
var nuget = Util.GetNuGetExePath();
string nupkgToPush = "filename.nupkg";
CommandRunnerResult result = null;
using (var server = CreateAndStartMockV3Server(pathContext.WorkingDirectory, out string sourceName))
{
pathContext.Settings.AddSource(sourceName, sourceName, "true");
// Act
result = CommandRunner.Run(
nuget,
pathContext.WorkingDirectory,
$"push {nupkgToPush} -Source {sourceName} -Timeout 110",
timeOutInMilliseconds: 120000,
logLine: _testOutputHelper.WriteLine); // 120 seconds
}
//Assert
string expectedFileNotFoundErrorMessage = string.Format(MESSAGE_FILE_DOES_NOT_EXIST, nupkgToPush);
Assert.False(result.Success, "File did not exist and should fail.");
Assert.DoesNotContain(MESSAGE_PACKAGE_PUSHED, result.Output);
Assert.Contains(expectedFileNotFoundErrorMessage, result.Errors);
}
}
/// <summary>
/// When pushing a nupkg by wildcard where no matching files exist, show a File Not Found error.
/// </summary>
[Fact]
public void PushCommand_Server_Nupkg_ByWildcard_FindsNothing_FileNotFoundError()
{
// Arrange
using (SimpleTestPathContext pathContext = new SimpleTestPathContext())
{
var nuget = Util.GetNuGetExePath();
string nupkgToPush = "*.nupkg";
CommandRunnerResult result = null;
using (var server = CreateAndStartMockV3Server(pathContext.WorkingDirectory, out string sourceName))
{
pathContext.Settings.AddSource(sourceName, sourceName, "true");
// Act
result = CommandRunner.Run(
nuget,
pathContext.WorkingDirectory,
$"push {nupkgToPush} -Source {sourceName} -Timeout 110",
timeOutInMilliseconds: 120000,
logLine: _testOutputHelper.WriteLine); // 120 seconds
}
//Assert
string expectedFileNotFoundErrorMessage = string.Format(MESSAGE_FILE_DOES_NOT_EXIST, nupkgToPush);
Assert.False(result.Success, "File did not exist and should fail.");
Assert.DoesNotContain(MESSAGE_PACKAGE_PUSHED, result.Output);
Assert.Contains(expectedFileNotFoundErrorMessage, result.Errors);
}
}
/// <summary>
/// When pushing a nupkg by filename to a Symbol Server with no matching snupkg, do not show a File Not Found error.
/// </summary>
[Fact]
public void PushCommand_Server_Nupkg_ByFilename_SnupkgDoesNotExist_NoFileNotFoundError()
{
// Arrange
using (SimpleTestPathContext pathContext = new SimpleTestPathContext())
{
var nuget = Util.GetNuGetExePath();
string packageId = "packageWithoutSnupkg";
string version = "1.1.0";
//Create Nupkg in test directory.
string nupkgFullPath = Util.CreateTestPackage(packageId, version, pathContext.WorkingDirectory);
string nupkgFileName = Util.BuildPackageString(packageId, version, NuGetConstants.PackageExtension);
string snupkgFileName = Util.BuildPackageString(packageId, version, NuGetConstants.SnupkgExtension);
string snupkgFullPath = Path.Combine(pathContext.WorkingDirectory, snupkgFileName);
CommandRunnerResult result = null;
using (var server = CreateAndStartMockV3Server(pathContext.WorkingDirectory, out string sourceName))
{
SetupMockServerAlwaysCreate(server);
pathContext.Settings.AddSource(sourceName, sourceName, "true");
// Act
result = CommandRunner.Run(
nuget,
pathContext.WorkingDirectory,
$"push {nupkgFullPath} -Source {sourceName} -Timeout 110",
timeOutInMilliseconds: 120000,
logLine: _testOutputHelper.WriteLine); // 120 seconds
}
// Assert
Assert.True(result.Success, "Expected to successfully push a nupkg without a snupkg.");
Assert.Contains(MESSAGE_PACKAGE_PUSHED, result.Output);
Assert.DoesNotContain(WITHOUT_FILENAME_MESSAGE_FILE_DOES_NOT_EXIST, result.Errors);
}
}
/// <summary>
/// When pushing *.nupkg to a symbol server, but no snupkgs are selected with that wildcard, there is not a FileNotFound error about snupkgs.
/// </summary>
[Fact]
public void PushCommand_Server_Nupkg_ByWildcard_SnupkgDoesNotExist_NoFileNotFoundError()
{
// Arrange
using (SimpleTestPathContext pathContext = new SimpleTestPathContext())
{
var nuget = Util.GetNuGetExePath();
string packageId = "packageWithoutSnupkg";
string version = "1.1.0";
//Create Nupkg in test directory.
string nupkgFullPath = Util.CreateTestPackage(packageId, version, pathContext.WorkingDirectory);
string pushArgument = "*.nupkg";
CommandRunnerResult result = null;
using (var server = CreateAndStartMockV3Server(pathContext.WorkingDirectory, out string sourceName))
{
SetupMockServerAlwaysCreate(server);
pathContext.Settings.AddSource(sourceName, sourceName, "true");
// Act
result = CommandRunner.Run(
nuget,
pathContext.WorkingDirectory,
$"push {pushArgument} -Source {sourceName} -Timeout 110",
timeOutInMilliseconds: 120000,
logLine: _testOutputHelper.WriteLine); // 120 seconds
}
// Assert
string expectedFileNotFoundErrorMessage = string.Format(MESSAGE_FILE_DOES_NOT_EXIST, pushArgument);
Assert.True(result.Success, "Snupkg File did not exist but should not fail a nupkg push.\n\n" + result.AllOutput);
Assert.Contains(MESSAGE_PACKAGE_PUSHED, result.Output);
Assert.DoesNotContain(WITHOUT_FILENAME_MESSAGE_FILE_DOES_NOT_EXIST, result.Errors);
Assert.DoesNotContain(NuGetConstants.SnupkgExtension, result.AllOutput); //Snupkgs should not be mentioned.
}
}
/// <summary>
/// When pushing a nupkg by filename to a Symbol Server with a matching snupkg, a 409 Conflict halts the push.
/// </summary>
[Fact]
public void PushCommand_Server_Nupkg_ByFilename_SnupkgExists_Conflict()
{
// Arrange
using (SimpleTestPathContext pathContext = new SimpleTestPathContext())
{
var nuget = Util.GetNuGetExePath();
string packageId = "packageWithSnupkg";
//Create nupkg in test directory.
string version = "1.1.0";
string nupkgFullPath = Util.CreateTestPackage(packageId, version, pathContext.WorkingDirectory);
string nupkgFileName = Util.BuildPackageString(packageId, version, NuGetConstants.PackageExtension);
string snupkgFileName = Util.BuildPackageString(packageId, version, NuGetConstants.SnupkgExtension);
string snupkgFullPath = Path.Combine(pathContext.WorkingDirectory, snupkgFileName);
//Create snupkg in test directory.
WriteSnupkgFile(snupkgFullPath);
CommandRunnerResult result = null;
CommandRunnerResult result2 = null;
using (var server = CreateAndStartMockV3Server(pathContext.WorkingDirectory, out string sourceName))
{
//Configure push to alternate returning Created and Conflict responses, which correspond to pushing the nupkg and snupkg, respectively.
SetupMockServerCreateNupkgDuplicateSnupkg(server, FuncStatus_Alternates_CreatedAndDuplicate());
pathContext.Settings.AddSource(sourceName, sourceName, "true");
// Act
//Since this is V3, this will trigger 2 pushes: one for nupkgs, and one for snupkgs.
result = CommandRunner.Run(
nuget,
pathContext.WorkingDirectory,
$"push {nupkgFullPath} -Source {sourceName} -Timeout 110",
timeOutInMilliseconds: 120000,
logLine: _testOutputHelper.WriteLine); // 120 seconds
//Second run with SkipDuplicate
result2 = CommandRunner.Run(
nuget,
pathContext.WorkingDirectory,
$"push {nupkgFullPath} -Source {sourceName} -Timeout 110 -SkipDuplicate",
timeOutInMilliseconds: 120000,
logLine: _testOutputHelper.WriteLine); // 120 seconds
}
// Assert
//Ignoring filename in File Not Found error since the error should not appear in any case.
string genericFileNotFoundError = WITHOUT_FILENAME_MESSAGE_FILE_DOES_NOT_EXIST;
//Nupkg should push, but corresponding snupkg is a duplicate and errors.
Assert.False(result.Success, "Expected to fail push a due to duplicate snupkg.");
Assert.Contains(MESSAGE_PACKAGE_PUSHED, result.Output); //nupkg pushed
Assert.Contains(MESSAGE_RESPONSE_NO_SUCCESS, result.AllOutput); //snupkg duplicate
Assert.DoesNotContain(MESSAGE_EXISTING_PACKAGE, result.AllOutput);
Assert.DoesNotContain(genericFileNotFoundError, result.Errors);
//Nupkg should push, and corresponding snupkg is a duplicate which is skipped.
Assert.True(result2.Success, "Expected to successfully push with SkipDuplicate option and a duplicate snupkg.");
Assert.Contains(MESSAGE_PACKAGE_PUSHED, result2.Output); //nupkg pushed
Assert.DoesNotContain(MESSAGE_RESPONSE_NO_SUCCESS, result2.AllOutput); //snupkg duplicate
Assert.Contains(MESSAGE_EXISTING_PACKAGE, result2.AllOutput);
Assert.DoesNotContain(genericFileNotFoundError, result2.Errors);
}
}
[Fact]
public void PushCommand_Server_Nupkg_ByWildcard_NupkgAndSnupkgPushed()
{
// Arrange
using (SimpleTestPathContext pathContext = new SimpleTestPathContext())
{
var nuget = Util.GetNuGetExePath();
string packageId = "packageWithSnupkg";
//Create a nupkg in test directory.
string version = "1.1.0";
Util.CreateTestPackage(packageId, version, pathContext.WorkingDirectory);
string nupkgFileName = Util.BuildPackageString(packageId, version, NuGetConstants.PackageExtension);
string snupkgFileName = Util.BuildPackageString(packageId, version, NuGetConstants.SnupkgExtension);
string snupkgFullPath = Path.Combine(pathContext.WorkingDirectory, snupkgFileName);
//Create snupkg in test directory.
WriteSnupkgFile(snupkgFullPath);
string wildcardPush = "*.nupkg";
var sourcePushUrl = string.Empty;
CommandRunnerResult result = null;
using (var server = CreateAndStartMockV3Server(pathContext.WorkingDirectory, out string sourceName))
{
sourcePushUrl = SetupMockServerAlwaysCreate(server);
pathContext.Settings.AddSource(sourceName, sourceName, "true");
// Act
//Since this is V3, this will trigger 2 pushes: one for nupkgs, and one for snupkgs.
result = CommandRunner.Run(
nuget,
pathContext.WorkingDirectory,
$"push {wildcardPush} -Source {sourceName} -Timeout 110",
timeOutInMilliseconds: 120000,
logLine: _testOutputHelper.WriteLine); // 120 seconds
}
// Assert
string genericFileNotFoundError = WITHOUT_FILENAME_MESSAGE_FILE_DOES_NOT_EXIST;
string pushingMessage = "Pushing {0} to '{1}'";
//Both should push, but to different servers
Assert.True(result.Success);
Assert.Contains(MESSAGE_PACKAGE_PUSHED, result.AllOutput); // files pushed
Assert.DoesNotContain(genericFileNotFoundError, result.Errors);
Assert.Contains(string.Format(pushingMessage, nupkgFileName, sourcePushUrl), result.AllOutput); //nupkg push to source
Assert.Contains(string.Format(pushingMessage, snupkgFileName, sourcePushUrl), result.AllOutput); //snupkg push to source
}
}
[Fact]
public void PushCommand_Server_Nupkg_ByWildcard_SeparateSymbolUrl_NupkgAndSnupkgPushedToDifferentSources()
{
// Arrange
using (SimpleTestPathContext pathContext = new SimpleTestPathContext())
{
var nuget = Util.GetNuGetExePath();
string packageId = "packageWithSnupkg";
//Create a nupkg in test directory.
string version = "1.1.0";
Util.CreateTestPackage(packageId, version, pathContext.WorkingDirectory);
string nupkgFileName = Util.BuildPackageString(packageId, version, NuGetConstants.PackageExtension);
string snupkgFileName = Util.BuildPackageString(packageId, version, NuGetConstants.SnupkgExtension);
string snupkgFullPath = Path.Combine(pathContext.WorkingDirectory, snupkgFileName);
//Create snupkg in test directory.
WriteSnupkgFile(snupkgFullPath);
string wildcardPush = "*.nupkg";
var sourcePushUrl = string.Empty;
var symbolPushUrl = string.Empty;
CommandRunnerResult result = null;
using (var server = CreateAndStartMockV3Server(pathContext.WorkingDirectory, out string sourceName))
using (var symbolServer = CreateAndStartMockV3Server(pathContext.WorkingDirectory, out string symbolSourceName))
{
sourcePushUrl = SetupMockServerAlwaysCreate(server);
symbolPushUrl = SetupMockServerAlwaysCreate(symbolServer);
pathContext.Settings.AddSource(sourceName, sourceName, "true");
pathContext.Settings.AddSource(symbolSourceName, symbolSourceName, "true");
// Act
//Since this is V3, this will trigger 2 pushes: one for nupkgs, and one for snupkgs.
result = CommandRunner.Run(
nuget,
pathContext.WorkingDirectory,
$"push {wildcardPush} -Source {sourceName} -SymbolSource {symbolSourceName} -Timeout 110",
timeOutInMilliseconds: 120000,
logLine: _testOutputHelper.WriteLine); // 120 seconds
}
// Assert
string genericFileNotFoundError = WITHOUT_FILENAME_MESSAGE_FILE_DOES_NOT_EXIST;
string pushingMessage = "Pushing {0} to '{1}'";
//Both should push, but to different servers
Assert.True(result.Success);
Assert.Contains(MESSAGE_PACKAGE_PUSHED, result.AllOutput); // files pushed
Assert.DoesNotContain(genericFileNotFoundError, result.Errors);
Assert.Contains(string.Format(pushingMessage, nupkgFileName, sourcePushUrl), result.AllOutput); //nupkg push to source
Assert.Contains(string.Format(pushingMessage, snupkgFileName, symbolPushUrl), result.AllOutput); //snupkg push to symbol source
}
}
[Fact]
public void PushCommand_Server_Nupkg_SeparateSymbolUrl_NoSymbolTrue_SnupkgNotPushed()
{
// Arrange
using (SimpleTestPathContext pathContext = new SimpleTestPathContext())
{
var nuget = Util.GetNuGetExePath();
string packageId = "packageWithSnupkg";
//Create a nupkg in test directory.
string version = "1.1.0";
Util.CreateTestPackage(packageId, version, pathContext.WorkingDirectory);
string nupkgFileName = Util.BuildPackageString(packageId, version, NuGetConstants.PackageExtension);
string snupkgFileName = Util.BuildPackageString(packageId, version, NuGetConstants.SnupkgExtension);
string snupkgFullPath = Path.Combine(pathContext.WorkingDirectory, snupkgFileName);
//Create snupkg in test directory.
WriteSnupkgFile(snupkgFullPath);
string wildcardPush = "*.nupkg";
var sourcePushUrl = string.Empty;
var symbolPushUrl = string.Empty;
CommandRunnerResult result = null;
using (var server = CreateAndStartMockV3Server(pathContext.WorkingDirectory, out string sourceName))
using (var symbolServer = CreateAndStartMockV3Server(pathContext.WorkingDirectory, out string symbolSourceName))
{
sourcePushUrl = SetupMockServerAlwaysCreate(server);
symbolPushUrl = SetupMockServerAlwaysCreate(symbolServer);
pathContext.Settings.AddSource(sourceName, sourceName, "true");
pathContext.Settings.AddSource(symbolSourceName, symbolSourceName, "true");
// Act
//Since this is V3, this will trigger 2 pushes: one for nupkgs, and one for snupkgs.
result = CommandRunner.Run(
nuget,
pathContext.WorkingDirectory,
$"push {wildcardPush} -Source {sourceName} -SymbolSource {symbolPushUrl} -noSymbol -Timeout 110",
timeOutInMilliseconds: 120000,
logLine: _testOutputHelper.WriteLine); // 120 seconds
}
// Assert
string genericFileNotFoundError = WITHOUT_FILENAME_MESSAGE_FILE_DOES_NOT_EXIST;
string pushingMessage = "Pushing {0} to '{1}'";
//Both should push, but to different servers
Assert.True(result.Success);
Assert.Contains(MESSAGE_PACKAGE_PUSHED, result.AllOutput); // files pushed
Assert.DoesNotContain(genericFileNotFoundError, result.Errors);
Assert.Contains(string.Format(pushingMessage, nupkgFileName, sourcePushUrl), result.AllOutput); //nupkg push to source
Assert.DoesNotContain(".snupkg", result.AllOutput); //snupkg not pushed
}
}
/// <summary>
/// When pushing *.Nupkg, (no skip duplicate) a 409 Conflict is returned and halts the secondary symbols push.
/// </summary>
[Fact]
public void PushCommand_Server_Nupkg_ByWildcard_FindsMatchingSnupkgs_Conflict()
{
// Arrange
using (SimpleTestPathContext pathContext = new SimpleTestPathContext())
{
var nuget = Util.GetNuGetExePath();
string packageId = "packageWithSnupkg";
//Create a nupkg in test directory.
string version = "1.1.0";
Util.CreateTestPackage(packageId, version, pathContext.WorkingDirectory);
string nupkgFileName = Util.BuildPackageString(packageId, version, NuGetConstants.PackageExtension);
string snupkgFileName = Util.BuildPackageString(packageId, version, NuGetConstants.SnupkgExtension);
string snupkgFullPath = Path.Combine(pathContext.WorkingDirectory, snupkgFileName);
//Create snupkg in test directory.
WriteSnupkgFile(snupkgFullPath);
string wildcardPush = "*.nupkg";
CommandRunnerResult result = null;
using (var server = CreateAndStartMockV3Server(pathContext.WorkingDirectory, out string sourceName))
{
//Configure push to return a Conflict for the first push, then Created for all remaining pushes.
SetupMockServerCreateNupkgDuplicateSnupkg(server, FuncStatus_Duplicate_ThenAlwaysCreated());
pathContext.Settings.AddSource(sourceName, sourceName, "true");
// Act
//Since this is V3, this will trigger 2 pushes: one for nupkgs, and one for snupkgs.
result = CommandRunner.Run(
nuget,
pathContext.WorkingDirectory,
$"push {wildcardPush} -Source {sourceName} -SymbolSource {sourceName} -Timeout 110",
timeOutInMilliseconds: 120000,
logLine: _testOutputHelper.WriteLine); // 120 seconds
}
// Assert
//Ignoring filename in File Not Found error since the error should not appear in any case.
string genericFileNotFoundError = WITHOUT_FILENAME_MESSAGE_FILE_DOES_NOT_EXIST;
//Nupkg should be a conflict, so its snupkg should also not push.
Assert.False(result.Success, "Expected to fail the push due to a duplicate nupkg.");
Assert.DoesNotContain(MESSAGE_PACKAGE_PUSHED, result.AllOutput); //nothing pushed
Assert.Contains(MESSAGE_RESPONSE_NO_SUCCESS, result.Errors); //nupkg duplicate
Assert.DoesNotContain(genericFileNotFoundError, result.Errors);
Assert.DoesNotContain(".snupkg", result.AllOutput); //snupkg not mentioned
}
}
/// <summary>
/// When pushing *.Nupkg with SkipDuplicate, a 409 Conflict is ignored and the corresponding symbols push is skipped.
/// </summary>
[Fact]
public void PushCommand_Server_Nupkg_ByWildcard_FindsMatchingSnupkgs_SkipDuplicate()
{
// Arrange
using (SimpleTestPathContext pathContext = new SimpleTestPathContext())
{
var nuget = Util.GetNuGetExePath();
string packageId = "packageWithSnupkg";
//Create a nupkg in test directory.
string version = "1.1.0";
Util.CreateTestPackage(packageId, version, pathContext.WorkingDirectory);
string nupkgFileName = Util.BuildPackageString(packageId, version, NuGetConstants.PackageExtension);
string snupkgFileName = Util.BuildPackageString(packageId, version, NuGetConstants.SnupkgExtension);
string snupkgFullPath = Path.Combine(pathContext.WorkingDirectory, snupkgFileName);
//Create snupkg in test directory.
WriteSnupkgFile(snupkgFullPath);
//Create another nupkg in test directory.
version = "2.12.1";
Util.CreateTestPackage(packageId, version, pathContext.WorkingDirectory);
string nupkgFileName2 = Util.BuildPackageString(packageId, version, NuGetConstants.PackageExtension);
string snupkgFileName2 = Util.BuildPackageString(packageId, version, NuGetConstants.SnupkgExtension);
string snupkgFullPath2 = Path.Combine(pathContext.WorkingDirectory, snupkgFileName2);
//Create another snupkg in test directory.
WriteSnupkgFile(snupkgFullPath2);
string wildcardPush = "*.nupkg";
CommandRunnerResult result = null;
using (var server = CreateAndStartMockV3Server(pathContext.WorkingDirectory, out string sourceName))
{
SetupMockServerAlwaysDuplicate(server);
pathContext.Settings.AddSource(sourceName, sourceName, "true");
// Act
//Since this is V3, this will trigger 2 pushes: one for nupkgs, and one for snupkgs.
result = CommandRunner.Run(
nuget,
pathContext.WorkingDirectory,
$"push {wildcardPush} -Source {sourceName} -Timeout 110 -SkipDuplicate",
timeOutInMilliseconds: 120000,
logLine: _testOutputHelper.WriteLine); // 120 seconds
}
// Assert
//Ignoring filename in File Not Found error since the error should not appear in any case.
string genericFileNotFoundError = WITHOUT_FILENAME_MESSAGE_FILE_DOES_NOT_EXIST;
//Nupkg should be an ignored conflict, so its snupkg shouldn't push.
Assert.True(result.Success, "Expected to skip pushing a snupkg with SkipDuplicate option when the nupkg is a duplicate.\n\n" + result.AllOutput);
Assert.DoesNotContain(MESSAGE_RESPONSE_NO_SUCCESS, result.Errors); //nupkg duplicate
Assert.Contains(MESSAGE_EXISTING_PACKAGE, result.AllOutput);
Assert.DoesNotContain(MESSAGE_PACKAGE_PUSHED, result.AllOutput); //nothing is pushed since nupkg/snupkgs are all skipped duplicates
Assert.DoesNotContain(genericFileNotFoundError, result.Errors);
Assert.DoesNotContain(snupkgFileName, result.AllOutput); //first snupkg is not attempted since nupkg was duplicate.
Assert.DoesNotContain(snupkgFileName2, result.AllOutput); //second snupkg is not attempted since nupkg was duplicate.
}
}
/// <summary>
/// When pushing *.Snupkg, (no skip duplicate) a 409 Conflict is returned and halts the remaining symbols push.
/// </summary>
[Fact]
public void PushCommand_Server_Snupkg_ByWildcard_FindsMatchingSnupkgs_Conflict()
{
// Arrange
using (SimpleTestPathContext pathContext = new SimpleTestPathContext())
{
var nuget = Util.GetNuGetExePath();
string packageId = "symbolsPackage";
//Create a nupkg in test directory.
string version = "1.1.0";
Util.CreateTestPackage(packageId, version, pathContext.WorkingDirectory);
string nupkgFileName = Util.BuildPackageString(packageId, version, NuGetConstants.PackageExtension);
string snupkgFileName = Util.BuildPackageString(packageId, version, NuGetConstants.SnupkgExtension);
string snupkgFullPath = Path.Combine(pathContext.WorkingDirectory, snupkgFileName);
//Create snupkg in test directory.
WriteSnupkgFile(snupkgFullPath);
string wildcardPush = "*.snupkg";
CommandRunnerResult result = null;
using (var server = CreateAndStartMockV3Server(pathContext.WorkingDirectory, out string sourceName))
{
//Configure push to return a Conflict for the first push, then Created for all remaining pushes.
SetupMockServerCreateNupkgDuplicateSnupkg(server, FuncStatus_Duplicate_ThenAlwaysCreated());
pathContext.Settings.AddSource(sourceName, sourceName, "true");
// Act
//Since this is V3, this will trigger 2 pushes: one for nupkgs, and one for snupkgs.
result = CommandRunner.Run(
nuget,
pathContext.WorkingDirectory,
$"push {wildcardPush} -Source {sourceName} -Timeout 110",
timeOutInMilliseconds: 120000,
logLine: _testOutputHelper.WriteLine); // 120 seconds
}
// Assert
//Ignoring filename in File Not Found error since the error should not appear in any case.
string genericFileNotFoundError = WITHOUT_FILENAME_MESSAGE_FILE_DOES_NOT_EXIST;
//Nupkg should be a conflict, so its snupkg should also not push.
Assert.False(result.Success, "Expected to fail the push due to a duplicate snupkg.");
Assert.DoesNotContain(MESSAGE_PACKAGE_PUSHED, result.Output); //nothing pushed
Assert.Contains(MESSAGE_RESPONSE_NO_SUCCESS, result.Errors); //nupkg duplicate
Assert.DoesNotContain(genericFileNotFoundError, result.Errors);
Assert.DoesNotContain(nupkgFileName, result.AllOutput); //nupkg not mentioned
}
}
/// <summary>
/// When pushing *.Snupkg with SkipDuplicate, a 409 Conflict is ignored and the remaining symbols push proceeds.
/// </summary>
[Fact]
public void PushCommand_Server_Snupkg_ByWildcard_FindsMatchingSnupkgs_SkipDuplicate()
{
// Arrange
using (SimpleTestPathContext pathContext = new SimpleTestPathContext())
{
var nuget = Util.GetNuGetExePath();
string packageId = "packageWithSnupkg";
//Create a nupkg in test directory.
string version = "1.1.0";
Util.CreateTestPackage(packageId, version, pathContext.WorkingDirectory);
string nupkgFileName = Util.BuildPackageString(packageId, version, NuGetConstants.PackageExtension);
string snupkgFileName = Util.BuildPackageString(packageId, version, NuGetConstants.SnupkgExtension);
string snupkgFullPath = Path.Combine(pathContext.WorkingDirectory, snupkgFileName);
//Create snupkg in test directory.
WriteSnupkgFile(snupkgFullPath);
//Create another nupkg in test directory.
version = "2.12.1";
Util.CreateTestPackage(packageId, version, pathContext.WorkingDirectory);
string nupkgFileName2 = Util.BuildPackageString(packageId, version, NuGetConstants.PackageExtension);
string snupkgFileName2 = Util.BuildPackageString(packageId, version, NuGetConstants.SnupkgExtension);
string snupkgFullPath2 = Path.Combine(pathContext.WorkingDirectory, snupkgFileName2);
//Create another snupkg in test directory.
WriteSnupkgFile(snupkgFullPath2);
string wildcardPush = "*.snupkg";
CommandRunnerResult result = null;
using (var server = CreateAndStartMockV3Server(pathContext.WorkingDirectory, out string sourceName))
{
SetupMockServerAlwaysDuplicate(server);
pathContext.Settings.AddSource(sourceName, sourceName, "true");
// Act
result = CommandRunner.Run(
nuget,
pathContext.WorkingDirectory,
$"push {wildcardPush} -Source {sourceName} -Timeout 110 -SkipDuplicate",
timeOutInMilliseconds: 120000,
logLine: _testOutputHelper.WriteLine); // 120 seconds
}
// Assert
//Ignoring filename in File Not Found error since the error should not appear in any case.
string genericFileNotFoundError = WITHOUT_FILENAME_MESSAGE_FILE_DOES_NOT_EXIST;
//Nupkg and Snupkg duplicates should be an ignored conflicts, so its all snupkg should be attempted.
Assert.True(result.Success, "Expected to successfully push all snupkgs with SkipDuplicate option when the snupkgs are duplicates.");
Assert.DoesNotContain(MESSAGE_RESPONSE_NO_SUCCESS, result.Errors); //snupkg duplicate is ignored
Assert.DoesNotContain(MESSAGE_PACKAGE_PUSHED, result.Output); //snupkgFileName and snupkgFileName2 are not pushed (just skipped conflicts)
Assert.Contains(MESSAGE_EXISTING_PACKAGE, result.AllOutput);
Assert.Contains(snupkgFileName, result.AllOutput); //first snupkg push is attempted
Assert.Contains(snupkgFileName2, result.AllOutput); //second snupkg push is attempted
Assert.DoesNotContain(genericFileNotFoundError, result.Errors);
Assert.DoesNotContain(nupkgFileName, result.AllOutput); //nupkgs should not be attempted in push
Assert.DoesNotContain(nupkgFileName2, result.AllOutput); //nupkgs should not be attempted in push
}
}
/// <summary>
/// When pushing a snupkg, a 409 Conflict is returned and any message from the server is shown appropriately.
/// </summary>
[Fact]
public void PushCommand_Server_Snupkg_ByFilename_SnupkgExists_Conflict_ServerMessage()
{
// Arrange
using (SimpleTestPathContext pathContext = new SimpleTestPathContext())
{
var nuget = Util.GetNuGetExePath();
string snupkgFileName = "fileName.snupkg";
string snupkgFullPath = Path.Combine(pathContext.WorkingDirectory, snupkgFileName);
//Create snupkg in test directory.
WriteSnupkgFile(snupkgFullPath);
CommandRunnerResult result = null;
CommandRunnerResult result2 = null;
using (var server = CreateAndStartMockV3Server(pathContext.WorkingDirectory, out string sourceName))
{
SetupMockServerAlwaysDuplicate(server);
pathContext.Settings.AddSource(sourceName, sourceName, "true");