-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
support error templates for text/xml (#3392)
(cherry picked from commit d88e9a5)
- Loading branch information
Showing
3 changed files
with
57 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package gateway | ||
|
||
import ( | ||
"bytes" | ||
"io/ioutil" | ||
"net/http" | ||
"net/http/httptest" | ||
"os" | ||
"path/filepath" | ||
"strings" | ||
"testing" | ||
|
||
"github.com/TykTechnologies/tyk/config" | ||
"github.com/TykTechnologies/tyk/headers" | ||
"github.com/TykTechnologies/tyk/test" | ||
) | ||
|
||
func TestHandleError_text_xml(t *testing.T) { | ||
file := filepath.Join(config.Global().TemplatePath, "error_500.xml") | ||
xml := `<error> | ||
<code>500</code> | ||
<message>{{.Message}}</message> | ||
</error>` | ||
err := ioutil.WriteFile(file, []byte(xml), 0600) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
defer os.Remove(file) | ||
expect := ` | ||
<error> | ||
<code>500</code> | ||
<message>There was a problem proxying the request</message> | ||
</error> | ||
` | ||
ts := StartTest() | ||
defer ts.Close() | ||
h := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {})) | ||
h.Close() | ||
BuildAndLoadAPI(func(spec *APISpec) { | ||
spec.Proxy.ListenPath = "/" | ||
spec.Proxy.TargetURL = ts.URL | ||
}) | ||
ts.Run(t, test.TestCase{ | ||
Path: "/", | ||
Code: http.StatusInternalServerError, | ||
Headers: map[string]string{ | ||
headers.ContentType: headers.TextXML, | ||
}, | ||
BodyMatchFunc: func(b []byte) bool { | ||
return strings.TrimSpace(expect) == string(bytes.TrimSpace(b)) | ||
}, | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters