mirror of
https://github.com/miniflux/v2.git
synced 2025-06-27 16:36:00 +00:00
Refactor config package
- Parse configuration only once during startup time - Store configuration values in a global variable
This commit is contained in:
parent
04d85b3c63
commit
228862fefa
28 changed files with 922 additions and 624 deletions
|
@ -134,13 +134,13 @@ func TestElapsedTime(t *testing.T) {
|
|||
func TestProxyFilterWithHttpDefault(t *testing.T) {
|
||||
os.Clearenv()
|
||||
os.Setenv("PROXY_IMAGES", "http-only")
|
||||
c := config.NewConfig()
|
||||
config.ParseConfig()
|
||||
|
||||
r := mux.NewRouter()
|
||||
r.HandleFunc("/proxy/{encodedURL}", func(w http.ResponseWriter, r *http.Request) {}).Name("proxy")
|
||||
|
||||
input := `<p><img src="http://website/folder/image.png" alt="Test"/></p>`
|
||||
output := imageProxyFilter(r, c, input)
|
||||
output := imageProxyFilter(r, input)
|
||||
expected := `<p><img src="/proxy/aHR0cDovL3dlYnNpdGUvZm9sZGVyL2ltYWdlLnBuZw==" alt="Test"/></p>`
|
||||
|
||||
if expected != output {
|
||||
|
@ -151,13 +151,13 @@ func TestProxyFilterWithHttpDefault(t *testing.T) {
|
|||
func TestProxyFilterWithHttpsDefault(t *testing.T) {
|
||||
os.Clearenv()
|
||||
os.Setenv("PROXY_IMAGES", "http-only")
|
||||
c := config.NewConfig()
|
||||
config.ParseConfig()
|
||||
|
||||
r := mux.NewRouter()
|
||||
r.HandleFunc("/proxy/{encodedURL}", func(w http.ResponseWriter, r *http.Request) {}).Name("proxy")
|
||||
|
||||
input := `<p><img src="https://website/folder/image.png" alt="Test"/></p>`
|
||||
output := imageProxyFilter(r, c, input)
|
||||
output := imageProxyFilter(r, input)
|
||||
expected := `<p><img src="https://website/folder/image.png" alt="Test"/></p>`
|
||||
|
||||
if expected != output {
|
||||
|
@ -168,13 +168,13 @@ func TestProxyFilterWithHttpsDefault(t *testing.T) {
|
|||
func TestProxyFilterWithHttpNever(t *testing.T) {
|
||||
os.Clearenv()
|
||||
os.Setenv("PROXY_IMAGES", "none")
|
||||
c := config.NewConfig()
|
||||
config.ParseConfig()
|
||||
|
||||
r := mux.NewRouter()
|
||||
r.HandleFunc("/proxy/{encodedURL}", func(w http.ResponseWriter, r *http.Request) {}).Name("proxy")
|
||||
|
||||
input := `<p><img src="http://website/folder/image.png" alt="Test"/></p>`
|
||||
output := imageProxyFilter(r, c, input)
|
||||
output := imageProxyFilter(r, input)
|
||||
expected := input
|
||||
|
||||
if expected != output {
|
||||
|
@ -185,13 +185,13 @@ func TestProxyFilterWithHttpNever(t *testing.T) {
|
|||
func TestProxyFilterWithHttpsNever(t *testing.T) {
|
||||
os.Clearenv()
|
||||
os.Setenv("PROXY_IMAGES", "none")
|
||||
c := config.NewConfig()
|
||||
config.ParseConfig()
|
||||
|
||||
r := mux.NewRouter()
|
||||
r.HandleFunc("/proxy/{encodedURL}", func(w http.ResponseWriter, r *http.Request) {}).Name("proxy")
|
||||
|
||||
input := `<p><img src="https://website/folder/image.png" alt="Test"/></p>`
|
||||
output := imageProxyFilter(r, c, input)
|
||||
output := imageProxyFilter(r, input)
|
||||
expected := input
|
||||
|
||||
if expected != output {
|
||||
|
@ -202,13 +202,13 @@ func TestProxyFilterWithHttpsNever(t *testing.T) {
|
|||
func TestProxyFilterWithHttpAlways(t *testing.T) {
|
||||
os.Clearenv()
|
||||
os.Setenv("PROXY_IMAGES", "all")
|
||||
c := config.NewConfig()
|
||||
config.ParseConfig()
|
||||
|
||||
r := mux.NewRouter()
|
||||
r.HandleFunc("/proxy/{encodedURL}", func(w http.ResponseWriter, r *http.Request) {}).Name("proxy")
|
||||
|
||||
input := `<p><img src="http://website/folder/image.png" alt="Test"/></p>`
|
||||
output := imageProxyFilter(r, c, input)
|
||||
output := imageProxyFilter(r, input)
|
||||
expected := `<p><img src="/proxy/aHR0cDovL3dlYnNpdGUvZm9sZGVyL2ltYWdlLnBuZw==" alt="Test"/></p>`
|
||||
|
||||
if expected != output {
|
||||
|
@ -219,13 +219,13 @@ func TestProxyFilterWithHttpAlways(t *testing.T) {
|
|||
func TestProxyFilterWithHttpsAlways(t *testing.T) {
|
||||
os.Clearenv()
|
||||
os.Setenv("PROXY_IMAGES", "all")
|
||||
c := config.NewConfig()
|
||||
config.ParseConfig()
|
||||
|
||||
r := mux.NewRouter()
|
||||
r.HandleFunc("/proxy/{encodedURL}", func(w http.ResponseWriter, r *http.Request) {}).Name("proxy")
|
||||
|
||||
input := `<p><img src="https://website/folder/image.png" alt="Test"/></p>`
|
||||
output := imageProxyFilter(r, c, input)
|
||||
output := imageProxyFilter(r, input)
|
||||
expected := `<p><img src="/proxy/aHR0cHM6Ly93ZWJzaXRlL2ZvbGRlci9pbWFnZS5wbmc=" alt="Test"/></p>`
|
||||
|
||||
if expected != output {
|
||||
|
@ -236,13 +236,13 @@ func TestProxyFilterWithHttpsAlways(t *testing.T) {
|
|||
func TestProxyFilterWithHttpInvalid(t *testing.T) {
|
||||
os.Clearenv()
|
||||
os.Setenv("PROXY_IMAGES", "invalid")
|
||||
c := config.NewConfig()
|
||||
config.ParseConfig()
|
||||
|
||||
r := mux.NewRouter()
|
||||
r.HandleFunc("/proxy/{encodedURL}", func(w http.ResponseWriter, r *http.Request) {}).Name("proxy")
|
||||
|
||||
input := `<p><img src="http://website/folder/image.png" alt="Test"/></p>`
|
||||
output := imageProxyFilter(r, c, input)
|
||||
output := imageProxyFilter(r, input)
|
||||
expected := `<p><img src="/proxy/aHR0cDovL3dlYnNpdGUvZm9sZGVyL2ltYWdlLnBuZw==" alt="Test"/></p>`
|
||||
|
||||
if expected != output {
|
||||
|
@ -253,13 +253,13 @@ func TestProxyFilterWithHttpInvalid(t *testing.T) {
|
|||
func TestProxyFilterWithHttpsInvalid(t *testing.T) {
|
||||
os.Clearenv()
|
||||
os.Setenv("PROXY_IMAGES", "invalid")
|
||||
c := config.NewConfig()
|
||||
config.ParseConfig()
|
||||
|
||||
r := mux.NewRouter()
|
||||
r.HandleFunc("/proxy/{encodedURL}", func(w http.ResponseWriter, r *http.Request) {}).Name("proxy")
|
||||
|
||||
input := `<p><img src="https://website/folder/image.png" alt="Test"/></p>`
|
||||
output := imageProxyFilter(r, c, input)
|
||||
output := imageProxyFilter(r, input)
|
||||
expected := `<p><img src="https://website/folder/image.png" alt="Test"/></p>`
|
||||
|
||||
if expected != output {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue