@@ -19,7 +19,6 @@ package com.netflix.spinnaker.orca.pipeline.util
1919
2020import  com.fasterxml.jackson.core.type.TypeReference 
2121import  com.fasterxml.jackson.databind.ObjectMapper 
22- import  com.netflix.spinnaker.kork.artifacts.ArtifactTypes 
2322import  com.netflix.spinnaker.kork.artifacts.model.Artifact 
2423import  com.netflix.spinnaker.kork.artifacts.model.ExpectedArtifact 
2524import  com.netflix.spinnaker.orca.api.pipeline.models.ExecutionStatus 
@@ -82,29 +81,6 @@ class ArtifactUtilsSpec extends Specification {
8281    artifact. name ==  ' build/libs/my-jar-100.jar' 
8382  }
8483
85-   def  " should bind stage-inlined artifacts to trigger artifacts"  () {
86-     setup :
87-     def  execution =  pipeline {
88-       stage {
89-         name =  " upstream stage" 
90-         type =  " stage1" 
91-         refId =  " 1" 
92-       }
93-     }
94- 
95-     execution. trigger =  new  DefaultTrigger (' manual'  )
96-     execution. trigger. artifacts. add(Artifact . builder(). type(' http/file'  ). name(' build/libs/my-jar-100.jar'  ). build())
97- 
98-     when :
99-     def  artifact =  makeArtifactUtils(). getBoundArtifactForStage(execution. stages[0 ], null , Artifact . builder()
100-         .type(' http/file'  )
101-         .name(' build/libs/my-jar-\\ d+.jar'  )
102-         .build())
103- 
104-     then :
105-     artifact. name ==  ' build/libs/my-jar-100.jar' 
106-   }
107- 
10884  def  " should find upstream artifacts in small pipeline"  () {
10985    when :
11086    def  desired =  execution. getStages(). find { it. name ==  " desired"   }
@@ -516,81 +492,118 @@ class ArtifactUtilsSpec extends Specification {
516492    initialArtifacts ==  finalArtifacts
517493  }
518494
519-   def  " should find  artifact if triggers is present in pipeline "  () {
495+   def  " resolve expected  artifact using default artifact "  () {
520496    given :
521-     def  defaultArtifact =  Artifact . builder()
522-         .customKind(true )
497+     def  matchArtifact =  Artifact 
498+         .builder()
499+         .name(" my-artifact"  )
500+         .artifactAccount(" embedded-artifact"  )
501+         .type(" embedded/base64"  )
523502        .build()
524- 
525-     def  matchArtifact =  Artifact . builder()
526-         .name(" my-pipeline-artifact"  )
503+     def  defaultArtifact =  Artifact 
504+         .builder()
505+         .name(" default-artifact"  )
506+         .artifactAccount(" embedded-artifact"  )
527507        .type(" embedded/base64"  )
528-         .reference(" aGVsbG8gd29ybGQK "  )
508+         .reference(" bmVtZXNpcwo= "  )
529509        .build()
530- 
531-     def  expectedArtifact =  ExpectedArtifact . builder()
532-         .usePriorArtifact(false )
533-         .useDefaultArtifact(false )
534-         .id(" my-id"  )
535-         .defaultArtifact(defaultArtifact)
510+     def  expectedArtifact =  ExpectedArtifact 
511+         .builder()
536512        .matchArtifact(matchArtifact)
513+         .defaultArtifact(defaultArtifact)
514+         .useDefaultArtifact(true )
537515        .build()
538516
539-     def  expectedArtifact2 =  ExpectedArtifact . builder()
540-         .usePriorArtifact(false )
541-         .useDefaultArtifact(false )
542-         .id(" my-id-2"  )
543-         .defaultArtifact(defaultArtifact)
517+     def  pipeline =  [
518+         id                : " 01HE3GXEJX05143Y7JSGTRRB40"  ,
519+         trigger           : [
520+             type : " manual"  ,
521+             //  not passing artifacts in trigger
522+         ],
523+         expectedArtifacts : [expectedArtifact],
524+     ]
525+     def  artifactUtils =  makeArtifactUtils()
526+ 
527+     when :
528+     artifactUtils. resolveArtifacts(pipeline)
529+     List<ExpectedArtifact >  resolvedArtifacts =  objectMapper. convertValue(
530+         pipeline. trigger. resolvedExpectedArtifacts,
531+         new  TypeReference<List<ExpectedArtifact > > () {}
532+     )
533+ 
534+     then :
535+     pipeline. trigger. artifacts. size() ==  1 
536+     pipeline. trigger. expectedArtifacts. size() ==  1 
537+     pipeline. trigger. resolvedExpectedArtifacts. size() ==  1 
538+     resolvedArtifacts* . getBoundArtifact() ==  [defaultArtifact]
539+   }
540+ 
541+   def  " resolve expected artifact using prior artifact"  () {
542+     given :
543+     def  artifactName =  " my-artifact-name" 
544+     def  priorArtifact =  Artifact 
545+         .builder()
546+         .name(artifactName)
547+         .artifactAccount(" embedded-artifact"  )
548+         .type(" embedded/base64"  )
549+         .reference(" b3NvcmlvCg=="  )
550+         .build()
551+ 
552+     def  pipelineId =  " 01HE3GXEJX05143Y7JSGTRRB41" 
553+     def  priorExecution =  pipeline {
554+       id :
555+       pipelineId
556+       status :
557+       ExecutionStatus . SUCCEEDED 
558+       stage {
559+         refId =  " 1" 
560+         outputs. artifacts =  [priorArtifact]
561+       }
562+     }
563+ 
564+     ExecutionRepository.ExecutionCriteria  criteria =  new  ExecutionRepository.ExecutionCriteria ();
565+     criteria. setPageSize(1 );
566+     criteria. setSortType(ExecutionRepository.ExecutionComparator . START_TIME_OR_ID );
567+ 
568+     def  executionRepositoryMock =  Mock (ExecutionRepository ) {
569+       retrievePipelinesForPipelineConfigId(pipelineId, criteria) >>  Observable . just(priorExecution)
570+     }
571+ 
572+     def  matchArtifact =  Artifact 
573+         .builder()
574+         .name(artifactName)
575+         .artifactAccount(" embedded-artifact"  )
576+         .type(" embedded/base64"  )
577+         .build()
578+     def  expectedArtifact =  ExpectedArtifact 
579+         .builder()
544580        .matchArtifact(matchArtifact)
581+         .usePriorArtifact(true )
545582        .build()
546583
547584    def  pipeline =  [
548-         " id"  : " abc"  ,
549-         " stages"  : [
550-             stage {
551-               expectedArtifacts : [expectedArtifact]
552-               inputArtifacts : [
553-                   " id"  : " my-id" 
554-               ]
555-             }
585+         id                : pipelineId,
586+         trigger           : [
587+             type : " manual"  ,
588+             //  not passing artifacts in trigger
556589        ],
557-         expectedArtifacts : [
558-           expectedArtifact
559-         ],
560-         trigger : [
561-             artifacts : [
562-                Artifact . builder()
563-                 .type(ArtifactTypes . EMBEDDED_BASE64 . getMimeType())
564-                 .name(matchArtifact. getName())
565-                 .reference(matchArtifact. getReference())
566-                 .build()
567-             ],
568-             type : " some-type" 
569-         ],
570-         triggers : [
571-             [
572-                 enabled : true ,
573-                 expectedArtifactIds : [
574-                     expectedArtifact. getId()
575-                 ],
576-                 type : " some-type" 
577-             ],
578-             [
579-                 enabled : true ,
580-                 expectedArtifactIds : [
581-                     expectedArtifact2. getId()
582-                 ],
583-                 type : " some-other-type" 
584-             ]
585-         ]
590+         expectedArtifacts : [expectedArtifact],
586591    ]
587592
588-     def  pipelineMap =  getObjectMapper(). convertValue(pipeline, Map . class)
593+     def  artifactUtils =  makeArtifactUtilsWithStub(executionRepositoryMock)
594+ 
589595    when :
590-      makeArtifactUtils(). resolveArtifacts(pipelineMap)
596+     artifactUtils. resolveArtifacts(pipeline)
597+     List<ExpectedArtifact >  resolvedArtifacts =  objectMapper. convertValue(
598+         pipeline. trigger. resolvedExpectedArtifacts,
599+         new  TypeReference<List<ExpectedArtifact > > () {}
600+     )
591601
592602    then :
593-     pipelineMap. trigger. resolvedExpectedArtifacts. size() ==  1 
603+     pipeline. trigger. artifacts. size() ==  1 
604+     pipeline. trigger. expectedArtifacts. size() ==  1 
605+     pipeline. trigger. resolvedExpectedArtifacts. size() ==  1 
606+     resolvedArtifacts* . getBoundArtifact() ==  [priorArtifact]
594607  }
595608
596609  private  List<Artifact >  extractTriggerArtifacts (Map<String , Object >  trigger ) {
0 commit comments