github.com/ouraigua/jenkins-library@v0.0.0-20231028010029-fbeaf2f3aa9b/pkg/versioning/gradle_test.go (about) 1 //go:build unit 2 // +build unit 3 4 package versioning 5 6 import ( 7 "os" 8 "path/filepath" 9 "testing" 10 11 "github.com/stretchr/testify/assert" 12 ) 13 14 func TestGradleGetVersion(t *testing.T) { 15 t.Run("success case", func(t *testing.T) { 16 tmpFolder := t.TempDir() 17 18 gradlePropsFilePath := filepath.Join(tmpFolder, "gradle.properties") 19 os.WriteFile(gradlePropsFilePath, []byte("version = 1.2.3"), 0666) 20 gradle := &Gradle{ 21 path: gradlePropsFilePath, 22 } 23 24 version, err := gradle.GetVersion() 25 26 assert.NoError(t, err) 27 assert.Equal(t, "1.2.3", version) 28 }) 29 } 30 31 func TestGradleSetVersion(t *testing.T) { 32 t.Run("success case", func(t *testing.T) { 33 tmpFolder := t.TempDir() 34 35 gradlePropsFilePath := filepath.Join(tmpFolder, "gradle.properties") 36 os.WriteFile(gradlePropsFilePath, []byte("version = 0.0.1"), 0666) 37 38 var content []byte 39 gradle := &Gradle{ 40 path: gradlePropsFilePath, 41 writeFile: func(filename string, filecontent []byte, mode os.FileMode) error { content = filecontent; return nil }, 42 } 43 err := gradle.SetVersion("1.2.3") 44 assert.NoError(t, err) 45 46 assert.Contains(t, string(content), "version = 1.2.3") 47 }) 48 }