@@ -196,7 +196,7 @@ func TestDockerLifecycleBuildCreation(t *testing.T) {
196196 require .NoError (t , err )
197197
198198 pusher := NewAppPushOperation (cf , "" , "" )
199-
199+
200200 // Test the buildDroplet method specifically with a docker package
201201 resultDroplet , err := pusher .buildDroplet (context .Background (), dockerPkg , manifest )
202202 require .NoError (t , err , "Docker lifecycle build should not fail" )
@@ -215,7 +215,7 @@ func TestDockerLifecycleStructure(t *testing.T) {
215215
216216 // Create build request directly to test lifecycle structure
217217 buildCreate := resource .NewBuildCreate (dockerPkg .GUID )
218-
218+
219219 // Apply the same logic as in buildDroplet method
220220 if dockerPkg .Type == resource .LifecycleDocker .String () {
221221 buildCreate .Lifecycle = & resource.Lifecycle {
@@ -228,7 +228,7 @@ func TestDockerLifecycleStructure(t *testing.T) {
228228 require .NotNil (t , buildCreate .Lifecycle , "Docker build should have lifecycle" )
229229 require .Equal (t , "docker" , buildCreate .Lifecycle .Type , "Docker build should have docker lifecycle type" )
230230 require .NotNil (t , buildCreate .Lifecycle .Data , "Docker build should have lifecycle data" )
231-
231+
232232 // Verify it's the correct type
233233 dockerLifecycle , ok := buildCreate .Lifecycle .Data .(* resource.DockerLifecycle )
234234 require .True (t , ok , "Docker build lifecycle data should be DockerLifecycle type" )
@@ -245,11 +245,100 @@ func TestDockerLifecycleJSONMarshaling(t *testing.T) {
245245 // Test JSON marshaling to ensure it produces the expected structure
246246 // This is what the CF API expects: {"type":"docker","data":{}}
247247 expectedJSON := `{"type":"docker","data":{}}`
248-
248+
249249 // Marshal the lifecycle
250250 actualJSON , err := dockerLifecycle .MarshalJSON ()
251251 require .NoError (t , err , "Docker lifecycle should marshal without error" )
252-
252+
253253 // Verify the JSON structure matches expectations
254254 require .JSONEq (t , expectedJSON , string (actualJSON ), "Docker lifecycle JSON should match expected format" )
255255}
256+
257+ func TestPushOperationLifecycleLogic (t * testing.T ) {
258+ tests := []struct {
259+ name string
260+ manifestLifecycle AppLifecycle
261+ docker * AppManifestDocker
262+ expectedPackage string // "docker" or "bits"
263+ expectedLifecycle string // "docker", "buildpack", or "cnb"
264+ }{
265+ {
266+ name : "Explicit docker lifecycle" ,
267+ manifestLifecycle : Docker ,
268+ docker : & AppManifestDocker {Image : "nginx:latest" },
269+ expectedPackage : "docker" ,
270+ expectedLifecycle : "docker" ,
271+ },
272+ {
273+ name : "Explicit buildpack lifecycle" ,
274+ manifestLifecycle : Buildpack ,
275+ docker : nil ,
276+ expectedPackage : "bits" ,
277+ expectedLifecycle : "buildpack" ,
278+ },
279+ {
280+ name : "Explicit CNB lifecycle" ,
281+ manifestLifecycle : CNB ,
282+ docker : nil ,
283+ expectedPackage : "bits" ,
284+ expectedLifecycle : "cnb" ,
285+ },
286+ {
287+ name : "No lifecycle with docker" ,
288+ manifestLifecycle : "" ,
289+ docker : & AppManifestDocker {Image : "nginx:latest" },
290+ expectedPackage : "docker" ,
291+ expectedLifecycle : "fallback" , // This would use app.Lifecycle.Type in actual code
292+ },
293+ {
294+ name : "No lifecycle without docker" ,
295+ manifestLifecycle : "" ,
296+ docker : nil ,
297+ expectedPackage : "bits" ,
298+ expectedLifecycle : "fallback" , // This would use app.Lifecycle.Type in actual code
299+ },
300+ }
301+
302+ for _ , tt := range tests {
303+ t .Run (tt .name , func (t * testing.T ) {
304+ manifest := & AppManifest {
305+ Name : "test-app" ,
306+ Lifecycle : tt .manifestLifecycle ,
307+ Docker : tt .docker ,
308+ }
309+
310+ // Test package type decision logic
311+ var shouldUseDockerpPackage bool
312+ if manifest .Lifecycle != "" {
313+ shouldUseDockerpPackage = (manifest .Lifecycle == Docker )
314+ } else {
315+ shouldUseDockerpPackage = (manifest .Docker != nil )
316+ }
317+
318+ if tt .expectedPackage == "docker" {
319+ require .True (t , shouldUseDockerpPackage , "Should use docker package" )
320+ } else {
321+ require .False (t , shouldUseDockerpPackage , "Should use bits package" )
322+ }
323+
324+ // Test lifecycle type decision logic (only when explicitly set)
325+ if manifest .Lifecycle != "" {
326+ var lifecycleType string
327+ switch manifest .Lifecycle {
328+ case Docker :
329+ lifecycleType = "docker"
330+ case CNB :
331+ lifecycleType = "cnb"
332+ case Buildpack :
333+ fallthrough
334+ default :
335+ lifecycleType = "buildpack"
336+ }
337+
338+ if tt .expectedLifecycle != "fallback" {
339+ require .Equal (t , tt .expectedLifecycle , lifecycleType , "Lifecycle type should match expected" )
340+ }
341+ }
342+ })
343+ }
344+ }
0 commit comments