@@ -76,6 +76,15 @@ func (m *MockHerokuClient) ListDynos(ctx context.Context, appName string) ([]Her
76
76
return dynos , args .Error (1 )
77
77
}
78
78
79
+ func (m * MockHerokuClient ) GetDynoSize (ctx context.Context , dynoSizeName string ) (HerokuDynoSize , error ) {
80
+ args := m .Called (ctx , dynoSizeName )
81
+ dynoSize , ok := args .Get (0 ).(HerokuDynoSize )
82
+ if ! ok {
83
+ return HerokuDynoSize {}, errors .New ("failed to cast to HerokuDynoSize" )
84
+ }
85
+ return dynoSize , args .Error (1 )
86
+ }
87
+
79
88
func (m * MockHerokuClient ) ListAddons (ctx context.Context , appName string ) ([]HerokuAddon , error ) {
80
89
args := m .Called (ctx , appName )
81
90
addons , ok := args .Get (0 ).([]HerokuAddon )
@@ -85,6 +94,15 @@ func (m *MockHerokuClient) ListAddons(ctx context.Context, appName string) ([]He
85
94
return addons , args .Error (1 )
86
95
}
87
96
97
+ func (m * MockHerokuClient ) GetPGInfo (ctx context.Context , addonID string ) (PGInfo , error ) {
98
+ args := m .Called (ctx , addonID )
99
+ pgInfo , ok := args .Get (0 ).(PGInfo )
100
+ if ! ok {
101
+ return PGInfo {}, errors .New ("failed to cast to *PGInfo" )
102
+ }
103
+ return pgInfo , args .Error (1 )
104
+ }
105
+
88
106
func (m * MockHerokuClient ) ListConfigVars (ctx context.Context , appName string ) (HerokuConfigVars , error ) {
89
107
args := m .Called (ctx , appName )
90
108
configVars , ok := args .Get (0 ).(HerokuConfigVars )
@@ -94,6 +112,15 @@ func (m *MockHerokuClient) ListConfigVars(ctx context.Context, appName string) (
94
112
return configVars , args .Error (1 )
95
113
}
96
114
115
+ func (m * MockHerokuClient ) GetReleaseTasks (ctx context.Context , appName string ) ([]HerokuReleaseTask , error ) {
116
+ args := m .Called (ctx , appName )
117
+ releaseTasks , ok := args .Get (0 ).([]HerokuReleaseTask )
118
+ if ! ok {
119
+ return nil , errors .New ("failed to cast to []HerokuReleaseTask" )
120
+ }
121
+ return releaseTasks , args .Error (1 )
122
+ }
123
+
97
124
func (m * MockHerokuClient ) SetToken (token string ) {
98
125
m .Called (token )
99
126
}
@@ -106,8 +133,11 @@ func TestInteractiveSetup(t *testing.T) {
106
133
herokuToken string
107
134
herokuApps []HerokuApplication
108
135
herokuDynos []HerokuDyno
136
+ herokuDynoSize HerokuDynoSize
109
137
herokuAddons []HerokuAddon
138
+ herokuPGInfo PGInfo
110
139
herokuConfigVars HerokuConfigVars
140
+ herokuReleaseTasks []HerokuReleaseTask
111
141
composeResponse * defangv1.GenerateComposeResponse
112
142
expectedComposeFileContents string
113
143
composeError error
@@ -128,6 +158,7 @@ func TestInteractiveSetup(t *testing.T) {
128
158
herokuDynos : []HerokuDyno {
129
159
{Name : "web.1" , Command : "npm start" , Size : "Standard-1X" , Type : "web" },
130
160
},
161
+ herokuDynoSize : HerokuDynoSize {Architecture : "amd64" , Name : "Eco" , Memory : 0.5 , Compute : 1 , PreciseDynoUnits : 0.28 },
131
162
herokuAddons : []HerokuAddon {
132
163
{
133
164
Name : "postgresql-addon-123" ,
@@ -145,6 +176,23 @@ func TestInteractiveSetup(t *testing.T) {
145
176
State : "provisioned" ,
146
177
},
147
178
},
179
+ herokuReleaseTasks : []HerokuReleaseTask {
180
+ {
181
+ Command : "rails db:migrate" ,
182
+ Type : "release" ,
183
+ Size : "Eco" ,
184
+ },
185
+ },
186
+ herokuPGInfo : PGInfo {
187
+ DatabaseName : "mydb" ,
188
+ NumBytes : 12345 ,
189
+ Info : []struct {
190
+ Name string `json:"name"`
191
+ Values []string `json:"values"`
192
+ }{
193
+ {Name : "PG Version" , Values : []string {"17.4" }},
194
+ },
195
+ },
148
196
herokuConfigVars : HerokuConfigVars {
149
197
"NODE_ENV" : "production" ,
150
198
"PORT" : "3000" ,
@@ -171,6 +219,7 @@ func TestInteractiveSetup(t *testing.T) {
171
219
{Name : "web.1" , Command : "node server.js" , Size : "Standard-2X" , Type : "web" },
172
220
{Name : "web.2" , Command : "node server.js" , Size : "Standard-2X" , Type : "web" },
173
221
},
222
+ herokuDynoSize : HerokuDynoSize {Architecture : "amd64" , Name : "Eco" , Memory : 0.5 , Compute : 1 , PreciseDynoUnits : 0.28 },
174
223
herokuAddons : []HerokuAddon {
175
224
{
176
225
Name : "redis-addon-456" ,
@@ -209,6 +258,7 @@ func TestInteractiveSetup(t *testing.T) {
209
258
{Name : "failing-app" , ID : "app-789" },
210
259
},
211
260
herokuDynos : []HerokuDyno {{Name : "web.1" , Command : "python app.py" , Type : "web" , Size : "Standard-1X" }},
261
+ herokuDynoSize : HerokuDynoSize {Architecture : "amd64" , Name : "Eco" , Memory : 0.5 , Compute : 1 , PreciseDynoUnits : 0.28 },
212
262
herokuAddons : []HerokuAddon {},
213
263
herokuConfigVars : HerokuConfigVars {},
214
264
composeError : errors .New ("fabric service unavailable" ),
@@ -226,6 +276,7 @@ func TestInteractiveSetup(t *testing.T) {
226
276
{Name : "yaml-invalid-app" , ID : "app-invalid" },
227
277
},
228
278
herokuDynos : []HerokuDyno {{Name : "web.1" , Command : "python app.py" , Type : "web" , Size : "Standard-1X" }},
279
+ herokuDynoSize : HerokuDynoSize {Architecture : "amd64" , Name : "Eco" , Memory : 0.5 , Compute : 1 , PreciseDynoUnits : 0.28 },
229
280
herokuAddons : []HerokuAddon {},
230
281
herokuConfigVars : HerokuConfigVars {},
231
282
composeResponse : & defangv1.GenerateComposeResponse {
@@ -280,8 +331,23 @@ func TestInteractiveSetup(t *testing.T) {
280
331
mockHerokuClient .On ("SetToken" , tt .herokuToken ).Once ()
281
332
mockHerokuClient .On ("ListApps" , mock .Anything ).Return (tt .herokuApps , nil )
282
333
mockHerokuClient .On ("ListDynos" , mock .Anything , mock .Anything ).Return (tt .herokuDynos , nil )
334
+
335
+ // GetDynoSize is called once for each dyno
336
+ for range tt .herokuDynos {
337
+ mockHerokuClient .On ("GetDynoSize" , mock .Anything , mock .Anything ).Return (tt .herokuDynoSize , nil ).Once ()
338
+ }
339
+
283
340
mockHerokuClient .On ("ListAddons" , mock .Anything , mock .Anything ).Return (tt .herokuAddons , nil )
341
+
342
+ // GetPGInfo is only called for Postgres addons
343
+ for _ , addon := range tt .herokuAddons {
344
+ if addon .AddonService .Name == "heroku-postgresql" {
345
+ mockHerokuClient .On ("GetPGInfo" , mock .Anything , addon .ID ).Return (tt .herokuPGInfo , nil ).Once ()
346
+ }
347
+ }
348
+
284
349
mockHerokuClient .On ("ListConfigVars" , mock .Anything , mock .Anything ).Return (tt .herokuConfigVars , nil )
350
+ mockHerokuClient .On ("GetReleaseTasks" , mock .Anything , mock .Anything ).Return (tt .herokuReleaseTasks , nil )
285
351
286
352
// Execute the function under test
287
353
ctx := context .Background ()
0 commit comments