api: extract http headers with some supported header list. (#2268)

This commit is contained in:
Harshavardhana
2016-07-22 20:31:45 -07:00
committed by GitHub
parent 55cb55675c
commit f85d94288d
5 changed files with 91 additions and 56 deletions

View File

@@ -21,6 +21,7 @@ import (
"encoding/xml"
"io/ioutil"
"net/http"
"reflect"
"testing"
)
@@ -84,3 +85,36 @@ func TestIsValidLocationContraint(t *testing.T) {
}
}
}
// Tests validate metadata extraction from http headers.
func TestExtractMetadataHeaders(t *testing.T) {
testCases := []struct {
header http.Header
metadata map[string]string
}{
// Validate if there a known 'content-type'.
{
header: http.Header{
"Content-Type": []string{"image/png"},
},
metadata: map[string]string{
"content-type": "image/png",
},
},
// Validate if there are no keys to extract.
{
header: http.Header{
"test-1": []string{"123"},
},
metadata: map[string]string{},
},
}
// Validate if the extracting headers.
for i, testCase := range testCases {
metadata := extractMetadataFromHeader(testCase.header)
if !reflect.DeepEqual(metadata, testCase.metadata) {
t.Fatalf("Test %d failed: Expected \"%#v\", got \"%#v\"", i+1, testCase.metadata, metadata)
}
}
}