@@ -1708,144 +1708,74 @@ await CliTester.Run(new RunConfiguration[]
1708
1708
}
1709
1709
1710
1710
[ Theory ]
1711
- [ InlineData ( "dotnet-isolated" ) ]
1712
- [ InlineData ( "node" ) ]
1713
- public async Task Start_MissingLocalSettingsJson_SuccessfulFunctionExecution ( string language )
1711
+ [ InlineData ( "dotnet-isolated" , "--dotnet-isolated" , "HttpTriggerFunc: [GET,POST] http://localhost:" , true , false ) ] // Runtime parameter set (dni), successful startup & invocation
1712
+ [ InlineData ( "node" , "--node" , "HttpTriggerFunc: [GET,POST] http://localhost:" , true , false ) ] // Runtime parameter set (node), successful startup & invocation
1713
+ [ InlineData ( "dotnet" , "--worker-runtime None" , $ "Use the up/down arrow keys to select a worker runtime:", false , false ) ] // Runtime parameter set to None, worker runtime prompt displayed
1714
+ [ InlineData ( "dotnet" , "" , $ "Use the up/down arrow keys to select a worker runtime:", false , false ) ] // Runtime parameter not provided, worker runtime prompt displayed
1715
+ [ InlineData ( "dotnet-isolated" , "" , "HttpTriggerFunc: [GET,POST] http://localhost:" , true , true ) ] // Runtime value is set via environment variable, successful startup & invocation
1716
+ public async Task Start_MissingLocalSettingsJson_BehavesAsExpected ( string language , string runtimeParameter , string expectedOutput , bool invokeFunction , bool setRuntimeViaEnvironment )
1714
1717
{
1715
- await CliTester . Run ( new RunConfiguration [ ]
1718
+ try
1716
1719
{
1717
- new RunConfiguration
1720
+ if ( setRuntimeViaEnvironment )
1718
1721
{
1719
- Commands = new [ ]
1720
- {
1721
- $ "init . --worker-runtime { language } ",
1722
- $ "new --template Httptrigger --name HttpTriggerFunc",
1723
- } ,
1724
- CommandTimeout = TimeSpan . FromSeconds ( 300 ) ,
1725
- } ,
1726
- new RunConfiguration
1722
+ Environment . SetEnvironmentVariable ( "FUNCTIONS_WORKER_RUNTIME" , "dotnet-isolated" ) ;
1723
+ }
1724
+
1725
+ await CliTester . Run ( new RunConfiguration [ ]
1727
1726
{
1728
- PreTest = ( workingDir ) =>
1727
+ new RunConfiguration
1729
1728
{
1730
- var LocalSettingsJson = Path . Combine ( workingDir , "local.settings.json" ) ;
1731
- File . Delete ( LocalSettingsJson ) ;
1732
- } ,
1733
- Commands = new [ ]
1734
- {
1735
- $ "start --{ language } --port { _funcHostPort } ",
1736
- } ,
1737
- ExpectExit = false ,
1738
- OutputContains = new [ ]
1739
- {
1740
- $ "local.settings.json",
1741
- "Functions:" ,
1742
- $ "HttpTriggerFunc: [GET,POST] http://localhost:{ _funcHostPort } /api/HttpTriggerFunc"
1743
- } ,
1744
- OutputDoesntContain = new string [ ]
1745
- {
1746
- "Initializing function HTTP routes"
1729
+ Commands = new [ ]
1730
+ {
1731
+ $ "init . --worker-runtime { language } ",
1732
+ $ "new --template Httptrigger --name HttpTriggerFunc",
1733
+ } ,
1734
+ CommandTimeout = TimeSpan . FromSeconds ( 300 ) ,
1747
1735
} ,
1748
- Test = async ( _ , p , _ ) =>
1736
+ new RunConfiguration
1749
1737
{
1750
- using ( var client = new HttpClient ( ) { BaseAddress = new Uri ( $ "http://localhost: { _funcHostPort } /" ) } )
1738
+ PreTest = ( workingDir ) =>
1751
1739
{
1752
- ( await WaitUntilReady ( client ) ) . Should ( ) . BeTrue ( because : _serverNotReady ) ;
1753
- var response = await client . GetAsync ( "/api/HttpTriggerFunc?name=Test" ) ;
1754
- response . StatusCode . Should ( ) . Be ( HttpStatusCode . OK ) ;
1755
- await Task . Delay ( TimeSpan . FromSeconds ( 2 ) ) ;
1756
- p . Kill ( ) ;
1740
+ var localSettingsJson = Path . Combine ( workingDir , "local.settings.json" ) ;
1741
+ File . Delete ( localSettingsJson ) ;
1742
+ } ,
1743
+ Commands = new [ ]
1744
+ {
1745
+ $ "start { runtimeParameter } --port { _funcHostPort } ",
1746
+ } ,
1747
+ ExpectExit = false ,
1748
+ OutputContains = new [ ]
1749
+ {
1750
+ expectedOutput
1751
+ } ,
1752
+ Test = async ( _ , p , _ ) =>
1753
+ {
1754
+ if ( invokeFunction )
1755
+ {
1756
+ using ( var client = new HttpClient ( ) { BaseAddress = new Uri ( $ "http://localhost:{ _funcHostPort } /") } )
1757
+ {
1758
+ ( await WaitUntilReady ( client ) ) . Should ( ) . BeTrue ( because : _serverNotReady ) ;
1759
+ var response = await client . GetAsync ( "/api/HttpTriggerFunc?name=Test" ) ;
1760
+ response . StatusCode . Should ( ) . Be ( HttpStatusCode . OK ) ;
1761
+ await Task . Delay ( TimeSpan . FromSeconds ( 2 ) ) ;
1762
+ p . Kill ( ) ;
1763
+ }
1764
+ }
1765
+ else
1766
+ {
1767
+ await Task . Delay ( TimeSpan . FromSeconds ( 2 ) ) ;
1768
+ p . Kill ( ) ;
1769
+ }
1770
+
1757
1771
}
1758
1772
}
1759
- }
1760
- } , _output ) ;
1761
- }
1762
-
1763
- [ Fact ]
1764
- public async Task Start_MissingLocalSettingsJson_Runtime_None_HandledAsExpected ( )
1765
- {
1766
- await CliTester . Run ( new RunConfiguration [ ]
1767
- {
1768
- new RunConfiguration
1769
- {
1770
- Commands = new [ ]
1771
- {
1772
- $ "init . --worker-runtime dotnet",
1773
- $ "new --template Httptrigger --name HttpTriggerFunc",
1774
- } ,
1775
- CommandTimeout = TimeSpan . FromSeconds ( 300 ) ,
1776
- } ,
1777
- new RunConfiguration
1778
- {
1779
- PreTest = ( workingDir ) =>
1780
- {
1781
- var LocalSettingsJson = Path . Combine ( workingDir , "local.settings.json" ) ;
1782
- File . Delete ( LocalSettingsJson ) ;
1783
- } ,
1784
- Commands = new [ ]
1785
- {
1786
- $ "start --worker-runtime None --port { _funcHostPort } ",
1787
- } ,
1788
- ExpectExit = false ,
1789
- OutputContains = new [ ]
1790
- {
1791
- $ "Use the up/down arrow keys to select a worker runtime:"
1792
- } ,
1793
- OutputDoesntContain = new string [ ]
1794
- {
1795
- "Initializing function HTTP routes"
1796
- } ,
1797
- Test = async ( _ , p , _ ) =>
1798
- {
1799
- await Task . Delay ( TimeSpan . FromSeconds ( 2 ) ) ;
1800
- p . Kill ( ) ;
1801
- }
1802
- }
1803
- } , _output ) ;
1804
-
1805
- }
1806
-
1807
- [ Fact ]
1808
- public async Task Start_MissingLocalSettingsJson_Runtime_NotProvided_HandledAsExpected ( )
1809
- {
1810
- await CliTester . Run ( new RunConfiguration [ ]
1773
+ } , _output ) ;
1774
+ }
1775
+ finally
1811
1776
{
1812
- new RunConfiguration
1813
- {
1814
- Commands = new [ ]
1815
- {
1816
- $ "init . --worker-runtime dotnet",
1817
- $ "new --template Httptrigger --name HttpTriggerFunc",
1818
- } ,
1819
- CommandTimeout = TimeSpan . FromSeconds ( 300 ) ,
1820
- } ,
1821
- new RunConfiguration
1822
- {
1823
- PreTest = ( workingDir ) =>
1824
- {
1825
- var LocalSettingsJson = Path . Combine ( workingDir , "local.settings.json" ) ;
1826
- File . Delete ( LocalSettingsJson ) ;
1827
- } ,
1828
- Commands = new [ ]
1829
- {
1830
- $ "start --port { _funcHostPort } ",
1831
- } ,
1832
- ExpectExit = false ,
1833
- OutputContains = new [ ]
1834
- {
1835
- $ "Use the up/down arrow keys to select a worker runtime:"
1836
- } ,
1837
- OutputDoesntContain = new string [ ]
1838
- {
1839
- "Initializing function HTTP routes"
1840
- } ,
1841
- Test = async ( _ , p , _ ) =>
1842
- {
1843
- await Task . Delay ( TimeSpan . FromSeconds ( 2 ) ) ;
1844
- p . Kill ( ) ;
1845
- }
1846
- }
1847
- } , _output ) ;
1848
-
1777
+ Environment . SetEnvironmentVariable ( "FUNCTIONS_WORKER_RUNTIME" , null ) ;
1778
+ }
1849
1779
}
1850
1780
1851
1781
private async Task < bool > WaitUntilReady ( HttpClient client )
0 commit comments