Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🌱 Added test cases for list.go and github.go #11937

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
131 changes: 131 additions & 0 deletions hack/tools/release/notes/list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,134 @@ func Test_buildSetOfPRNumbers(t *testing.T) {
})
}
}

func Test_githubFromToPRLister_listPRs(t *testing.T) {
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
}
})
}
}
Loading