mirror of
https://github.com/caddyserver/caddy.git
synced 2025-01-23 10:45:49 +03:00
proxy: fix checking error in TestDownstreamHeadersUpdate and TestUpstreamHeadersUpdate
Signed-off-by: Tw <tw19881113@gmail.com>
This commit is contained in:
parent
bac54de9eb
commit
4670d13c8c
1 changed files with 31 additions and 27 deletions
|
@ -13,6 +13,7 @@ import (
|
||||||
"net/url"
|
"net/url"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"reflect"
|
||||||
"runtime"
|
"runtime"
|
||||||
"strings"
|
"strings"
|
||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
|
@ -407,16 +408,19 @@ func TestUpstreamHeadersUpdate(t *testing.T) {
|
||||||
replacer := httpserver.NewReplacer(r, nil, "")
|
replacer := httpserver.NewReplacer(r, nil, "")
|
||||||
|
|
||||||
headerKey := "Merge-Me"
|
headerKey := "Merge-Me"
|
||||||
values, ok := actualHeaders[headerKey]
|
got := actualHeaders[headerKey]
|
||||||
if !ok {
|
expect := []string{"Initial", "Merge-Value"}
|
||||||
t.Errorf("Request sent to upstream backend does not contain expected %v header. Expected header to be added", headerKey)
|
if !reflect.DeepEqual(got, expect) {
|
||||||
} else if len(values) < 2 && (values[0] != "Initial" || values[1] != replacer.Replace("{hostname}")) {
|
t.Errorf("Request sent to upstream backend does not contain expected %v header: expect %v, but got %v",
|
||||||
t.Errorf("Values for proxy header `+Merge-Me` should be merged. Got %v", values)
|
headerKey, expect, got)
|
||||||
}
|
}
|
||||||
|
|
||||||
headerKey = "Add-Me"
|
headerKey = "Add-Me"
|
||||||
if _, ok := actualHeaders[headerKey]; !ok {
|
got = actualHeaders[headerKey]
|
||||||
t.Errorf("Request sent to upstream backend does not contain expected %v header", headerKey)
|
expect = []string{"Add-Value"}
|
||||||
|
if !reflect.DeepEqual(got, expect) {
|
||||||
|
t.Errorf("Request sent to upstream backend does not contain expected %v header: expect %v, but got %v",
|
||||||
|
headerKey, expect, got)
|
||||||
}
|
}
|
||||||
|
|
||||||
headerKey = "Remove-Me"
|
headerKey = "Remove-Me"
|
||||||
|
@ -425,12 +429,11 @@ func TestUpstreamHeadersUpdate(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
headerKey = "Replace-Me"
|
headerKey = "Replace-Me"
|
||||||
headerValue := replacer.Replace("{hostname}")
|
got = actualHeaders[headerKey]
|
||||||
value, ok := actualHeaders[headerKey]
|
expect = []string{replacer.Replace("{hostname}")}
|
||||||
if !ok {
|
if !reflect.DeepEqual(got, expect) {
|
||||||
t.Errorf("Request sent to upstream backend should not remove %v header", headerKey)
|
t.Errorf("Request sent to upstream backend does not contain expected %v header: expect %v, but got %v",
|
||||||
} else if len(value) > 0 && headerValue != value[0] {
|
headerKey, expect, got)
|
||||||
t.Errorf("Request sent to upstream backend should replace value of %v header with %v. Instead value was %v", headerKey, headerValue, value)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if actualHost != expectHost {
|
if actualHost != expectHost {
|
||||||
|
@ -477,16 +480,19 @@ func TestDownstreamHeadersUpdate(t *testing.T) {
|
||||||
actualHeaders := w.Header()
|
actualHeaders := w.Header()
|
||||||
|
|
||||||
headerKey := "Merge-Me"
|
headerKey := "Merge-Me"
|
||||||
values, ok := actualHeaders[headerKey]
|
got := actualHeaders[headerKey]
|
||||||
if !ok {
|
expect := []string{"Initial", "Merge-Value"}
|
||||||
t.Errorf("Downstream response does not contain expected %v header. Expected header should be added", headerKey)
|
if !reflect.DeepEqual(got, expect) {
|
||||||
} else if len(values) < 2 && (values[0] != "Initial" || values[1] != replacer.Replace("{hostname}")) {
|
t.Errorf("Downstream response does not contain expected %s header: expect %v, but got %v",
|
||||||
t.Errorf("Values for header `+Merge-Me` should be merged. Got %v", values)
|
headerKey, expect, got)
|
||||||
}
|
}
|
||||||
|
|
||||||
headerKey = "Add-Me"
|
headerKey = "Add-Me"
|
||||||
if _, ok := actualHeaders[headerKey]; !ok {
|
got = actualHeaders[headerKey]
|
||||||
t.Errorf("Downstream response does not contain expected %v header", headerKey)
|
expect = []string{"Add-Value"}
|
||||||
|
if !reflect.DeepEqual(got, expect) {
|
||||||
|
t.Errorf("Downstream response does not contain expected %s header: expect %v, but got %v",
|
||||||
|
headerKey, expect, got)
|
||||||
}
|
}
|
||||||
|
|
||||||
headerKey = "Remove-Me"
|
headerKey = "Remove-Me"
|
||||||
|
@ -495,14 +501,12 @@ func TestDownstreamHeadersUpdate(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
headerKey = "Replace-Me"
|
headerKey = "Replace-Me"
|
||||||
headerValue := replacer.Replace("{hostname}")
|
got = actualHeaders[headerKey]
|
||||||
value, ok := actualHeaders[headerKey]
|
expect = []string{replacer.Replace("{hostname}")}
|
||||||
if !ok {
|
if !reflect.DeepEqual(got, expect) {
|
||||||
t.Errorf("Downstream response should contain %v header and not remove it", headerKey)
|
t.Errorf("Downstream response does not contain expected %s header: expect %v, but got %v",
|
||||||
} else if len(value) > 0 && headerValue != value[0] {
|
headerKey, expect, got)
|
||||||
t.Errorf("Downstream response should have header %v with value %v. Instead value was %v", headerKey, headerValue, value)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
|
Loading…
Reference in a new issue