@@ -11,6 +11,7 @@ import (
11
11
"testing"
12
12
13
13
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/appservice/armappservice/v2"
14
+ "github.com/azure/azure-dev/cli/azd/pkg/azsdk"
14
15
"github.com/azure/azure-dev/cli/azd/pkg/convert"
15
16
"github.com/azure/azure-dev/cli/azd/test/mocks"
16
17
"github.com/stretchr/testify/require"
@@ -67,6 +68,31 @@ func Test_DeployTrackLinuxWebAppStatus(t *testing.T) {
67
68
require .True (t , ran )
68
69
require .Error (t , err )
69
70
})
71
+
72
+ t .Run ("Error" , func (t * testing.T ) {
73
+ ran := false
74
+ mockContext := mocks .NewMockContext (context .Background ())
75
+ azCli := newAzCliFromMockContext (mockContext )
76
+
77
+ registerLogicAppMocks (mockContext , & ran )
78
+ registerLogicAppZipDeployMocks (mockContext , & ran )
79
+ registerLogicAppPollingMocks (mockContext , & ran )
80
+
81
+ zipFile := bytes .NewReader ([]byte {})
82
+
83
+ res , err := azCli .DeployAppServiceZip (
84
+ * mockContext .Context ,
85
+ "SUBSCRIPTION_ID" ,
86
+ "RESOURCE_GROUP_ID" ,
87
+ "WINDOWS_LOGIC_APP_NAME" ,
88
+ zipFile ,
89
+ func (s string ) {},
90
+ )
91
+
92
+ require .NoError (t , err )
93
+ require .True (t , ran )
94
+ require .NotNil (t , res )
95
+ })
70
96
}
71
97
72
98
func registerIsLinuxWebAppMocks (mockContext * mocks.MockContext , ran * bool ) {
@@ -79,7 +105,7 @@ func registerIsLinuxWebAppMocks(mockContext *mocks.MockContext, ran *bool) {
79
105
response := armappservice.WebAppsClientGetResponse {
80
106
Site : armappservice.Site {
81
107
Location : convert .RefOf ("eastus2" ),
82
- Kind : convert .RefOf ("appserivce " ),
108
+ Kind : convert .RefOf ("app,linux " ),
83
109
Name : convert .RefOf ("LINUX_WEB_APP_NAME" ),
84
110
Properties : & armappservice.SiteProperties {
85
111
DefaultHostName : convert .RefOf ("LINUX_WEB_APP_NAME.azurewebsites.net" ),
@@ -100,6 +126,61 @@ func registerIsLinuxWebAppMocks(mockContext *mocks.MockContext, ran *bool) {
100
126
})
101
127
}
102
128
129
+ func registerLogicAppMocks (mockContext * mocks.MockContext , ran * bool ) {
130
+ mockContext .HttpClient .When (func (request * http.Request ) bool {
131
+ return request .Method == http .MethodGet &&
132
+ strings .Contains (request .URL .Path ,
133
+ "/subscriptions/SUBSCRIPTION_ID/resourceGroups/RESOURCE_GROUP_ID/providers/Microsoft.Web/sites/WINDOWS_LOGIC_APP_NAME" )
134
+ }).RespondFn (func (request * http.Request ) (* http.Response , error ) {
135
+ * ran = true
136
+ response := armappservice.WebAppsClientGetResponse {
137
+ Site : armappservice.Site {
138
+ Location : convert .RefOf ("eastus2" ),
139
+ Kind : convert .RefOf ("functionapp" ),
140
+ Name : convert .RefOf ("WINDOWS_LOGIC_APP_NAME" ),
141
+ Properties : & armappservice.SiteProperties {
142
+ DefaultHostName : convert .RefOf ("WINDOWS_LOGIC_APP_NAME.azurewebsites.net" ),
143
+ SiteConfig : & armappservice.SiteConfig {
144
+ LinuxFxVersion : convert .RefOf ("" ),
145
+ },
146
+ HostNameSSLStates : []* armappservice.HostNameSSLState {
147
+ {
148
+ HostType : convert .RefOf (armappservice .HostTypeRepository ),
149
+ Name : convert .RefOf ("WINDOWS_LOGIC_APP_SCM_HOST" ),
150
+ },
151
+ },
152
+ },
153
+ },
154
+ }
155
+
156
+ return mocks .CreateHttpResponseWithBody (request , http .StatusOK , response )
157
+ })
158
+ }
159
+
160
+ func registerLogicAppPollingMocks (mockContext * mocks.MockContext , ran * bool ) {
161
+ // Polling call to check on the deployment status
162
+ mockContext .HttpClient .When (func (request * http.Request ) bool {
163
+ return request .Method == http .MethodGet && strings .Contains (request .URL .Path , "/deployments/latest" )
164
+ }).RespondFn (func (request * http.Request ) (* http.Response , error ) {
165
+ * ran = true
166
+ completeStatus := azsdk.DeployStatusResponse {
167
+ DeployStatus : azsdk.DeployStatus {
168
+ Id : "ID" ,
169
+ Status : http .StatusOK ,
170
+ StatusText : "OK" ,
171
+ Message : "Deployment Complete" ,
172
+ Progress : nil ,
173
+ Complete : true ,
174
+ Active : true ,
175
+ SiteName : "WINDOWS_LOGIC_APP_NAME" ,
176
+ LogUrl : "https://log.url" ,
177
+ },
178
+ }
179
+
180
+ return mocks .CreateHttpResponseWithBody (request , http .StatusOK , completeStatus )
181
+ })
182
+ }
183
+
103
184
func registerLinuxWebAppDeployRuntimeSuccessfulMocks (mockContext * mocks.MockContext , ran * bool ) {
104
185
mockContext .HttpClient .When (func (request * http.Request ) bool {
105
186
//nolint:lll
@@ -158,6 +239,21 @@ func registerLinuxWebAppDeployRuntimeFailedMocks(mockContext *mocks.MockContext,
158
239
})
159
240
}
160
241
242
+ func registerLogicAppZipDeployMocks (mockContext * mocks.MockContext , ran * bool ) {
243
+ // Original call to start the deployment operation
244
+ mockContext .HttpClient .When (func (request * http.Request ) bool {
245
+ return request .Method == http .MethodPost &&
246
+ request .URL .Host == "WINDOWS_LOGIC_APP_SCM_HOST" &&
247
+ strings .Contains (request .URL .Path , "/api/zipdeploy" )
248
+ }).RespondFn (func (request * http.Request ) (* http.Response , error ) {
249
+ * ran = true
250
+ response , _ := mocks .CreateEmptyHttpResponse (request , http .StatusAccepted )
251
+ response .Header .Set ("Location" , "https://WINDOWS_LOGIC_APP_SCM_HOST/deployments/latest" )
252
+
253
+ return response , nil
254
+ })
255
+ }
256
+
161
257
func registerLinuxWebAppZipDeployMocks (mockContext * mocks.MockContext , ran * bool ) {
162
258
mockContext .HttpClient .When (func (request * http.Request ) bool {
163
259
return request .Method == http .MethodPost &&
0 commit comments