Skip to content

Commit

Permalink
Fix onedr0p#154: Do not require Api Key or URL in parent config, vali…
Browse files Browse the repository at this point in the history
…date in child config (onedr0p#157)

Signed-off-by: Russell Troxel <[email protected]>
  • Loading branch information
rtrox authored Apr 27, 2023
1 parent 230419c commit a42b0cb
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 10 deletions.
33 changes: 33 additions & 0 deletions internal/arr/config/arr_integration_test.go
Original file line number Diff line number Diff line change
@@ -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())

}
17 changes: 17 additions & 0 deletions internal/arr/config/arr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down
9 changes: 1 addition & 8 deletions internal/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit a42b0cb

Please sign in to comment.