mirror of
https://github.com/SAP/jenkins-library.git
synced 2024-12-14 11:03:09 +02:00
a46b57e6b4
* Use commonPipelineEnvironment in go binary * Update groovy part incl. tests * Rework structure and naming * Support influx resources in steps * Update tests and some cleanups * Add correct defer handling * Address PR feedback * Fix test * Update resources.go Co-authored-by: Sven Merk <33895725+nevskrem@users.noreply.github.com>
52 lines
1.1 KiB
Go
52 lines
1.1 KiB
Go
package piperenv
|
|
|
|
import (
|
|
"io/ioutil"
|
|
"os"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestSetResourceParameter(t *testing.T) {
|
|
dir, err := ioutil.TempDir("", "")
|
|
if err != nil {
|
|
t.Fatal("Failed to create temporary directory")
|
|
}
|
|
|
|
// clean up tmp dir
|
|
defer os.RemoveAll(dir)
|
|
|
|
err = SetResourceParameter(dir, "testRes", "testParam", "testVal")
|
|
|
|
assert.NoError(t, err, "Error occured but none expected")
|
|
assert.Equal(t, "testVal", GetResourceParameter(dir, "testRes", "testParam"))
|
|
}
|
|
|
|
func TestSetParameter(t *testing.T) {
|
|
dir, err := ioutil.TempDir("", "")
|
|
if err != nil {
|
|
t.Fatal("Failed to create temporary directory")
|
|
}
|
|
|
|
// clean up tmp dir
|
|
defer os.RemoveAll(dir)
|
|
|
|
err = SetParameter(dir, "testParam", "testVal")
|
|
|
|
assert.NoError(t, err, "Error occured but none expected")
|
|
assert.Equal(t, "testVal", GetParameter(dir, "testParam"))
|
|
}
|
|
|
|
func TestReadFromDisk(t *testing.T) {
|
|
dir, err := ioutil.TempDir("", "")
|
|
if err != nil {
|
|
t.Fatal("Failed to create temporary directory")
|
|
}
|
|
|
|
// clean up tmp dir
|
|
defer os.RemoveAll(dir)
|
|
|
|
assert.Equal(t, "", GetParameter(dir, "testParamNotExistingYet"))
|
|
}
|