55using System . Collections . ObjectModel ;
66using System . IO ;
77using System . Net ;
8+ using System . Threading ;
89using System . Threading . Tasks ;
910using FluentAssertions ;
1011using Microsoft . AspNetCore . Http ;
1314using Microsoft . Azure . WebJobs . Host . Executors ;
1415using Microsoft . Azure . WebJobs . Host . Scale ;
1516using Microsoft . Azure . WebJobs . Script . ExtensionBundle ;
17+ using Microsoft . Azure . WebJobs . Script . Models ;
1618using Microsoft . Azure . WebJobs . Script . Scale ;
1719using Microsoft . Azure . WebJobs . Script . WebHost . Controllers ;
1820using Microsoft . Azure . WebJobs . Script . WebHost . Management ;
@@ -36,13 +38,15 @@ public class HostControllerTests
3638 private readonly Mock < IExtensionBundleManager > _extensionBundleManager ;
3739 private readonly Mock < HostPerformanceManager > _mockHostPerformanceManager ;
3840 private readonly HostHealthMonitorOptions _hostHealthMonitorOptions ;
41+ private readonly ScriptApplicationHostOptions _applicationHostOptions ;
3942
4043 public HostControllerTests ( )
4144 {
4245 _scriptPath = Path . GetTempPath ( ) ;
43- var applicationHostOptions = new ScriptApplicationHostOptions ( ) ;
44- applicationHostOptions . ScriptPath = _scriptPath ;
45- var optionsWrapper = new OptionsWrapper < ScriptApplicationHostOptions > ( applicationHostOptions ) ;
46+ _applicationHostOptions = new ScriptApplicationHostOptions ( ) ;
47+ _applicationHostOptions . ScriptPath = _scriptPath ;
48+ var optionsWrapper = new OptionsWrapper < ScriptApplicationHostOptions > ( _applicationHostOptions ) ;
49+
4650 var loggerProvider = new TestLoggerProvider ( ) ;
4751 var loggerFactory = new LoggerFactory ( ) ;
4852 loggerFactory . AddProvider ( loggerProvider ) ;
@@ -66,6 +70,37 @@ public HostControllerTests()
6670 }
6771 }
6872
73+ [ Theory ]
74+ [ InlineData ( false , false , FunctionAppContentEditingState . NotAllowed ) ]
75+ [ InlineData ( false , true , FunctionAppContentEditingState . Allowed ) ]
76+ [ InlineData ( true , true , FunctionAppContentEditingState . NotAllowed ) ]
77+ [ InlineData ( true , false , FunctionAppContentEditingState . NotAllowed ) ]
78+ [ InlineData ( true , true , FunctionAppContentEditingState . Unknown , false ) ]
79+ public async Task GetHostStatus_TestFunctionAppContentEditable ( bool isFileSystemReadOnly , bool azureFilesAppSettingsExist , FunctionAppContentEditingState isFunctionAppContentEditable , bool isLinuxConsumption = true )
80+ {
81+ _mockScriptHostManager . SetupGet ( p => p . LastError ) . Returns ( ( Exception ) null ) ;
82+ var mockHostIdProvider = new Mock < IHostIdProvider > ( MockBehavior . Strict ) ;
83+ mockHostIdProvider . Setup ( p => p . GetHostIdAsync ( CancellationToken . None ) ) . ReturnsAsync ( "test123" ) ;
84+ var mockserviceProvider = new Mock < IServiceProvider > ( MockBehavior . Strict ) ;
85+ mockserviceProvider . Setup ( p => p . GetService ( typeof ( IExtensionBundleManager ) ) ) . Returns ( null ) ;
86+
87+ if ( isLinuxConsumption )
88+ {
89+ _mockEnvironment . Setup ( p => p . GetEnvironmentVariable ( EnvironmentSettingNames . ContainerName ) ) . Returns ( "test-container" ) ;
90+ }
91+
92+ _applicationHostOptions . IsFileSystemReadOnly = isFileSystemReadOnly ;
93+ if ( azureFilesAppSettingsExist )
94+ {
95+ _mockEnvironment . Setup ( p => p . GetEnvironmentVariable ( EnvironmentSettingNames . AzureFilesConnectionString ) ) . Returns ( "test value" ) ;
96+ _mockEnvironment . Setup ( p => p . GetEnvironmentVariable ( EnvironmentSettingNames . AzureFilesContentShare ) ) . Returns ( "test value" ) ;
97+ }
98+
99+ var result = ( OkObjectResult ) ( await _hostController . GetHostStatus ( _mockScriptHostManager . Object , mockHostIdProvider . Object , mockserviceProvider . Object ) ) ;
100+ var status = ( HostStatus ) result . Value ;
101+ Assert . Equal ( status . FunctionAppContentEditingState , isFunctionAppContentEditable ) ;
102+ }
103+
69104 [ Theory ]
70105 [ InlineData ( "blah" , ScriptHostState . Running , HttpStatusCode . BadRequest ) ]
71106 [ InlineData ( "Stopped" , ScriptHostState . Running , HttpStatusCode . BadRequest ) ]
0 commit comments