5c6229be8f
Signed-off-by: Steven Kriegler <61625851+justusbunsi@users.noreply.github.com>
45 lines
863 B
Go
45 lines
863 B
Go
package settings
|
|
|
|
import (
|
|
"io/ioutil"
|
|
"os"
|
|
"path"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
var defaultConfig []byte = []byte(
|
|
`gitea:
|
|
url: https://example.com/gitea
|
|
token: 1337
|
|
webhookSecret: {}
|
|
repositories: []
|
|
sonarqube:
|
|
url: https://example.com/sonarqube
|
|
token: 42
|
|
webhookSecret: {}
|
|
projects: []
|
|
`)
|
|
|
|
func WriteConfigFile(t *testing.T, content []byte) {
|
|
dir := os.TempDir()
|
|
config := path.Join(dir, "config.yaml")
|
|
|
|
t.Cleanup(func() {
|
|
os.Remove(config)
|
|
})
|
|
|
|
_ = ioutil.WriteFile(config, content,0444)
|
|
}
|
|
|
|
func TestLoadWithMissingFile(t *testing.T) {
|
|
assert.Panics(t, func() { Load(os.TempDir()) }, "No panic while reading missing file")
|
|
}
|
|
|
|
func TestLoadWithExistingFile(t *testing.T) {
|
|
WriteConfigFile(t, defaultConfig)
|
|
|
|
assert.NotPanics(t, func() { Load(os.TempDir()) }, "Unexpected panic while reading existing file")
|
|
}
|