-
Notifications
You must be signed in to change notification settings - Fork 447
/
Copy pathInitTests.cs
926 lines (881 loc) · 32.7 KB
/
InitTests.cs
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
using System;
using System.Collections.Generic;
using System.IO;
using System.Threading.Tasks;
using Azure.Functions.Cli.Common;
using Azure.Functions.Cli.Helpers;
using Azure.Functions.Cli.Tests.E2E.Helpers;
using Xunit;
using Xunit.Abstractions;
namespace Azure.Functions.Cli.Tests.E2E
{
public class InitTests : BaseE2ETest
{
public InitTests(ITestOutputHelper output) : base(output) { }
[Theory]
[InlineData("node")]
[InlineData("java")]
[InlineData("python")]
public Task init_with_worker_runtime(string workerRuntime)
{
var files = new List<FileResult>
{
new FileResult
{
Name = "local.settings.json",
ContentContains = new []
{
"FUNCTIONS_WORKER_RUNTIME",
workerRuntime
}
},
};
if (workerRuntime == "powershell")
{
files.Add(new FileResult
{
Name = "profile.ps1",
ContentContains = new[] { "# Azure Functions profile.ps1" }
});
}
return CliTester.Run(new RunConfiguration
{
Commands = new[] { $"init . --worker-runtime {workerRuntime} --skip-npm-install" },
CheckFiles = files.ToArray(),
OutputContains = new[]
{
"Writing .gitignore",
"Writing host.json",
"Writing local.settings.json",
$".vscode{Path.DirectorySeparatorChar}extensions.json",
},
OutputDoesntContain = new[] { "Initialized empty Git repository" },
CommandTimeout = TimeSpan.FromSeconds(60)
}, _output);
}
[Theory]
[InlineData("dotnet")]
[InlineData("dotnet-isolated")]
[InlineData("powershell")]
public Task init_with_only_runtime_option(string workerRuntime)
{
var files = new List<FileResult>
{
new FileResult
{
Name = "local.settings.json",
ContentContains = new []
{
"FUNCTIONS_WORKER_RUNTIME",
workerRuntime
}
},
};
if (workerRuntime == "powershell")
{
files.Add(new FileResult
{
Name = "profile.ps1",
ContentContains = new[] { "# Azure Functions profile.ps1" }
});
}
return CliTester.Run(new RunConfiguration
{
Commands = new[] { $"init --{workerRuntime}" },
CheckFiles = files.ToArray(),
OutputContains = new[]
{
$".vscode{Path.DirectorySeparatorChar}extensions.json",
},
OutputDoesntContain = new[] { "Initialized empty Git repository" }
}, _output);
}
[Theory]
[InlineData("node", "v3")]
[InlineData("node", "v4")]
[InlineData("node", "")]
[InlineData("java", "v1")]
[InlineData("python", "v1")]
[InlineData("python", "v2")]
[InlineData("python", "")]
public Task init_with_worker_runtime_and_model(string workerRuntime, string programmingModel)
{
var files = new List<FileResult>
{
new FileResult
{
Name = "local.settings.json",
ContentContains = new []
{
"FUNCTIONS_WORKER_RUNTIME",
workerRuntime
}
}
};
if (workerRuntime == "python" && (programmingModel == "v2" || programmingModel == string.Empty))
{
files.Add(new FileResult
{
Name = "function_app.py",
});
}
else if (workerRuntime == "node" && (programmingModel == "v4" || programmingModel == string.Empty))
{
files.Add(new FileResult
{
Name = "package.json",
ContentContains = new[]
{
"\"@azure/functions\": \"^4"
}
});
}
var programmingModelFlag = programmingModel == string.Empty ? string.Empty : $"--model {programmingModel}";
return CliTester.Run(new RunConfiguration
{
Commands = new[] { $"init . --worker-runtime {workerRuntime} {programmingModelFlag}" },
CheckFiles = files.ToArray(),
OutputContains = new[]
{
"Writing .gitignore",
"Writing host.json",
"Writing local.settings.json",
$".vscode{Path.DirectorySeparatorChar}extensions.json",
},
OutputDoesntContain = new[] { "Initialized empty Git repository" },
CommandTimeout = TimeSpan.FromSeconds(300)
}, _output);
}
[Theory]
[InlineData("node", "v1")]
[InlineData("node", "v2")]
[InlineData("java", "v2")]
[InlineData("python", "v3")]
public Task init_with_worker_runtime_and_unsupported_model(string workerRuntime, string programmingModel)
{
return CliTester.Run(new RunConfiguration
{
Commands = new[] { $"init . --worker-runtime {workerRuntime} --model {programmingModel}" },
HasStandardError = true,
ErrorContains = new[]
{
$"programming model is not supported for worker runtime {workerRuntime}. Supported programming models for worker runtime {workerRuntime} are:"
}
}, _output);
}
[Fact]
public Task init_dotnet_app()
{
return CliTester.Run(new RunConfiguration
{
Commands = new[] { "init dotnet-funcs --worker-runtime dotnet" },
CheckFiles = new[]
{
new FileResult
{
Name = Path.Combine("dotnet-funcs", "local.settings.json"),
ContentContains = new[]
{
"FUNCTIONS_WORKER_RUNTIME",
"dotnet"
}
},
new FileResult
{
Name = Path.Combine("dotnet-funcs", "dotnet-funcs.csproj"),
ContentContains = new[]
{
"Microsoft.NET.Sdk.Functions",
"v4"
}
}
}
}, _output);
}
[Fact]
public Task init_dotnet_app_net9_isolated()
{
return CliTester.Run(new RunConfiguration
{
Commands = new[] { "init dotnet-funcs --worker-runtime dotnet-isolated --target-framework net9.0" },
CheckFiles = new[]
{
new FileResult
{
Name = Path.Combine("dotnet-funcs", "local.settings.json"),
ContentContains = new[]
{
"FUNCTIONS_WORKER_RUNTIME",
"dotnet-isolated",
}
},
new FileResult
{
Name = Path.Combine("dotnet-funcs", "dotnet-funcs.csproj"),
ContentContains = new[]
{
"Microsoft.NET.Sdk",
"v4",
"net9.0",
}
}
}
}, _output);
}
[Fact]
public Task init_dotnet_app_net8()
{
return CliTester.Run(new RunConfiguration
{
Commands = new[] { "init dotnet-funcs --worker-runtime dotnet --target-framework net8.0" },
CheckFiles = new[]
{
new FileResult
{
Name = Path.Combine("dotnet-funcs", "local.settings.json"),
ContentContains = new[]
{
"FUNCTIONS_WORKER_RUNTIME",
"dotnet",
"FUNCTIONS_INPROC_NET8_ENABLED",
}
},
new FileResult
{
Name = Path.Combine("dotnet-funcs", "dotnet-funcs.csproj"),
ContentContains = new[]
{
"Microsoft.NET.Sdk.Functions",
"v4"
}
}
}
}, _output);
}
[Fact]
public Task init_with_unknown_worker_runtime()
{
const string unknownWorkerRuntime = "foo";
return CliTester.Run(new RunConfiguration
{
Commands = new[] { $"init . --worker-runtime {unknownWorkerRuntime}" },
HasStandardError = true,
ErrorContains = new[]
{
$"Worker runtime '{unknownWorkerRuntime}' is not a valid option."
}
}, _output);
}
[Fact]
public Task init_with_unsupported_target_framework_for_dotnet()
{
const string unsupportedTargetFramework = "net7.0";
return CliTester.Run(new RunConfiguration
{
Commands = new[] { $"init . --worker-runtime dotnet --target-framework {unsupportedTargetFramework}" },
HasStandardError = true,
ErrorContains = new[]
{
$"Unable to parse target framework {unsupportedTargetFramework} for worker runtime dotnet. Valid options are net8.0, net6.0"
}
}, _output);
}
[Fact]
public Task init_with_no_source_control()
{
return CliTester.Run(new RunConfiguration
{
Commands = new[] { "init . --worker-runtime node" },
CheckDirectories = new[]
{
new DirectoryResult { Name = ".git", Exists = false }
},
CommandTimeout = TimeSpan.FromSeconds(300)
}, _output);
}
[Theory]
[InlineData("dotnet", "4")]
[InlineData("node", "4")]
[InlineData("powershell", "4")]
public Task init_with_Dockerfile(string workerRuntime, string version)
{
return CliTester.Run(new RunConfiguration
{
Commands = new[] { $"init . --worker-runtime {workerRuntime} --docker" },
CheckFiles = new[]
{
new FileResult
{
Name = "Dockerfile",
ContentContains = new[] { $"FROM mcr.microsoft.com/azure-functions/{workerRuntime}:{version}" }
}
},
CommandTimeout = TimeSpan.FromSeconds(300),
OutputContains = new[] { "Dockerfile" }
}, _output);
}
[SkippableFact]
public async Task init_with_python_Dockerfile()
{
WorkerLanguageVersionInfo worker = await PythonHelpers.GetEnvironmentPythonVersion();
Skip.If(worker == null);
await CliTester.Run(new RunConfiguration
{
Commands = new[] { $"init . --worker-runtime python --docker" },
CheckFiles = new[]
{
new FileResult
{
Name = "Dockerfile",
ContentContains = new[] { $"FROM mcr.microsoft.com/azure-functions/python:4-python{worker.Major}.{worker.Minor}" }
}
},
OutputContains = new[] { "Dockerfile" }
}, _output);
}
[Fact]
public Task init_with_dotnet8InProcess_dockerfile()
{
return CliTester.Run(new RunConfiguration
{
Commands = new[] { $"init . --worker-runtime dotnet --target-framework net8.0 --docker" },
CheckFiles = new[]
{
new FileResult
{
Name = "Dockerfile",
ContentContains = new[] { $"FROM mcr.microsoft.com/azure-functions/dotnet:4-dotnet8" }
}
},
OutputContains = new[] { "Dockerfile" }
}, _output);
}
[Fact]
public Task init_with_dotnetIsolated_dockerfile()
{
return CliTester.Run(new RunConfiguration
{
Commands = new[] { $"init . --worker-runtime dotnet-isolated --docker" },
CheckFiles = new[]
{
new FileResult
{
Name = "Dockerfile",
ContentContains = new[] { $"FROM mcr.microsoft.com/azure-functions/dotnet-isolated:4-dotnet-isolated8.0" }
}
},
OutputContains = new[] { "Dockerfile" }
}, _output);
}
[Fact(Skip = "Disabling oop test from in-proc branch for now. Need to revisit to determine these can be removed from this branch")]
public Task init_with_dotnet7Isolated_dockerfile()
{
return CliTester.Run(new RunConfiguration
{
Commands = new[] { $"init . --worker-runtime dotnet-isolated --target-framework net7.0 --docker" },
CheckFiles = new[]
{
new FileResult
{
Name = "Dockerfile",
ContentContains = new[] { $"FROM mcr.microsoft.com/azure-functions/dotnet-isolated:4-dotnet-isolated7.0" }
}
},
OutputContains = new[] { "Dockerfile" }
}, _output);
}
[Fact]
public Task init_with_dotnet9Isolated_dockerfile()
{
return CliTester.Run(new RunConfiguration
{
Commands = new[] { $"init . --worker-runtime dotnet-isolated --target-framework net9.0 --docker" },
CheckFiles = new[]
{
new FileResult
{
Name = "Dockerfile",
ContentContains = new[] { $"FROM mcr.microsoft.com/azure-functions/dotnet-isolated:4-dotnet-isolated9.0" }
}
},
OutputContains = new[] { "Dockerfile" }
}, _output);
}
[Fact]
public Task init_with_Dockerfile_for_csx()
{
return CliTester.Run(new RunConfiguration
{
Commands = new[] { $"init . --worker-runtime dotnet --docker --csx" },
CheckFiles = new[]
{
new FileResult
{
Name = "Dockerfile",
ContentNotContains = new[] { "dotnet publish" },
ContentContains = new[] { $"FROM mcr.microsoft.com/azure-functions/dotnet:4" }
}
},
OutputContains = new[] { "Dockerfile" }
}, _output);
}
[Fact]
public Task init_csx_app()
{
return CliTester.Run(new RunConfiguration
{
Commands = new[] { "init . --worker-runtime dotnet --csx" },
CheckFiles = new FileResult[]
{
new FileResult
{
Name = "local.settings.json",
ContentContains = new []
{
"FUNCTIONS_WORKER_RUNTIME",
"dotnet"
}
}
},
OutputContains = new[]
{
"Writing .gitignore",
"Writing host.json",
"Writing local.settings.json",
$".vscode{Path.DirectorySeparatorChar}extensions.json",
}
}, _output);
}
[Fact]
public Task init_app_with_spaces()
{
return CliTester.Run(new RunConfiguration
{
Commands = new[]
{
"init \"functions project\" --worker-runtime dotnet",
"new --prefix \"functions project\" --template BlobTrigger --name testfunc"
},
CommandTimeout = new TimeSpan(0, 1, 0)
});
}
[Theory]
[InlineData("--worker-runtime node --language typescript")]
[InlineData("--typescript")]
public Task init_ts_app_using_lang(string initCommand)
{
return CliTester.Run(new RunConfiguration
{
Commands = new[] { $"init . {initCommand} --docker" },
CheckFiles = new FileResult[]
{
new FileResult
{
Name = "local.settings.json",
ContentContains = new []
{
"FUNCTIONS_WORKER_RUNTIME",
"node"
}
},
new FileResult
{
Name = "Dockerfile",
ContentContains = new []
{
"mcr.microsoft.com/azure-functions/node:4",
"npm run build"
}
}
},
OutputContains = new[]
{
"Writing tsconfig.json",
"Writing .funcignore",
"Writing package.json",
"Writing .gitignore",
"Writing host.json",
"Writing local.settings.json",
$".vscode{Path.DirectorySeparatorChar}extensions.json",
"Writing Dockerfile",
"Writing .dockerignore"
},
CommandTimeout = TimeSpan.FromSeconds(300)
}, _output);
}
[Fact]
public Task javascript_adds_packagejson()
{
return CliTester.Run(new RunConfiguration
{
Commands = new[] { "init . --worker-runtime node" },
CheckFiles = new FileResult[]
{
new FileResult
{
Name = "local.settings.json",
ContentContains = new []
{
"FUNCTIONS_WORKER_RUNTIME",
"node"
}
}
},
OutputContains = new[]
{
"Writing package.json",
"Writing .gitignore",
"Writing host.json",
"Writing local.settings.json",
$".vscode{Path.DirectorySeparatorChar}extensions.json",
},
CommandTimeout = TimeSpan.FromSeconds(300)
}, _output);
}
[Fact]
public Task init_ts_app_using_runtime()
{
return CliTester.Run(new RunConfiguration
{
Commands = new[] { "init . --worker-runtime typescript" },
OutputContains = new[]
{
"Writing tsconfig.json",
"Writing .funcignore",
"Writing package.json",
"Writing .gitignore",
"Writing host.json",
"Writing local.settings.json",
$".vscode{Path.DirectorySeparatorChar}extensions.json",
},
CommandTimeout = TimeSpan.FromSeconds(240)
}, _output);
}
[Fact]
public Task ini_ts_app_v4_with_skip_npm_install()
{
return CliTester.Run(new RunConfiguration
{
Commands = new[] { "init . --worker-runtime node --language typescript --model V4 --skip-npm-install" },
CheckDirectories = new DirectoryResult[]
{
new DirectoryResult
{
Name = "node_modules",
Exists = false
}
},
OutputContains = new[]
{
"You skipped \"npm install\". You must run \"npm install\" manually"
},
OutputDoesntContain = new[]
{
"Running 'npm install'..."
}
}, _output);
}
[Theory]
[InlineData("dotnet", "4")]
[InlineData("node", "4")]
[InlineData("powershell", "4")]
public Task init_docker_only_for_existing_project(string workerRuntime, string version)
{
return CliTester.Run(new RunConfiguration
{
Commands = new[]
{
$"init . --worker-runtime {workerRuntime}",
$"init . --docker-only",
},
CheckFiles = new[]
{
new FileResult
{
Name = "Dockerfile",
ContentContains = new[] { $"FROM mcr.microsoft.com/azure-functions/{workerRuntime}:{version}" }
}
},
OutputContains = new[] { "Dockerfile" },
CommandTimeout = TimeSpan.FromSeconds(300)
}, _output);
}
[Fact]
public Task init_docker_only_for_csx_project()
{
return CliTester.Run(new RunConfiguration
{
Commands = new[]
{
$"init . --worker-runtime dotnet --csx",
$"init . --docker-only --csx",
},
CheckFiles = new[]
{
new FileResult
{
Name = "Dockerfile",
ContentNotContains = new[] { "dotnet publish" },
ContentContains = new[] { $"FROM mcr.microsoft.com/azure-functions/dotnet:4" }
}
},
OutputContains = new[] { "Dockerfile" }
}, _output);
}
[Fact]
public Task init_docker_only_no_project()
{
return CliTester.Run(new RunConfiguration
{
Commands = new[]
{
$"init . --docker-only"
},
HasStandardError = true,
ErrorContains = new[]
{
$"Can't determine project language from files."
}
}, _output);
}
[Fact]
public Task init_function_app_powershell_enable_managed_dependencies_and_set_default_version()
{
return CliTester.Run(new RunConfiguration
{
Commands = new[] { "init . --worker-runtime powershell --managed-dependencies" },
CheckFiles = new FileResult[]
{
new FileResult
{
Name = "host.json",
ContentContains = new []
{
"logging",
"applicationInsights",
"extensionBundle",
"managedDependency",
"enabled",
"true"
}
},
new FileResult
{
Name = "requirements.psd1",
ContentContains = new []
{
"For latest supported version, go to 'https://www.powershellgallery.com/packages/Az'.",
"To use the Az module in your function app, please uncomment the line below.",
"Az",
}
},
new FileResult
{
Name = "profile.ps1",
ContentContains = new []
{
"env:MSI_SECRET",
"Disable-AzContextAutosave -Scope Process | Out-Null",
"Connect-AzAccount -Identity"
}
},
new FileResult
{
Name = "local.settings.json",
ContentContains = new []
{
"FUNCTIONS_WORKER_RUNTIME",
"powershell",
"FUNCTIONS_WORKER_RUNTIME_VERSION",
"7.4"
}
}
},
OutputContains = new[]
{
"Writing profile.ps1",
"Writing requirements.psd1",
"Writing .gitignore",
"Writing host.json",
"Writing local.settings.json",
$".vscode{Path.DirectorySeparatorChar}extensions.json",
}
}, _output);
}
[Fact]
public Task init_function_app_contains_logging_config()
{
return CliTester.Run(new RunConfiguration
{
Commands = new[] { "init . --worker-runtime node" },
CheckFiles = new FileResult[]
{
new FileResult
{
Name = "host.json",
ContentContains = new []
{
"applicationInsights",
"excludedTypes",
"Request",
"logging"
}
}
},
OutputContains = new[]
{
"Writing host.json"
},
CommandTimeout = TimeSpan.FromSeconds(300)
}, _output);
}
[Fact]
public Task init_managed_dependencies_is_only_supported_in_powershell()
{
return CliTester.Run(new RunConfiguration
{
Commands = new[]
{
$"init . --worker-runtime python --managed-dependencies "
},
HasStandardError = true,
ErrorContains = new[]
{
$"Managed dependencies is only supported for PowerShell"
}
}, _output);
}
[Fact]
public Task init_python_app_twice()
{
return CliTester.Run(new RunConfiguration
{
Commands = new[]
{
"init \"anapp\" --worker-runtime python -m v1",
"init \"anapp\" --worker-runtime python -m v1"
},
OutputContains = new[]
{
"Writing .gitignore",
"Writing host.json",
"Writing local.settings.json",
"Writing getting_started.md",
$".vscode{Path.DirectorySeparatorChar}extensions.json",
"requirements.txt already exists. Skipped!",
".gitignore already exists. Skipped!",
"host.json already exists. Skipped!",
"getting_started.md already exists. Skipped!",
"local.settings.json already exists. Skipped!",
$".vscode{Path.DirectorySeparatorChar}extensions.json already exists. Skipped!"
}
}, _output);
}
[Fact]
public Task init_python_app_twice_new_programming_model()
{
return CliTester.Run(new RunConfiguration
{
Commands = new[]
{
"init \"anapp\" --worker-runtime python",
"init \"anapp\" --worker-runtime python"
},
OutputContains = new[]
{
"Writing .gitignore",
"Writing host.json",
"Writing local.settings.json",
$".vscode{Path.DirectorySeparatorChar}extensions.json",
"requirements.txt already exists. Skipped!",
".gitignore already exists. Skipped!",
"host.json already exists. Skipped!",
"local.settings.json already exists. Skipped!",
$".vscode{Path.DirectorySeparatorChar}extensions.json already exists. Skipped!"
}
}, _output);
}
[Theory]
[InlineData("-m V1")]
[InlineData("-m V2")]
[InlineData("")]
public Task init_python_app_generates_requirements_txt(string modelParameter)
{
return CliTester.Run(new RunConfiguration
{
Commands = new[]
{
$"init . --worker-runtime python {modelParameter}"
},
OutputContains = new[]
{
"Writing requirements.txt"
},
CheckFiles = new FileResult[]
{
new FileResult
{
Name = "requirements.txt",
ContentContains = new []
{
"# Do not include azure-functions-worker",
"azure-functions"
}
}
},
}, _output);
}
[Fact]
public Task init_python_app_generates_getting_started_md()
{
return CliTester.Run(new RunConfiguration
{
Commands = new[]
{
"init . --worker-runtime python -m V1"
},
OutputContains = new[]
{
"Writing getting_started.md"
},
CheckFiles = new FileResult[]
{
new FileResult
{
Name = "getting_started.md",
ContentContains = new []
{
"## Getting Started with Azure Function"
}
}
},
}, _output);
}
[Theory]
[InlineData("dotnet-isolated","4", "net6.0")]
[InlineData("dotnet-isolated", "4", "net7.0")]
[InlineData("dotnet-isolated","4", "net8.0")]
public Task init_docker_only_for_existing_project_TargetFramework(string workerRuntime, string version, string TargetFramework)
{
var TargetFrameworkstr = TargetFramework.Replace("net", string.Empty);
return CliTester.Run(new RunConfiguration
{
Commands = new[]
{
$"init . --worker-runtime {workerRuntime} --target-framework {TargetFramework}",
$"init . --docker-only",
},
CheckFiles = new[]
{
new FileResult
{
Name = "Dockerfile",
ContentContains = new[] { $"FROM mcr.microsoft.com/azure-functions/{workerRuntime}:{version}-{workerRuntime}{TargetFrameworkstr}" }
}
},
OutputContains = new[] { "Dockerfile" },
CommandTimeout = TimeSpan.FromSeconds(300)
}, _output);
}
}
}