Allow custom config path via environment variable
Signed-off-by: Steven Kriegler <61625851+justusbunsi@users.noreply.github.com>
This commit is contained in:
parent
706aeb0d0f
commit
5c6229be8f
|
@ -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())
|
||||
}
|
||||
|
|
22
cmd/gitea-sonarqube-bot/main_test.go
Normal file
22
cmd/gitea-sonarqube-bot/main_test.go
Normal 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")
|
||||
})
|
||||
}
|
|
@ -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: {}
|
||||
|
|
Loading…
Reference in a new issue