@@ -58,6 +58,13 @@ func TestPacRun_checkNeedUpdate(t *testing.T) {
5858}
5959
6060func TestChangePipelineRun (t * testing.T ) {
61+ repo := & v1alpha1.Repository {
62+ ObjectMeta : metav1.ObjectMeta {
63+ Name : "testrepo" ,
64+ Namespace : "test" ,
65+ },
66+ }
67+
6168 prs := []* tektonv1.PipelineRun {
6269 {
6370 ObjectMeta : metav1.ObjectMeta {
@@ -66,21 +73,59 @@ func TestChangePipelineRun(t *testing.T) {
6673 },
6774 },
6875 }
69- event := info .NewEvent ()
70- event .Repository = "testrepo"
71- p := & PacRun {event : event }
72- repo := & v1alpha1.Repository {
73- ObjectMeta : metav1.ObjectMeta {
74- Name : "testrepo" ,
75- Namespace : "test" ,
76+
77+ jsonErrorPRs := []* tektonv1.PipelineRun {
78+ {
79+ ObjectMeta : metav1.ObjectMeta {
80+ Name : "json-error-pr" ,
81+ Namespace : "test" ,
82+ },
83+ Spec : tektonv1.PipelineRunSpec {
84+ Params : []tektonv1.Param {
85+ {
86+ Name : "my-param" ,
87+ Value : tektonv1.ParamValue {
88+ // We are intentionally leaving this empty:
89+ // Type: tektonv1.ParamTypeString,
90+ StringVal : "some-value" ,
91+ },
92+ },
93+ },
94+ },
95+ },
96+ }
97+
98+ tests := []struct {
99+ name string
100+ prs []* tektonv1.PipelineRun
101+ expectedError string
102+ }{
103+ {
104+ name : "test with params" ,
105+ prs : prs ,
76106 },
107+ {
108+ name : "test with json error" ,
109+ prs : jsonErrorPRs ,
110+ expectedError : "failed to marshal PipelineRun json-error-pr: json: error calling MarshalJSON for type v1.ParamValue: impossible ParamValues.Type: \" \" " ,
111+ },
112+ }
113+ for _ , tt := range tests {
114+ t .Run (tt .name , func (t * testing.T ) {
115+ event := info .NewEvent ()
116+ event .Repository = "testrepo"
117+ p := & PacRun {event : event }
118+ ctx , _ := rtesting .SetupFakeContext (t )
119+ err := p .changePipelineRun (ctx , repo , tt .prs )
120+ if tt .expectedError != "" {
121+ assert .Error (t , err , tt .expectedError )
122+ return
123+ }
124+ assert .Assert (t , strings .HasPrefix (tt .prs [0 ].GetName (), "pac-gitauth" ), tt .prs [0 ].GetName (), "has no pac-gitauth prefix" )
125+ assert .Assert (t , tt .prs [0 ].GetAnnotations ()[apipac .GitAuthSecret ] != "" )
126+ assert .Assert (t , tt .prs [0 ].GetNamespace () == "testrepo" , "namespace should be testrepo: %v" , tt .prs [0 ].GetNamespace ())
127+ })
77128 }
78- ctx , _ := rtesting .SetupFakeContext (t )
79- err := p .changePipelineRun (ctx , repo , prs )
80- assert .NilError (t , err )
81- assert .Assert (t , strings .HasPrefix (prs [0 ].GetName (), "pac-gitauth" ), prs [0 ].GetName (), "has no pac-gitauth prefix" )
82- assert .Assert (t , prs [0 ].GetAnnotations ()[apipac .GitAuthSecret ] != "" )
83- assert .Assert (t , prs [0 ].GetNamespace () == "testrepo" , "namespace should be testrepo: %v" , prs [0 ].GetNamespace ())
84129}
85130
86131func TestFilterRunningPipelineRunOnTargetTest (t * testing.T ) {
0 commit comments