-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add tests and update provider_issues.go
- Loading branch information
Showing
3 changed files
with
194 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
125 changes: 125 additions & 0 deletions
125
hack/tools/release/internal/update_providers/provider_issues_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
//go:build tools | ||
// +build tools | ||
|
||
/* | ||
Copyright 2022 The Kubernetes Authors. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package main | ||
|
||
import ( | ||
"os" | ||
"testing" | ||
|
||
. "github.com/onsi/gomega" | ||
) | ||
|
||
// MockExiter is a mock implementation of the Exiter interface. | ||
type MockExiter struct { | ||
ExitCalled bool | ||
ExitCode int | ||
} | ||
|
||
// Exit is a mock implementation of the Exiter interface. | ||
func (me *MockExiter) Exit(code int) { | ||
me.ExitCalled = true | ||
me.ExitCode = code | ||
} | ||
|
||
func Test_GetReleaseDetails(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
releaseTag string | ||
releaseDate string | ||
want releaseDetails | ||
expectExit bool | ||
}{ | ||
{ | ||
name: "Correct RELEASE_TAG and RELEASE_DATE are set", | ||
releaseTag: "v1.7.0-beta.0", | ||
releaseDate: "2024-04-16", | ||
want: releaseDetails{ | ||
ReleaseDate: "Tuesday, 16th April 2024", | ||
ReleaseTag: "v1.7.0", | ||
BetaTag: "v1.7.0-beta.0", | ||
ReleaseLink: "https://github.com/kubernetes-sigs/cluster-api/tree/main/docs/release/releases/release-1.7.md#timeline", | ||
ReleaseNotesLink: "https://github.com/kubernetes-sigs/cluster-api/releases/tag/v1.7.0-beta.0", | ||
}, | ||
expectExit: false, | ||
}, | ||
{ | ||
name: "RELEASE_TAG is not in the format ^v\\d+\\.\\d+\\.\\d+-beta\\.\\d+$", | ||
releaseTag: "v1.7.0.1", | ||
releaseDate: "2024-04-16", | ||
expectExit: true, | ||
}, | ||
{ | ||
name: "RELEASE_TAG does not have prefix 'v' in its semver", | ||
releaseTag: "1.7.0-beta.0", | ||
releaseDate: "2024-04-16", | ||
expectExit: true, | ||
}, | ||
{ | ||
name: "RELEASE_TAG contains invalid Major.Minor.Patch SemVer", | ||
releaseTag: "v1.x.0-beta.0", | ||
releaseDate: "2024-04-16", | ||
expectExit: true, | ||
}, | ||
{ | ||
name: "invalid yyyy-dd-mm RELEASE_DATE entered", | ||
releaseTag: "v1.7.0-beta.0", | ||
releaseDate: "2024-16-4", | ||
expectExit: true, | ||
}, | ||
{ | ||
name: "invalid yyyy/dd/mm RELEASE_DATE entered", | ||
releaseTag: "v1.7.0-beta.0", | ||
releaseDate: "2024/16/4", | ||
expectExit: true, | ||
}, | ||
{ | ||
name: "invalid yyyy/mm/dd RELEASE_DATE entered", | ||
releaseTag: "v1.7.0-beta.0", | ||
releaseDate: "2024/4/16", | ||
expectExit: true, | ||
}, | ||
} | ||
|
||
for _, tt := range tests { | ||
mockExiter := &MockExiter{} | ||
m := &ProviderIssues{Exiter: mockExiter} | ||
|
||
t.Run(tt.name, func(t *testing.T) { | ||
g := NewWithT(t) | ||
|
||
_ = os.Setenv("RELEASE_TAG", tt.releaseTag) | ||
_ = os.Setenv("RELEASE_DATE", tt.releaseDate) | ||
|
||
got := m.getReleaseDetails() | ||
if tt.expectExit { | ||
g.Expect(mockExiter.ExitCalled).To(BeTrue()) | ||
g.Expect(mockExiter.ExitCode).To(Equal(1)) | ||
} else { | ||
g.Expect(mockExiter.ExitCalled).To(BeFalse()) | ||
g.Expect(got.ReleaseDate).To(Equal(tt.want.ReleaseDate)) | ||
g.Expect(got.ReleaseTag).To(Equal(tt.want.ReleaseTag)) | ||
g.Expect(got.BetaTag).To(Equal(tt.want.BetaTag)) | ||
g.Expect(got.ReleaseLink).To(Equal(tt.want.ReleaseLink)) | ||
} | ||
_ = os.Unsetenv("RELEASE_TAG") | ||
_ = os.Unsetenv("RELEASE_DATE") | ||
}) | ||
} | ||
} |