@@ -15,6 +15,7 @@ import (
1515 "testing"
1616 "time"
1717
18+ "github.com/openshift-pipelines/pipelines-as-code/pkg/apis/pipelinesascode/v1alpha1"
1819 "github.com/openshift-pipelines/pipelines-as-code/pkg/params"
1920 "github.com/openshift-pipelines/pipelines-as-code/pkg/params/clients"
2021 "github.com/openshift-pipelines/pipelines-as-code/pkg/params/info"
@@ -308,13 +309,14 @@ func TestSetClient(t *testing.T) {
308309 name string
309310 apiURL string
310311 opts * info.Event
312+ repo * v1alpha1.Repository
311313 wantErrSubstr string
312314 muxUser func (w http.ResponseWriter , r * http.Request )
313315 }{
314316 {
315- name : "bad/no username " ,
317+ name : "bad/no token " ,
316318 opts : info .NewEvent (),
317- wantErrSubstr : "no spec.git_provider.user " ,
319+ wantErrSubstr : "no spec.git_provider.secret " ,
318320 },
319321 {
320322 name : "bad/no secret" ,
@@ -349,7 +351,26 @@ func TestSetClient(t *testing.T) {
349351 _ , _ = w .Write ([]byte (`{"errors": [{"message": "Unauthorized"}]}` ))
350352 },
351353 apiURL : "https://foo.bar/rest" ,
352- wantErrSubstr : "cannot get user foo with token" ,
354+ wantErrSubstr : "failed validation of user foo with provided token: Unauthorized" ,
355+ },
356+ {
357+ name : "bad/invalid secret" ,
358+ opts : & info.Event {
359+ Provider : & info.Provider {
360+ Token : "bar" ,
361+ URL : "https://foo.bar" ,
362+ },
363+ },
364+ repo : & v1alpha1.Repository {
365+ Spec : v1alpha1.RepositorySpec {
366+ URL : "rest/api/1.0/users/foo" ,
367+ },
368+ },
369+ muxUser : func (w http.ResponseWriter , _ * http.Request ) {
370+ w .WriteHeader (http .StatusUnauthorized )
371+ },
372+ apiURL : "https://foo.bar" ,
373+ wantErrSubstr : "token validation failed: unauthorized" ,
353374 },
354375 {
355376 name : "bad/unknown error" ,
@@ -365,7 +386,7 @@ func TestSetClient(t *testing.T) {
365386 _ , _ = w .Write ([]byte (`{"errors": [{"message": "Internal Server Error"}]}` ))
366387 },
367388 apiURL : "https://foo.bar/rest" ,
368- wantErrSubstr : "cannot get user foo : Internal Server Error" ,
389+ wantErrSubstr : "user validation failed with : Internal Server Error" ,
369390 },
370391 {
371392 name : "good/url append /rest" ,
@@ -398,7 +419,7 @@ func TestSetClient(t *testing.T) {
398419 mux .HandleFunc ("/users/foo" , tt .muxUser )
399420 }
400421 v := & Provider {client : client , baseURL : tURL }
401- err := v .SetClient (ctx , fakeRun , tt .opts , nil , nil )
422+ err := v .SetClient (ctx , fakeRun , tt .opts , tt . repo , nil )
402423 if tt .wantErrSubstr != "" {
403424 assert .ErrorContains (t , err , tt .wantErrSubstr )
404425 return
0 commit comments