Merge branch 'ada/20241129-parseversion-test'
This commit is contained in:
commit
69a7d96e4b
1 changed files with 82 additions and 0 deletions
|
|
@ -53,6 +53,88 @@ func TestNormalizeVersionString(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestParseVersion(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
|
tests := []struct {
|
||||||
|
name string
|
||||||
|
input string
|
||||||
|
wantErr bool
|
||||||
|
wantMajor int
|
||||||
|
wantMinor int
|
||||||
|
wantPatch int
|
||||||
|
wantPrerel string
|
||||||
|
wantBuild string
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "basic version",
|
||||||
|
input: "4.24.0",
|
||||||
|
wantMajor: 4, wantMinor: 24, wantPatch: 0,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "with v prefix",
|
||||||
|
input: "v4.24.0",
|
||||||
|
wantMajor: 4, wantMinor: 24, wantPatch: 0,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "with prerelease",
|
||||||
|
input: "4.24.0-rc.3",
|
||||||
|
wantMajor: 4, wantMinor: 24, wantPatch: 0,
|
||||||
|
wantPrerel: "rc.3",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "with build metadata",
|
||||||
|
input: "4.24.0+build.123",
|
||||||
|
wantMajor: 4, wantMinor: 24, wantPatch: 0,
|
||||||
|
wantBuild: "build.123",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "with prerelease and build",
|
||||||
|
input: "4.24.0-rc.3+build.123",
|
||||||
|
wantMajor: 4, wantMinor: 24, wantPatch: 0,
|
||||||
|
wantPrerel: "rc.3",
|
||||||
|
wantBuild: "build.123",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "invalid format",
|
||||||
|
input: "not-a-version",
|
||||||
|
wantErr: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "empty string",
|
||||||
|
input: "",
|
||||||
|
wantErr: true,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, tc := range tests {
|
||||||
|
tc := tc
|
||||||
|
t.Run(tc.name, func(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
got, err := ParseVersion(tc.input)
|
||||||
|
if tc.wantErr {
|
||||||
|
if err == nil {
|
||||||
|
t.Fatalf("ParseVersion(%q) expected error, got nil", tc.input)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("ParseVersion(%q) unexpected error: %v", tc.input, err)
|
||||||
|
}
|
||||||
|
if got.Major != tc.wantMajor || got.Minor != tc.wantMinor || got.Patch != tc.wantPatch {
|
||||||
|
t.Fatalf("ParseVersion(%q) = %d.%d.%d, want %d.%d.%d",
|
||||||
|
tc.input, got.Major, got.Minor, got.Patch, tc.wantMajor, tc.wantMinor, tc.wantPatch)
|
||||||
|
}
|
||||||
|
if got.Prerelease != tc.wantPrerel {
|
||||||
|
t.Fatalf("ParseVersion(%q).Prerelease = %q, want %q", tc.input, got.Prerelease, tc.wantPrerel)
|
||||||
|
}
|
||||||
|
if got.Build != tc.wantBuild {
|
||||||
|
t.Fatalf("ParseVersion(%q).Build = %q, want %q", tc.input, got.Build, tc.wantBuild)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestDetectChannelFromVersion(t *testing.T) {
|
func TestDetectChannelFromVersion(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue