From 056e4ee7079ae5cebb5d163c218781b8b4fa0514 Mon Sep 17 00:00:00 2001 From: zjhe Date: Thu, 7 Apr 2022 16:37:28 +0800 Subject: [PATCH] change signature --- upgradetest.go | 8 ++++---- upgradetest_test.go | 10 ++++++---- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/upgradetest.go b/upgradetest.go index 56d5b2f..32bc8e8 100644 --- a/upgradetest.go +++ b/upgradetest.go @@ -135,14 +135,14 @@ func sameMajorVersion(majorVersion int) func(i interface{}) bool { } } -func GetCurrentMajorVersionFromEnv() string { +func GetCurrentMajorVersionFromEnv() (int, error) { currentMajorVer := os.Getenv("PREVIOUS_MAJOR_VERSION") if currentMajorVer == "" { - return "v0" + return 0, nil } previousMajorVer, err := strconv.Atoi(strings.TrimPrefix(currentMajorVer, "v")) if err != nil { - return "" + return 0, err } - return fmt.Sprintf("v%d", previousMajorVer+1) + return previousMajorVer + 1, nil } diff --git a/upgradetest_test.go b/upgradetest_test.go index 7b73158..6e832a7 100644 --- a/upgradetest_test.go +++ b/upgradetest_test.go @@ -43,12 +43,14 @@ func TestSkipIfNoTagsWithinMajorVersion(t *testing.T) { } func TestGetCurrentMajorVersionFromEnv_default(t *testing.T) { - majorVersionFromEnv := GetCurrentMajorVersionFromEnv() - assert.Equal(t, "v0", majorVersionFromEnv) + majorVersionFromEnv, err := GetCurrentMajorVersionFromEnv() + assert.Nil(t, err) + assert.Equal(t, 0, majorVersionFromEnv) } func TestGetCurrentMajorVersionFromEnv_basic(t *testing.T) { os.Setenv("PREVIOUS_MAJOR_VERSION", "v0") - majorVersionFromEnv := GetCurrentMajorVersionFromEnv() - assert.Equal(t, "v1", majorVersionFromEnv) + majorVersionFromEnv, err := GetCurrentMajorVersionFromEnv() + assert.Nil(t, err) + assert.Equal(t, 1, majorVersionFromEnv) }