github.com/verrazzano/verrazzano@v1.7.0/ci/tools/derive_upgrade_version_test.go (about) 1 // Copyright (c) 2022, 2023, Oracle and/or its affiliates. 2 // Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. 3 package main 4 5 import ( 6 "github.com/stretchr/testify/assert" 7 "os" 8 "testing" 9 ) 10 11 // TestGetInstallReleaseWithoutMajorVersion Tests the getInstallRelease function 12 // WHEN with git release tags major version change does not exist 13 // THEN install release version with two minor release difference is expected 14 func TestGetInstallReleaseWithoutMajorVersion(t *testing.T) { 15 pwd, _ := os.Getwd() 16 parseCliArgs([]string{pwd, "install-version"}) 17 releaseTags := []string{"v1.0.0", "v1.0.1", "v1.0.2", "v1.0.3", "v1.0.4", "v1.1.0", "v1.1.1", "v1.1.2", "v1.2.0", "v1.2.1", "v1.2.2", "v1.3.0", "v1.3.1", "v1.3.2", "v1.3.3", "v1.3.4", "v1.3.5", "v1.3.6", "v1.3.7", "v1.3.8", "v1.4.0", "v1.4.1", "v1.4.2"} 18 assert.Equal(t, "v1.2.2", getInstallRelease(releaseTags)) 19 } 20 21 // TestGetInstallReleaseWithMajorRelease Tests the getInstallRelease function 22 // WHEN with git release tags major version change exists 23 // THEN install release version with two minor release difference is expected 24 func TestGetInstallReleaseWithMajorRelease(t *testing.T) { 25 pwd, _ := os.Getwd() 26 parseCliArgs([]string{pwd, "install-version"}) 27 releaseTags := []string{"v1.0.0", "v1.0.1", "v1.0.2", "v1.0.3", "v1.0.4", "v1.1.0", "v1.1.1", "v1.1.2", "v1.2.0", "v1.2.1", "v1.2.2", "v1.3.0", "v1.3.1", "v1.3.2", "v1.3.3", "v1.3.4", "v1.3.5", "v1.3.6", "v1.3.7", "v1.3.8", "v1.4.0", "v1.4.1", "v1.4.2", "v1.5.0", "v2.0.0", "v2.1.0"} 28 assert.Equal(t, "v1.5.0", getInstallRelease(releaseTags)) 29 } 30 31 // TestGetInstallReleaseNotMoreThanTwoMinorVersions Tests the getInstallRelease function 32 // WHEN there are no more than two minor release tags 33 // THEN install release version with the first minor release is expected 34 func TestGetInstallReleaseNotMoreThanTwoMinorVersions(t *testing.T) { 35 pwd, _ := os.Getwd() 36 parseCliArgs([]string{pwd, "install-version"}) 37 releaseTags := []string{"v1.4.0", "v1.4.1", "v1.4.2", "v1.5.0", "v1.5.1"} 38 assert.Equal(t, "v1.4.0", getInstallRelease(releaseTags)) 39 } 40 41 // TestGetInterimReleaseWithoutMajorVersion Tests the getInterimRelease function 42 // WHEN with git release tags major version change does not exist 43 // THEN interim release version with one minor release difference is expected 44 func TestGetInterimReleaseWithoutMajorVersion(t *testing.T) { 45 pwd, _ := os.Getwd() 46 parseCliArgs([]string{pwd, "interim-version"}) 47 releaseTags := []string{"v1.0.0", "v1.0.1", "v1.0.2", "v1.0.3", "v1.0.4", "v1.1.0", "v1.1.1", "v1.1.2", "v1.2.0", "v1.2.1", "v1.2.2", "v1.3.0", "v1.3.1", "v1.3.2", "v1.3.3", "v1.3.4", "v1.3.5", "v1.3.6", "v1.3.7", "v1.3.8", "v1.4.0", "v1.4.1", "v1.4.2"} 48 assert.Equal(t, "v1.3.8", getInterimRelease(releaseTags)) 49 } 50 51 // TestGetInterimReleaseWithMajorVersion Tests the getInterimRelease function 52 // WHEN with git release tags major version change exists 53 // THEN interim release version with one minor release difference is expected 54 func TestGetInterimReleaseWithMajorVersion(t *testing.T) { 55 pwd, _ := os.Getwd() 56 parseCliArgs([]string{pwd, "interim-version"}) 57 releaseTags := []string{"v1.0.0", "v1.0.1", "v1.0.2", "v1.0.3", "v1.0.4", "v1.1.0", "v1.1.1", "v1.1.2", "v1.2.0", "v1.2.1", "v1.2.2", "v1.3.0", "v1.3.1", "v1.3.2", "v1.3.3", "v1.3.4", "v1.3.5", "v1.3.6", "v1.3.7", "v1.3.8", "v1.4.0", "v1.4.1", "v1.4.2", "v1.5.0", "2.0.0"} 58 assert.Equal(t, "v1.5.0", getInterimRelease(releaseTags)) 59 } 60 61 // TestGetInterimReleaseNotMoreThanTwoMinorVersions Tests the getInterimRelease function 62 // WHEN there are no more than two minor release tags 63 // THEN interim release version with the first patch release of the last minor release is expected 64 func TestGetInterimReleaseNotMoreThanTwoMinorVersions(t *testing.T) { 65 pwd, _ := os.Getwd() 66 parseCliArgs([]string{pwd, "interim-version"}) 67 releaseTags := []string{"v1.4.0", "v1.4.1", "v1.4.2", "v1.5.0", "v1.5.1"} 68 assert.Equal(t, "v1.4.2", getInterimRelease(releaseTags)) 69 } 70 71 // TestGetLatestReleaseForBranch tests the getLatestReleaseForCurrentBranch function 72 // WHEN Verrazzano development version input is given from a current branch 73 // THEN latest release with one minor release difference is expected. 74 func TestGetLatestReleaseForBranch(t *testing.T) { 75 pwd, _ := os.Getwd() 76 parseCliArgs([]string{pwd, "latest-version-for-branch", "1.4.3"}) 77 releaseTags := []string{"v1.0.0", "v1.0.1", "v1.0.2", "v1.0.3", "v1.0.4", "v1.1.0", "v1.1.1", "v1.1.2", "v1.2.0", "v1.2.1", "v1.2.2", "v1.3.0", "v1.3.1", "v1.3.2", "v1.3.3", "v1.3.4", "v1.3.5", "v1.3.6", "v1.3.7", "v1.3.8", "v1.4.0", "v1.4.1", "v1.4.2", "v1.5.0", "2.0.0"} 78 assert.Equal(t, "v1.3.8", getLatestReleaseForCurrentBranch(releaseTags)) 79 }