Skip to content

Commit b421ba1

Browse files
committed
test(github): use New() gh provider in tests
Provider struct literals bypass the New() constructor, leaving the checkRunsCache map nil. Use New() consistently across test files to ensure proper initialization. Signed-off-by: Akshay Pant <akpant@redhat.com>
1 parent 38989ae commit b421ba1

File tree

5 files changed

+20
-23
lines changed

5 files changed

+20
-23
lines changed

pkg/matcher/annotation_matcher_test.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1623,9 +1623,8 @@ func TestMatchPipelinerunAnnotationAndRepositories(t *testing.T) {
16231623
ctx, _ := rtesting.SetupFakeContext(t)
16241624
fakeclient, mux, ghTestServerURL, teardown := ghtesthelper.SetupGH()
16251625
defer teardown()
1626-
vcx := &ghprovider.Provider{
1627-
Token: github.Ptr("None"),
1628-
}
1626+
vcx := ghprovider.New()
1627+
vcx.Token = github.Ptr("None")
16291628
vcx.SetGithubClient(fakeclient)
16301629
if tt.args.runevent.Request == nil {
16311630
tt.args.runevent.Request = &info.Request{Header: http.Header{}, Payload: nil}
@@ -2338,7 +2337,7 @@ func TestMatchPipelinerunByAnnotation(t *testing.T) {
23382337

23392338
eventEmitter := events.NewEventEmitter(cs.Clients.Kube, logger)
23402339
repo := tt.repo
2341-
matches, err := MatchPipelinerunByAnnotation(ctx, logger, tt.args.pruns, cs, &tt.args.runevent, &ghprovider.Provider{}, eventEmitter, repo, true)
2340+
matches, err := MatchPipelinerunByAnnotation(ctx, logger, tt.args.pruns, cs, &tt.args.runevent, ghprovider.New(), eventEmitter, repo, true)
23422341
if tt.wantErrNoFailedPipelineToRetest {
23432342
assert.Assert(t, err != nil, "expected ErrNoFailedPipelineToRetest")
23442343
assert.Assert(t, errors.Is(err, NoFailedPipelineToRetestError("/pac ")), "expected ErrNoFailedPipelineToRetest, got: %v", err)
@@ -3284,7 +3283,7 @@ func TestFilterSuccessfulTemplates(t *testing.T) {
32843283
return
32853284
}
32863285

3287-
filtered := filterSuccessfulTemplates(ctx, logger, cs, event, repo, &ghprovider.Provider{}, tt.matchedPRs)
3286+
filtered := filterSuccessfulTemplates(ctx, logger, cs, event, repo, ghprovider.New(), tt.matchedPRs)
32883287

32893288
// Check that the correct number of templates remain
32903289
assert.Equal(t, len(tt.expectedNames), len(filtered),

pkg/pipelineascode/match_test.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -557,10 +557,9 @@ func TestGetPipelineRunsFromRepo(t *testing.T) {
557557
k8int := &kitesthelper.KinterfaceTest{
558558
ConsoleURL: "https://console.url",
559559
}
560-
vcx := &ghprovider.Provider{
561-
Token: github.Ptr("None"),
562-
Logger: logger,
563-
}
560+
vcx := ghprovider.New()
561+
vcx.Token = github.Ptr("None")
562+
vcx.Logger = logger
564563
vcx.SetGithubClient(fakeclient)
565564
pacInfo := &info.PacOpts{
566565
Settings: settings.Settings{
@@ -789,7 +788,9 @@ func TestVerifyRepoAndUser(t *testing.T) {
789788
func(rw http.ResponseWriter, _ *http.Request) { fmt.Fprint(rw, `{}`) },
790789
)
791790

792-
vcx := &ghprovider.Provider{Token: github.Ptr("token"), Logger: logger}
791+
vcx := ghprovider.New()
792+
vcx.Token = github.Ptr("token")
793+
vcx.Logger = logger
793794
vcx.SetGithubClient(ghClient)
794795
vcx.SetPacInfo(pacInfo)
795796

pkg/pipelineascode/pipelineascode_startpr_test.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -207,11 +207,10 @@ func setupStartPRTest(t *testing.T) (*params.Run, *info.Event, *zap.SugaredLogge
207207

208208
// setupProviderForTest creates and configures a GitHub provider for testing.
209209
func setupProviderForTest(cs *params.Run, logger *zap.SugaredLogger, fakeclient *github.Client, pacInfo *info.PacOpts) *ghprovider.Provider {
210-
vcx := &ghprovider.Provider{
211-
Run: cs,
212-
Token: github.Ptr("test-token"),
213-
Logger: logger,
214-
}
210+
vcx := ghprovider.New()
211+
vcx.Run = cs
212+
vcx.Token = github.Ptr("test-token")
213+
vcx.Logger = logger
215214
vcx.SetGithubClient(fakeclient)
216215
vcx.SetPacInfo(pacInfo)
217216
return vcx

pkg/pipelineascode/pipelineascode_test.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -662,11 +662,10 @@ func TestRun(t *testing.T) {
662662
HubCatalogs: &hubCatalogs,
663663
},
664664
}
665-
vcx := &ghprovider.Provider{
666-
Run: cs,
667-
Token: github.Ptr("None"),
668-
Logger: logger,
669-
}
665+
vcx := ghprovider.New()
666+
vcx.Run = cs
667+
vcx.Token = github.Ptr("None")
668+
vcx.Logger = logger
670669
vcx.SetGithubClient(fakeclient)
671670
vcx.SetPacInfo(pacInfo)
672671
p := NewPacs(&tt.runevent, vcx, cs, pacInfo, k8int, logger, nil)

pkg/reconciler/reconciler_test.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,8 @@ func TestReconcilerReconcileKind(t *testing.T) {
7171
fakeclient, mux, _, teardown := ghtesthelper.SetupGH()
7272
defer teardown()
7373

74-
vcx := &ghprovider.Provider{
75-
Token: github.Ptr("None"),
76-
}
74+
vcx := ghprovider.New()
75+
vcx.Token = github.Ptr("None")
7776

7877
vcx.SetGithubClient(fakeclient)
7978

0 commit comments

Comments
 (0)