131 lines
3.2 KiB
Go
131 lines
3.2 KiB
Go
package semver_test
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"git.thokra.dev/thokra/stamp/internal/changeset"
|
|
"git.thokra.dev/thokra/stamp/internal/semver"
|
|
)
|
|
|
|
func TestBump_Major(t *testing.T) {
|
|
got, err := semver.Bump("1.2.3", changeset.BumpMajor, "")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if got != "2.0.0" {
|
|
t.Errorf("expected 2.0.0, got %s", got)
|
|
}
|
|
}
|
|
|
|
func TestBump_Minor(t *testing.T) {
|
|
got, err := semver.Bump("1.2.3", changeset.BumpMinor, "")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if got != "1.3.0" {
|
|
t.Errorf("expected 1.3.0, got %s", got)
|
|
}
|
|
}
|
|
|
|
func TestBump_Patch(t *testing.T) {
|
|
got, err := semver.Bump("1.2.3", changeset.BumpPatch, "")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if got != "1.2.4" {
|
|
t.Errorf("expected 1.2.4, got %s", got)
|
|
}
|
|
}
|
|
|
|
func TestBump_PreMajor(t *testing.T) {
|
|
got, err := semver.Bump("1.2.3", changeset.BumpPreMajor, "alpha")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if got != "2.0.0-alpha.0" {
|
|
t.Errorf("expected 2.0.0-alpha.0, got %s", got)
|
|
}
|
|
}
|
|
|
|
func TestBump_PreMinor(t *testing.T) {
|
|
got, err := semver.Bump("1.2.3", changeset.BumpPreMinor, "beta")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if got != "1.3.0-beta.0" {
|
|
t.Errorf("expected 1.3.0-beta.0, got %s", got)
|
|
}
|
|
}
|
|
|
|
func TestBump_PrePatch(t *testing.T) {
|
|
got, err := semver.Bump("1.2.3", changeset.BumpPrePatch, "rc")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if got != "1.2.4-rc.0" {
|
|
t.Errorf("expected 1.2.4-rc.0, got %s", got)
|
|
}
|
|
}
|
|
|
|
func TestBump_PreRelease_Increment(t *testing.T) {
|
|
got, err := semver.Bump("1.2.4-rc.0", changeset.BumpPreRelease, "rc")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if got != "1.2.4-rc.1" {
|
|
t.Errorf("expected 1.2.4-rc.1, got %s", got)
|
|
}
|
|
}
|
|
|
|
func TestBump_PreRelease_NewFromStable(t *testing.T) {
|
|
got, err := semver.Bump("1.2.3", changeset.BumpPreRelease, "alpha")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if got != "1.2.4-alpha.0" {
|
|
t.Errorf("expected 1.2.4-alpha.0, got %s", got)
|
|
}
|
|
}
|
|
|
|
func TestBump_InvalidVersion(t *testing.T) {
|
|
_, err := semver.Bump("not-a-version", changeset.BumpPatch, "")
|
|
if err == nil {
|
|
t.Fatal("expected error for invalid version")
|
|
}
|
|
}
|
|
|
|
func TestHighestBump(t *testing.T) {
|
|
tests := []struct {
|
|
bumps []changeset.BumpType
|
|
expected changeset.BumpType
|
|
}{
|
|
{[]changeset.BumpType{changeset.BumpPatch, changeset.BumpMinor}, changeset.BumpMinor},
|
|
{[]changeset.BumpType{changeset.BumpMinor, changeset.BumpMajor}, changeset.BumpMajor},
|
|
{[]changeset.BumpType{changeset.BumpPreRelease}, changeset.BumpPreRelease},
|
|
{[]changeset.BumpType{changeset.BumpPreRelease, changeset.BumpPatch}, changeset.BumpPatch},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
got := semver.HighestBump(tt.bumps)
|
|
if got != tt.expected {
|
|
t.Errorf("HighestBump(%v) = %s, want %s", tt.bumps, got, tt.expected)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestProjectBumps(t *testing.T) {
|
|
changesets := []*changeset.Changeset{
|
|
{Slug: "a", Bumps: map[string]changeset.BumpType{"app": changeset.BumpMinor, "lib": changeset.BumpPatch}},
|
|
{Slug: "b", Bumps: map[string]changeset.BumpType{"app": changeset.BumpPatch}},
|
|
}
|
|
|
|
bumps := semver.ProjectBumps(changesets)
|
|
|
|
if len(bumps["app"]) != 2 {
|
|
t.Errorf("expected 2 bumps for app, got %d", len(bumps["app"]))
|
|
}
|
|
if len(bumps["lib"]) != 1 {
|
|
t.Errorf("expected 1 bump for lib, got %d", len(bumps["lib"]))
|
|
}
|
|
}
|