forked from elastic/package-registry
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain_content_type_test.go
50 lines (42 loc) · 1.31 KB
/
main_content_type_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
// or more contributor license agreements. Licensed under the Elastic License;
// you may not use this file except in compliance with the Elastic License.
package main
import (
"net/http"
"net/http/httptest"
"net/url"
"testing"
"github.com/stretchr/testify/assert"
)
func TestContentTypes(t *testing.T) {
tests := []struct {
endpoint string
expectedContentType string
}{
{"/index.json", "application/json"},
{"/activemq-0.0.1.tar.gz", "application/gzip"},
{"/favicon.ico", "image/x-icon"},
{"/metricbeat-mysql.png", "image/png"},
{"/kibana-coredns.jpg", "image/jpeg"},
{"/README.md", "text/markdown; charset=utf-8"},
{"/logo_mysql.svg", "image/svg+xml"},
{"/manifest.yml", "text/yaml; charset=UTF-8"},
}
for _, test := range tests {
t.Run(test.endpoint, func(t *testing.T) {
runContentType(t, test.endpoint, test.expectedContentType)
})
}
}
func runContentType(t *testing.T, endpoint, expectedContentType string) {
publicPath := "./testdata/content-types"
recorder := httptest.NewRecorder()
h := catchAll(http.Dir(publicPath), testCacheTime)
h.ServeHTTP(recorder, &http.Request{
URL: &url.URL{
Path: endpoint,
},
})
assert.Equal(t, expectedContentType, recorder.Header().Get("Content-Type"))
}