Allow custom config path via environment variable

Signed-off-by: Steven Kriegler <61625851+justusbunsi@users.noreply.github.com>
This commit is contained in:
justusbunsi 2021-06-20 15:39:54 +02:00
parent 706aeb0d0f
commit 5c6229be8f
No known key found for this signature in database
GPG key ID: 990B348ECAC9C7DB
3 changed files with 35 additions and 4 deletions

View file

@ -1,12 +1,21 @@
package main
import (
"os"
"path"
"github.com/justusbunsi/gitea-sonarqube-pr-bot/internal/settings"
)
func main() {
func GetConfigLocation() string {
configPath := path.Join("config")
settings.Load(configPath)
if customConfigPath, ok := os.LookupEnv("PRBOT_CONFIG_PATH"); ok {
configPath = customConfigPath
}
return configPath
}
func main() {
settings.Load(GetConfigLocation())
}

View file

@ -0,0 +1,22 @@
package main
import (
"os"
"testing"
"github.com/stretchr/testify/assert"
)
func TestGetConfigLocationWithDefault(t *testing.T) {
assert.Equal(t, "config", GetConfigLocation())
}
func TestGetConfigLocationWithEnvironmentOverride(t *testing.T) {
os.Setenv("PRBOT_CONFIG_PATH", "/tmp/")
assert.Equal(t, "/tmp/", GetConfigLocation())
t.Cleanup(func() {
os.Unsetenv("PRBOT_CONFIG_PATH")
})
}

View file

@ -9,8 +9,8 @@ import (
"github.com/stretchr/testify/assert"
)
var defaultConfig []byte = []byte(`
gitea:
var defaultConfig []byte = []byte(
`gitea:
url: https://example.com/gitea
token: 1337
webhookSecret: {}