Add tests

This commit is contained in:
Donny Xia
2020-05-18 14:37:44 -07:00
parent 557cd656ab
commit 44f5093ae3

View File

@@ -1,12 +1,13 @@
package main
import (
"fmt"
"os"
"regexp"
"testing"
)
func TestGetModuleCurrentVersion(t *testing.T) {
func TestList(t *testing.T) {
pwd, err := os.Getwd()
if err != nil {
t.Errorf(err.Error())
@@ -27,3 +28,43 @@ func TestGetModuleCurrentVersion(t *testing.T) {
}
}
}
func TestRelease(t *testing.T) {
prepareGit()
modName := "api"
versionType := "patch"
pwd, err := os.Getwd()
if err != nil {
t.Errorf(err.Error())
}
remote := "upstream"
// Check remotes
checkRemoteExistence(pwd, remote)
// Fetch latest tags from remote
fetchTags(pwd, remote)
mod := module{
name: modName,
path: pwd,
}
mod.UpdateCurrentVersion()
oldVersion := mod.version.String()
mod.version.Bump(versionType)
newVersion := mod.version.String()
logInfo("Bumping version: %s => %s", oldVersion, newVersion)
// Create branch
branch := fmt.Sprintf("release-%s-v%d.%d", mod.name, mod.version.major, mod.version.minor)
newBranch(pwd, branch)
addWorktree(pwd, tempDir, branch)
merge(tempDir, "upstream/master")
// Update module path
mod.path = tempDir
// Clean
cleanGit()
pruneWorktree(pwd)
deleteBranch(pwd, branch)
}