mirror of
https://github.com/onedr0p/exportarr.git
synced 2026-02-06 10:57:32 +00:00
Signed-off-by: Russell Troxel <russell@troxel.io>
This commit is contained in:
parent
230419c680
commit
a42b0cb848
33
internal/arr/config/arr_integration_test.go
Normal file
33
internal/arr/config/arr_integration_test.go
Normal file
@ -0,0 +1,33 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
base_config "github.com/onedr0p/exportarr/internal/config"
|
||||
"github.com/spf13/pflag"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestArrConfigIntegration(t *testing.T) {
|
||||
require := require.New(t)
|
||||
|
||||
configFlags := pflag.NewFlagSet("test", pflag.ContinueOnError)
|
||||
base_config.RegisterConfigFlags(configFlags)
|
||||
|
||||
arrConfigFlags := testFlagSet()
|
||||
|
||||
t.Setenv("URL", "http://localhost")
|
||||
t.Setenv("CONFIG", "test_fixtures/config.test_xml")
|
||||
t.Setenv("PORT", "9792")
|
||||
t.Setenv("ENABLE_ADDITIONAL_METRICS", "true")
|
||||
t.Setenv("ENABLE_UNKNOWN_QUEUE_ITEMS", "false")
|
||||
|
||||
config, err := base_config.LoadConfig(configFlags)
|
||||
require.NoError(err)
|
||||
arrConfig, err := LoadArrConfig(*config, arrConfigFlags)
|
||||
require.NoError(err)
|
||||
|
||||
require.NoError(config.Validate())
|
||||
require.NoError(arrConfig.Validate())
|
||||
|
||||
}
|
||||
@ -163,6 +163,23 @@ func TestLoadConfig_XMLConfig(t *testing.T) {
|
||||
require.Equal("abcdef0123456789abcdef0123456789", config.ApiKey)
|
||||
}
|
||||
|
||||
func TestLoadConfig_XMLConfigEnv(t *testing.T) {
|
||||
flags := testFlagSet()
|
||||
t.Setenv("CONFIG", "test_fixtures/config.test_xml")
|
||||
c := base_config.Config{
|
||||
URL: "http://localhost",
|
||||
}
|
||||
|
||||
config, err := LoadArrConfig(c, flags)
|
||||
|
||||
require := require.New(t)
|
||||
require.NoError(err)
|
||||
|
||||
// schema/host from config, port, and asdf from xml, api & version defaulted in LoadConfig.
|
||||
require.Equal("http://localhost:7878/asdf", config.URL)
|
||||
require.Equal("abcdef0123456789abcdef0123456789", config.ApiKey)
|
||||
}
|
||||
|
||||
func TestValidate(t *testing.T) {
|
||||
params := []struct {
|
||||
name string
|
||||
|
||||
@ -30,8 +30,8 @@ type Config struct {
|
||||
App string `koanf:"-"`
|
||||
LogLevel string `koanf:"log-level" validate:"ValidateLogLevel"`
|
||||
LogFormat string `koanf:"log-format" validate:"in:console,json"`
|
||||
URL string `koanf:"url" validate:"required|url"`
|
||||
ApiKey string `koanf:"api-key" validate:"required"`
|
||||
URL string `koanf:"url"`
|
||||
ApiKey string `koanf:"api-key"`
|
||||
ApiKeyFile string `koanf:"api-key-file"`
|
||||
Port int `koanf:"port" validate:"required"`
|
||||
Interface string `koanf:"interface" validate:"required|ip"`
|
||||
|
||||
@ -9,14 +9,7 @@ import (
|
||||
|
||||
func testFlagSet() *pflag.FlagSet {
|
||||
out := pflag.NewFlagSet("test", pflag.ContinueOnError)
|
||||
out.StringP("log-level", "l", "info", "Log level (debug, info, warn, error, fatal, panic)")
|
||||
out.StringP("config", "c", "", "*arr config.xml file for parsing authentication information")
|
||||
out.StringP("url", "u", "", "URL to *arr instance")
|
||||
out.StringP("api-key", "k", "", "API Key for *arr instance")
|
||||
out.StringP("api-key-file", "f", "", "File containing API Key for *arr instance")
|
||||
out.Int("port", 0, "Port to listen on")
|
||||
out.StringP("interface", "i", "", "IP address to listen on")
|
||||
out.Bool("disable-ssl-verify", false, "Disable SSL verification")
|
||||
RegisterConfigFlags(out)
|
||||
return out
|
||||
}
|
||||
func TestLoadConfig_Defaults(t *testing.T) {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user