diff options
author | 2023-02-25 09:36:19 +0100 | |
---|---|---|
committer | 2023-02-25 15:57:59 -0800 | |
commit | 2c2700a31d7349f67016a3786125597f9ee38c56 (patch) | |
tree | 9a9cef0c5d6a17946be70e709cf1d0349d05bc77 /config/config_test.go | |
parent | 8f9ccc6540be9d637b812985936f064bada8fcf3 (diff) | |
download | v2-2c2700a31d7349f67016a3786125597f9ee38c56.tar.gz v2-2c2700a31d7349f67016a3786125597f9ee38c56.tar.zst v2-2c2700a31d7349f67016a3786125597f9ee38c56.zip |
Proxy support for several media types
closes #615
closes #635
Diffstat (limited to 'config/config_test.go')
-rw-r--r-- | config/config_test.go | 141 |
1 files changed, 133 insertions, 8 deletions
diff --git a/config/config_test.go b/config/config_test.go index 188e2b7b..1725caa5 100644 --- a/config/config_test.go +++ b/config/config_test.go @@ -1163,9 +1163,9 @@ func TestPocketConsumerKeyFromUserPrefs(t *testing.T) { } } -func TestProxyImages(t *testing.T) { +func TestProxyOption(t *testing.T) { os.Clearenv() - os.Setenv("PROXY_IMAGES", "all") + os.Setenv("PROXY_OPTION", "all") parser := NewParser() opts, err := parser.ParseEnvironmentVariables() @@ -1174,14 +1174,14 @@ func TestProxyImages(t *testing.T) { } expected := "all" - result := opts.ProxyImages() + result := opts.ProxyOption() if result != expected { - t.Fatalf(`Unexpected PROXY_IMAGES value, got %q instead of %q`, result, expected) + t.Fatalf(`Unexpected PROXY_OPTION value, got %q instead of %q`, result, expected) } } -func TestDefaultProxyImagesValue(t *testing.T) { +func TestDefaultProxyOptionValue(t *testing.T) { os.Clearenv() parser := NewParser() @@ -1190,11 +1190,101 @@ func TestDefaultProxyImagesValue(t *testing.T) { t.Fatalf(`Parsing failure: %v`, err) } - expected := defaultProxyImages - result := opts.ProxyImages() + expected := defaultProxyOption + result := opts.ProxyOption() if result != expected { - t.Fatalf(`Unexpected PROXY_IMAGES value, got %q instead of %q`, result, expected) + t.Fatalf(`Unexpected PROXY_OPTION value, got %q instead of %q`, result, expected) + } +} + +func TestProxyMediaTypes(t *testing.T) { + os.Clearenv() + os.Setenv("PROXY_MEDIA_TYPES", "image,audio") + + parser := NewParser() + opts, err := parser.ParseEnvironmentVariables() + if err != nil { + t.Fatalf(`Parsing failure: %v`, err) + } + + expected := []string{"audio", "image"} + + if len(expected) != len(opts.ProxyMediaTypes()) { + t.Fatalf(`Unexpected PROXY_MEDIA_TYPES value, got %v instead of %v`, opts.ProxyMediaTypes(), expected) + } + + resultMap := make(map[string]bool) + for _, mediaType := range opts.ProxyMediaTypes() { + resultMap[mediaType] = true + } + + for _, mediaType := range expected { + if !resultMap[mediaType] { + t.Fatalf(`Unexpected PROXY_MEDIA_TYPES value, got %v instead of %v`, opts.ProxyMediaTypes(), expected) + } + } +} + +func TestDefaultProxyMediaTypes(t *testing.T) { + os.Clearenv() + + parser := NewParser() + opts, err := parser.ParseEnvironmentVariables() + if err != nil { + t.Fatalf(`Parsing failure: %v`, err) + } + + expected := []string{"image"} + + if len(expected) != len(opts.ProxyMediaTypes()) { + t.Fatalf(`Unexpected PROXY_MEDIA_TYPES value, got %v instead of %v`, opts.ProxyMediaTypes(), expected) + } + + resultMap := make(map[string]bool) + for _, mediaType := range opts.ProxyMediaTypes() { + resultMap[mediaType] = true + } + + for _, mediaType := range expected { + if !resultMap[mediaType] { + t.Fatalf(`Unexpected PROXY_MEDIA_TYPES value, got %v instead of %v`, opts.ProxyMediaTypes(), expected) + } + } +} + +func TestProxyHTTPClientTimeout(t *testing.T) { + os.Clearenv() + os.Setenv("PROXY_HTTP_CLIENT_TIMEOUT", "24") + + parser := NewParser() + opts, err := parser.ParseEnvironmentVariables() + if err != nil { + t.Fatalf(`Parsing failure: %v`, err) + } + + expected := 24 + result := opts.ProxyHTTPClientTimeout() + + if result != expected { + t.Fatalf(`Unexpected PROXY_HTTP_CLIENT_TIMEOUT value, got %d instead of %d`, result, expected) + } +} + +func TestDefaultProxyHTTPClientTimeoutValue(t *testing.T) { + os.Clearenv() + + parser := NewParser() + opts, err := parser.ParseEnvironmentVariables() + if err != nil { + t.Fatalf(`Parsing failure: %v`, err) + } + + expected := defaultProxyHTTPClientTimeout + result := opts.ProxyHTTPClientTimeout() + + if result != expected { + t.Fatalf(`Unexpected PROXY_HTTP_CLIENT_TIMEOUT value, got %d instead of %d`, result, expected) } } @@ -1297,6 +1387,41 @@ func TestDefaultHTTPClientMaxBodySizeValue(t *testing.T) { } } +func TestHTTPServerTimeout(t *testing.T) { + os.Clearenv() + os.Setenv("HTTP_SERVER_TIMEOUT", "342") + + parser := NewParser() + opts, err := parser.ParseEnvironmentVariables() + if err != nil { + t.Fatalf(`Parsing failure: %v`, err) + } + + expected := 342 + result := opts.HTTPServerTimeout() + + if result != expected { + t.Fatalf(`Unexpected HTTP_SERVER_TIMEOUT value, got %d instead of %d`, result, expected) + } +} + +func TestDefaultHTTPServerTimeoutValue(t *testing.T) { + os.Clearenv() + + parser := NewParser() + opts, err := parser.ParseEnvironmentVariables() + if err != nil { + t.Fatalf(`Parsing failure: %v`, err) + } + + expected := defaultHTTPServerTimeout + result := opts.HTTPServerTimeout() + + if result != expected { + t.Fatalf(`Unexpected HTTP_SERVER_TIMEOUT value, got %d instead of %d`, result, expected) + } +} + func TestParseConfigFile(t *testing.T) { content := []byte(` # This is a comment |