From a5070637552ff63cd30de7184b6a8a5e341824ae Mon Sep 17 00:00:00 2001 From: ira-pandey1 Date: Fri, 7 Mar 2025 14:43:26 +0530 Subject: [PATCH 1/2] Added test cases for list.go and github.go --- hack/tools/release/notes/list_test.go | 140 ++++++++++++++++++++++++++ 1 file changed, 140 insertions(+) diff --git a/hack/tools/release/notes/list_test.go b/hack/tools/release/notes/list_test.go index 688abc9a1c0e..d74b4ae75833 100644 --- a/hack/tools/release/notes/list_test.go +++ b/hack/tools/release/notes/list_test.go @@ -65,3 +65,143 @@ func Test_buildSetOfPRNumbers(t *testing.T) { }) } } + +func Test_githubFromToPRLister_listPRs(t *testing.T) { + type fields struct { + client *githubClient + fromRef *ref + toRef *ref + branch string + } + type args struct { + previousReleaseRef ref + } + tests := []struct { + name string + fields *githubFromToPRLister + args ref + wantErr bool + }{ + { + name: "Successful PR Listing", + fields: &githubFromToPRLister{ + client: &githubClient{ + repo: "kubernetes-sigs/kind", + }, + fromRef: ref{ + reType: "tags", + value: "v0.26.0", + }, + toRef: ref{ + reType: "tags", + value: "v0.27.0", + }, + branch: "main", + }, + args: ref{ + reType: "tags", + value: "v0.26.0", + }, + wantErr: false, + }, + { + name: "Setting previousReleaseRef.value blank - should use toRef and fromRef from fields", + fields: &githubFromToPRLister{ + client: &githubClient{ + repo: "kubernetes-sigs/kind", + }, + fromRef: ref{ + reType: "tags", + value: "v0.26.0", + }, + toRef: ref{ + reType: "tags", + value: "v0.27.0", + }, + branch: "main", + }, + args: ref{ + reType: "tags", + value: "", + }, + wantErr: false, + }, + { + name: "Create PR List when fromRef is not set", + fields: &githubFromToPRLister{ + client: &githubClient{ + repo: "kubernetes-sigs/kind", + }, + toRef: ref{ + reType: "tags", + value: "v0.27.0", + }, + branch: "main", + }, + args: ref{ + reType: "tags", + value: "v0.26.0", + }, + wantErr: false, + }, + { + name: "Fail when previousReleaseRef.value is set to invalid", + fields: &githubFromToPRLister{ + client: &githubClient{ + repo: "kubernetes-sigs/kind", + }, + fromRef: ref{ + reType: "tags", + value: "v0.26.0", + }, + toRef: ref{ + reType: "tags", + value: "v0.27.0", + }, + branch: "main", + }, + args: ref{ + reType: "tags", + value: "invalid", + }, + wantErr: true, + }, + { + name: "Fail when toRef and previousReleaseRef set blank", + fields: &githubFromToPRLister{ + client: &githubClient{ + repo: "kubernetes-sigs/kind", + }, + fromRef: ref{ + reType: "tags", + value: "v0.26.0", + }, + toRef: ref{ + reType: "tags", + value: "", + }, + branch: "main", + }, + args: ref{ + reType: "tags", + value: "", + }, + wantErr: true, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + l := &githubFromToPRLister{ + client: tt.fields.client, + fromRef: tt.fields.fromRef, + toRef: tt.fields.toRef, + branch: tt.fields.branch, + } + _, err := l.listPRs(tt.args) + if (err != nil) != tt.wantErr { + t.Errorf("githubFromToPRLister.listPRs() error = %v, wantErr %v", err, tt.wantErr) + return + } + }) + } +} From 8b3ece593caf8f3a829208631d4408dc80b398a0 Mon Sep 17 00:00:00 2001 From: ira-pandey1 Date: Wed, 26 Mar 2025 10:52:14 +0530 Subject: [PATCH 2/2] Linting issues fixed --- hack/tools/release/notes/list_test.go | 67 ++++++++++++--------------- 1 file changed, 29 insertions(+), 38 deletions(-) diff --git a/hack/tools/release/notes/list_test.go b/hack/tools/release/notes/list_test.go index d74b4ae75833..c5848e236d9f 100644 --- a/hack/tools/release/notes/list_test.go +++ b/hack/tools/release/notes/list_test.go @@ -67,15 +67,6 @@ func Test_buildSetOfPRNumbers(t *testing.T) { } func Test_githubFromToPRLister_listPRs(t *testing.T) { - type fields struct { - client *githubClient - fromRef *ref - toRef *ref - branch string - } - type args struct { - previousReleaseRef ref - } tests := []struct { name string fields *githubFromToPRLister @@ -85,106 +76,106 @@ func Test_githubFromToPRLister_listPRs(t *testing.T) { { name: "Successful PR Listing", fields: &githubFromToPRLister{ - client: &githubClient{ - repo: "kubernetes-sigs/kind", + client: &githubClient{ + repo: "kubernetes-sigs/kind", }, fromRef: ref{ reType: "tags", - value: "v0.26.0", + value: "v0.26.0", }, toRef: ref{ reType: "tags", - value: "v0.27.0", + value: "v0.27.0", }, - branch: "main", + branch: "main", }, args: ref{ reType: "tags", - value: "v0.26.0", + value: "v0.26.0", }, wantErr: false, }, { name: "Setting previousReleaseRef.value blank - should use toRef and fromRef from fields", fields: &githubFromToPRLister{ - client: &githubClient{ - repo: "kubernetes-sigs/kind", + client: &githubClient{ + repo: "kubernetes-sigs/kind", }, fromRef: ref{ reType: "tags", - value: "v0.26.0", + value: "v0.26.0", }, toRef: ref{ reType: "tags", - value: "v0.27.0", + value: "v0.27.0", }, - branch: "main", + branch: "main", }, args: ref{ reType: "tags", - value: "", + value: "", }, wantErr: false, }, { name: "Create PR List when fromRef is not set", fields: &githubFromToPRLister{ - client: &githubClient{ - repo: "kubernetes-sigs/kind", + client: &githubClient{ + repo: "kubernetes-sigs/kind", }, toRef: ref{ reType: "tags", - value: "v0.27.0", + value: "v0.27.0", }, - branch: "main", + branch: "main", }, args: ref{ reType: "tags", - value: "v0.26.0", + value: "v0.26.0", }, wantErr: false, }, { name: "Fail when previousReleaseRef.value is set to invalid", fields: &githubFromToPRLister{ - client: &githubClient{ - repo: "kubernetes-sigs/kind", + client: &githubClient{ + repo: "kubernetes-sigs/kind", }, fromRef: ref{ reType: "tags", - value: "v0.26.0", + value: "v0.26.0", }, toRef: ref{ reType: "tags", - value: "v0.27.0", + value: "v0.27.0", }, - branch: "main", + branch: "main", }, args: ref{ reType: "tags", - value: "invalid", + value: "invalid", }, wantErr: true, }, { name: "Fail when toRef and previousReleaseRef set blank", fields: &githubFromToPRLister{ - client: &githubClient{ - repo: "kubernetes-sigs/kind", + client: &githubClient{ + repo: "kubernetes-sigs/kind", }, fromRef: ref{ reType: "tags", - value: "v0.26.0", + value: "v0.26.0", }, toRef: ref{ reType: "tags", - value: "", + value: "", }, - branch: "main", + branch: "main", }, args: ref{ reType: "tags", - value: "", + value: "", }, wantErr: true, },